HTTPClient.h issues

Morning everyone, I cannot compile my sketch on Platformio. I got the following msg error.
src\main.cpp: In function ‘void loop()’:
src\main.cpp:179:16: error: no matching function for call to ‘HttpClient::HttpClient()’
my platformio.ini is as this:

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
upload_port = COM4

lib_deps =
    me-no-dev/AsyncTCP@^1.1.1
    me-no-dev/ESP Async WebServer@^1.2.3
    adafruit/Adafruit BMP085 Library@^1.2.1
    adafruit/Adafruit BusIO@^1.10.1
    SPI
    adafruit/DHT sensor library@^1.4.3
    amcewen/HttpClient@^2.2.0

For info I m working on Windows. Some guys in other forums told me that my sketch running well under linux for info. Thanks for your help. Appreciate any ideas.

my sketch is:

#include <Arduino.h>
#include <ESPAsyncWebServer.h>
#include <SPIFFS.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <WiFi.h>
#include <HttpClient.h>
Adafruit_BMP085 bmp;

unsigned long last_time = 0;
unsigned long timer_delay = 10000;

 //here we use 4 of ESP32 to read data

  #define DHTPIN 18
  //our sensor is DHT11 type
  #define DHTTYPE DHT11
  //create an instance of DHT sensor
 DHT dht(DHTPIN, DHTTYPE);

const char *ssid = "XXXX";
const char *password = "XXX";

const char* serverName = "https://XXX.php";

// Keep this API Key value to be compatible with the PHP code provided in the project page.
// If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key

String apiKeyValue = "xxx";

AsyncWebServer server(80);

void setup()

{

  //----------------------------------------------------Serial

  Serial.begin(115200);
  Serial.println("\n");

  //----------------------------------------------------GPIO

                

  //----------------------------------------------------SPIFFS

  if(!SPIFFS.begin())
  {
    Serial.println("Erreur SPIFFS...");
    return;
  }

  File root = SPIFFS.open("/");
  File file = root.openNextFile();
  while(file)
  {
    Serial.print("File: ");
    Serial.println(file.name());
    file.close();
    file = root.openNextFile();
  }

  //----------------------------------------------------WIFI

  WiFi.begin(ssid, password);
  Serial.print("Tentative de connexion...");

  while(WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(100);
  }
  Serial.println("\n");
  Serial.println("Connexion etablie!");
  Serial.print("Adresse IP: ");
  Serial.println(WiFi.localIP());

 dht.begin();

  //----------------------------------------------------SERVER

  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    request->send(SPIFFS, "/index.html", "text/html");
  });

  server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    request->send(SPIFFS, "/style.css", "text/css");
  });

  server.on("/script.js", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    request->send(SPIFFS, "/script.js", "text/javascript");
  });

   server.on("/script.js", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    request->send(SPIFFS, "/jquery-3.4.1.min.js", "text/javascript");
  });

  server.on("/lireTemperature", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    double val_temp = bmp.readTemperature();
    String Temperature=String(val_temp);
    request->send(200, "text/plain", Temperature);
  });

   server.on("/lireTemperatureDHT", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    double val_tempDHT =  dht.readTemperature();
    String TemperatureDHT=String(val_tempDHT);
    request->send(200, "text/plain", TemperatureDHT);
  });

  server.on("/lirePression", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    int val_pression=bmp.readPressure()/100;
    String Pression=String(val_pression);
    request->send(200, "text/plain", Pression);
  });

  server.on("/lireAltitude", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    int val_altitude=bmp.readAltitude(103200);
    String Altitude=String(val_altitude);
    request->send(200, "text/plain", Altitude);
  });

  server.on("/lireHumidite", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    int val_humidite=dht.readHumidity();
    String Humidite=String(val_humidite);
    request->send(200, "text/plain", Humidite);
  });

  server.begin();

  Serial.println("Serveur actif!");
  if (!bmp.begin()) {
  Serial.println("Could not find a valid BMP085/BMP180 sensor, check wiring!");
  while (1) {}
  }
}

 

void loop() {
   //Send an HTTP POST request every 10 seconds
  if((millis()-last_time) > timer_delay) {

 

    if(WiFi.status()== WL_CONNECTED){

 

    HttpClient http;

          

    WiFiClient client;

      http.begin(client,serverName);

     

      http.addHeader("Content-Type", "application/x-www-form-urlencoded");

//Data to send with HTTP POST

      String httpRequestData = "api_key=" + apiKeyValue + "&humidity=" +dht.readHumidity()

                          + "&temperature=" + dht.readTemperature() + "";      

      // Send HTTP POST request

      int httpResponseCode = http.POST(httpRequestData);

                 

      //http.addHeader("Content-Type", "application/json");

      // JSON data to send with HTTP POST

      //String httpRequestData = "{\"api_key\":\"" + my_Api_Key + "\",\"field1\":\"" + String(random(50)) + "\"}";          

      // Send HTTP POST request

     // int httpResponseCode = http.POST(httpRequestData);

     

      Serial.print("HTTP Response code is: ");

      Serial.println(httpResponseCode);

      http.end();

    }

    else {

      Serial.println("WiFi is Disconnected!");

    }

    }

    last_time = millis();

  }

o_O? The HTTPClient library is provided by the Arduino-ESP32 core through arduino-esp32/libraries/HTTPClient at 1.0.6 · espressif/arduino-esp32 · GitHub. Please remove that library dependency. No statement is needed to use built-in core libraries.

Thank I am a beginner and my question may be stupid. how can I drag and drop the files into my project. I cannot do it easily as there is no link to download the library? thanks for your help.
for info I have removed the previous library that i installed. httpclient is no more in my library and i got this message:
src\main.cpp: In function ‘void loop()’:
src\main.cpp:179:5: error: ‘HttpClient’ was not declared in this scope
HttpClient http;
^
src\main.cpp:183:7: error: ‘http’ was not declared in this scope
http.begin(client,serverName);

The class name is

not HttpClient.

If the files you refer to is a library, best to use lib_deps in the platformio.ini with the expression found for the library in https://registry.platformio.org/.

Otherwise, copy them in a new folder in lib/ or put them in src/.

Thanks for all. but I still got an error src\main.cpp:10:24: fatal error: HTTPClient.h: No such file or directory.

I cannot reproduce your problem. Using

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
upload_port = COM4

lib_deps =
    me-no-dev/AsyncTCP@^1.1.1
    me-no-dev/ESP Async WebServer@^1.2.3
    adafruit/Adafruit BMP085 Library@^1.2.1
    adafruit/Adafruit BusIO@^1.10.1
    SPI
    adafruit/DHT sensor library@^1.4.3

with a src/main.cpp of

#include <Arduino.h>
#include <ESPAsyncWebServer.h>
#include <HTTPClient.h>
#include <Adafruit_BMP085.h>
#include <DHT.h>
#include <DHT_U.h>

HTTPClient http;

void setup() {}
void loop() {}

leads to a successful compilation.

RAM:   [          ]   4.2% (used 13816 bytes from 327680 bytes)
Flash: [==        ]  19.9% (used 261286 bytes from 1310720 bytes)
Building .pio\build\esp32doit-devkit-v1\firmware.bin
esptool.py v3.1
Merged 1 ELF section
============== [SUCCESS] Took 12.98 seconds ==============

Can you show the full code and current platformio.ini again?

I see it s ok for you.
=>please find the error msg I got (sorry this is in french): [{
“resource”: “/c:/Users/Laurent/Documents/PlatformIO/Projects/Barometer_PIO/src/main.cpp”,
“owner”: “C/C++”,
“code”: “1696”,
“severity”: 8,
“message”: “Erreurs #include détectées. Mettez à jour includePath. Les tildes sont désactivés pour cette unité de traduction (C:\Users\Laurent\Documents\PlatformIO\Projects\Barometer_PIO\src\main.cpp).”,
“source”: “C/C++”,
“startLineNumber”: 4,
“startColumn”: 1,
“endLineNumber”: 4,
“endColumn”: 24
}]

#include <Arduino.h>

#include <ESPAsyncWebServer.h>

#include <HTTPClient.h>

#include <Adafruit_BMP085.h>

#include <DHT.h>

#include <DHT_U.h>

HTTPClient http;

HTTPClient http;

Adafruit_BMP085 bmp;

unsigned long last_time = 0;

unsigned long timer_delay = 10000;

 //here we use 4 of ESP32 to read data

  #define DHTPIN 18

  //our sensor is DHT11 type

  #define DHTTYPE DHT11

  //create an instance of DHT sensor

 DHT dht(DHTPIN, DHTTYPE);

const char *ssid = "xxxx";

const char *password = "xxxx";

const char* serverName = "xxxx";

// Keep this API Key value to be compatible with the PHP code provided in the project page.

// If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key

String apiKeyValue = "xxx";

AsyncWebServer server(80);

void setup()

{

  //----------------------------------------------------Serial

  Serial.begin(115200);

  Serial.println("\n");

  //----------------------------------------------------GPIO

                

  //----------------------------------------------------SPIFFS

  if(!SPIFFS.begin())

  {

    Serial.println("Erreur SPIFFS...");

    return;

  }

  File root = SPIFFS.open("/");

  File file = root.openNextFile();

  while(file)

  {

    Serial.print("File: ");

    Serial.println(file.name());

    file.close();

    file = root.openNextFile();

  }

  //----------------------------------------------------WIFI

  WiFi.begin(ssid, password);

  Serial.print("Tentative de connexion...");

 

  while(WiFi.status() != WL_CONNECTED)

  {

    Serial.print(".");

    delay(100);

  }

 

  Serial.println("\n");

  Serial.println("Connexion etablie!");

  Serial.print("Adresse IP: ");

  Serial.println(WiFi.localIP());

 //Serial.println("DHT11 sensor!");

  //call begin to start sensor

  //dht.begin();

  //use the functions which are supplied by library.

 //float humidite = dht.readHumidity();

  // Read temperature as Celsius (the default)

  //float temperature = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).

  // if (isnan(humidite) || isnan(temperature)) {

  //   Serial.println("Failed to read from DHT sensor!");

   // return;

  // }

 dht.begin();

  //----------------------------------------------------SERVER

  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)

  {

    request->send(SPIFFS, "/index.html", "text/html");

  });

  server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest *request)

  {

    request->send(SPIFFS, "/style.css", "text/css");

  });

  server.on("/script.js", HTTP_GET, [](AsyncWebServerRequest *request)

  {

    request->send(SPIFFS, "/script.js", "text/javascript");

  });

   server.on("/script.js", HTTP_GET, [](AsyncWebServerRequest *request)

  {

    request->send(SPIFFS, "/jquery-3.4.1.min.js", "text/javascript");

  });

  server.on("/lireTemperature", HTTP_GET, [](AsyncWebServerRequest *request)

  {

    double val_temp = bmp.readTemperature();

    String Temperature=String(val_temp);

    request->send(200, "text/plain", Temperature);

  });

   server.on("/lireTemperatureDHT", HTTP_GET, [](AsyncWebServerRequest *request)

  {

    double val_tempDHT =  dht.readTemperature();

    String TemperatureDHT=String(val_tempDHT);

    request->send(200, "text/plain", TemperatureDHT);

  });

  server.on("/lirePression", HTTP_GET, [](AsyncWebServerRequest *request)

  {

   

    int val_pression=bmp.readPressure()/100;

    String Pression=String(val_pression);

    request->send(200, "text/plain", Pression);

  });

  server.on("/lireAltitude", HTTP_GET, [](AsyncWebServerRequest *request)

  {

   

    int val_altitude=bmp.readAltitude(103200);

    String Altitude=String(val_altitude);

    request->send(200, "text/plain", Altitude);

  });

  server.on("/lireHumidite", HTTP_GET, [](AsyncWebServerRequest *request)

  {

   

    int val_humidite=dht.readHumidity();

    String Humidite=String(val_humidite);

    request->send(200, "text/plain", Humidite);

  });

  server.begin();

  Serial.println("Serveur actif!");

  if (!bmp.begin()) {

  Serial.println("Could not find a valid BMP085/BMP180 sensor, check wiring!");

  while (1) {}

  }

}

 

void loop() {

   //Send an HTTP POST request every 10 seconds

  if((millis()-last_time) > timer_delay) {

 

    if(WiFi.status()== WL_CONNECTED){

                  

      http.begin(serverName);

     

      http.addHeader("Content-Type", "application/x-www-form-urlencoded");

//Data to send with HTTP POST

      String httpRequestData = "api_key=" + apiKeyValue + "&humidity=" +dht.readHumidity()

                          + "&temperature=" + dht.readTemperature() + "";      

      // Send HTTP POST request

      int httpResponseCode = http.POST(httpRequestData);

                 

      //http.addHeader("Content-Type", "application/json");

      // JSON data to send with HTTP POST

      //String httpRequestData = "{\"api_key\":\"" + my_Api_Key + "\",\"field1\":\"" + String(random(50)) + "\"}";          

      // Send HTTP POST request

     // int httpResponseCode = http.POST(httpRequestData);

     

      Serial.print("HTTP Response code is: ");

      Serial.println(httpResponseCode);

      http.end();

    }

    else {

      Serial.println("WiFi is Disconnected!");

    }

    }

    last_time = millis();

 

  }
[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
upload_port = COM4
lib_deps =
    me-no-dev/AsyncTCP@^1.1.1
    me-no-dev/ESP Async WebServer@^1.2.3
    adafruit/Adafruit BMP085 Library@^1.2.1
    adafruit/Adafruit BusIO@^1.10.1
    SPI
    adafruit/DHT sensor library@^1.4.3

This is a VSCode Intellisense error. Intellisense is updated after a build or with Ctrl+Shift+P → Rebuild IntelliSense.

Does the Build button throw an error via GCC? What’s the exact message?

src\main.cpp:4:24: fatal error: HTTPClient.h: No such file or directory


  • Looking for HTTPClient.h dependency? Check our library registry!
  • CLI > platformio lib search “header:HTTPClient.h”
  • Web > PlatformIO Registry

compilation terminated.
*** [.pio\build\esp32doit-devkit-v1\src\main.cpp.o] Error 1

Something is not adding up. First of all I get different errors from the code you posted because it does not include FS.h and SPIFFS.h, and it double-creates the http object. Fixing that, the code compiles fine.

Please remove the .pio hidden folder inside the project and replace the src/main.cpp with #include <Arduino.h>#include <ESPAsyncWebServer.h>#include <HTTPClient.h># - Pastebin.com.

still the same issue
Looking for HTTPClient.h dependency? Check our library registry!
*


compilation terminated.
*** [.pio\build\esp32doit-devkit-v1\src\main.cpp.o] Error 1

Remove the folders

  • <home folder>\.platformio\.cache
  • <home folder>\.platformio\lib
  • <home folder>\.platformio\packages\framework-arduinoespressif32

and retry.

1 Like

SUCCESS!!! Thanks a lot. what was the issue?

Either your Arduino-ESP32 framework package was corrupted or you globally installed the erronous amcewen/HttpClient in PlatformIO. This will prevent the Arduino-ESP32’s internal HTTPClient.h library to be picked up.

I really appreciate your help. Take care!