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();
}