HTTPCLient does not have a type ERROR

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
_phillip
 
Posts: 313
Joined: Fri Apr 09, 2021 3:28 pm

HTTPCLient does not have a type ERROR

Post by _phillip »

I have tried to get this test sketch to work but have never been able to overcome the following error:
"'HTTPClient' does not name a type; did you mean 'HttpClient'?"

I probably have an excess of #include libraries added to try an solve this error. In my research I have come across several comments about their being several 'HTTPClient.h' and 'HttpClient.h', which appears to be true. This is confusing to say the least. Whether this is the problem, I am not certain.

If I add: #include HttpClient.h (note lower case 'ttp', then the error becomes -
"'HTTPClient' does not name a type; did you mean 'HttpClient'?"

If anyone can shed some light on this I would be very grateful. Here is my test sketch:

Code: Select all

 
  // test Rui sketch
  // cannot overcome following error:
  //  'HTTPClient' does not name a type; did you mean 'HttpClient'?
  
  #include <b64.h>
  #include <Wire.h>
  #include <Adafruit_Sensor.h>
  #include <Adafruit_BME280.h>
  #include <WiFi101.h>
  #include "Adafruit_MQTT.h"
  #include "Adafruit_MQTT_Client.h"

  #include <SPI.h>
  #include <WiFi.h>
  #include <HTTPClient.h>

  // My code moved from loop() ...
  WiFiClient client;
  HTTPClient http;
  
// Replace with your network credentials
const char* ssid     = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

const char* serverName = "http://redristracards.com/post-data.php";

  String apiKeyValue = "tPmAT5Ab3j7F9";

void setup() {
  Serial.begin(115200);
  
  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) { 
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());

  // (you can also pass in a Wire library object like &Wire2)
  bool status = bme.begin(0x76);
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring or change I2C address!");
    while (1);
  }
}


void loop() {
  //Check WiFi connection status
  if(WiFi.status()== WL_CONNECTED){
    
    // Your Domain name with URL path or IP address with path
    http.begin(client, serverName);
    
    // Specify content-type header
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    
    // Prepare your HTTP POST request data
    String httpRequestData = "api_key=" + apiKeyValue + "&value1=" + String(bme.readTemperature())
                           + "&value2=" + String(bme.readHumidity()) + "&value3=" + String(bme.readPressure()/100.0F) + "";
    Serial.print("httpRequestData: ");
    Serial.println(httpRequestData);


    if (httpResponseCode>0) {
      Serial.print("HTTP Response code: ");
      Serial.println(httpResponseCode);
    }
    else {
      Serial.print("Error code: ");
      Serial.println(httpResponseCode);
    }
    // Free resources
    http.end();
  }
  else {
    Serial.println("WiFi Disconnected");
  }
  //Send an HTTP POST request every 30 seconds
  delay(30000);  
}
Thank you.

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: HTTPCLient does not have a type ERROR

Post by adafruit_support_bill »

The capitalization of the #include statement is irrelevant. It is just a file name. What matters is the capitalization of your declaration:

Code: Select all

  HTTPClient http;
That should match the capitalization of the class definition in the header file:

Code: Select all

class HttpClient : public Client

User avatar
_phillip
 
Posts: 313
Joined: Fri Apr 09, 2021 3:28 pm

Re: HTTPCLient does not have a type ERROR

Post by _phillip »

Thank you. I will try to implement that info in the sketch.
I appreciate your help.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”