#include "DHTesp.h" // Click here to get the library: http://librarymanager/All#DHTesp
#include <WiFi.h>
#include <HTTPClient.h>
DHTesp xyz ;
WiFiClient client ;
const char* server = "http://api.thingspeak.com/update?";
String myApiKey="HJZTFJVO9LHIE83C";
HTTPClient http ;
const char* ssid ="Wokwi-GUEST";
const char* password = "";
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid,password);
xyz.setup(15, DHTesp::DHT22); // Connect DHT sensor to GPIO 17
Serial.println("Hello,ESP32!");
while (WiFi.status()!=WL_CONNECTED){
delay (500);
Serial.print(".");
}
http.begin(server);
delay(100);
}
void loop()
{
float humidity = xyz.getHumidity();
float temperature = xyz.getTemperature();
float luminosite = 100 ;
Serial.print("temp=");
Serial.print(temperature);
Serial.println("\n");
Serial.print("hum=");
Serial.print(humidity);
Serial.println("\n");
Serial.print("lim=");
Serial.println(luminosite);
Serial.println("\n");
delay(5000);
http.addHeader("Content-Type","application/json");
String httpRequestData ="{\"api_key\": \"" + myApiKey +"\",\"field1\":\""+String(temperature)+"\",\"field2\":\""+ String (humidity )+"\",\"field3\":\""+ String (luminosite)+"\"}" ;
Serial.println(httpRequestData);
int httpResponseCode = http.POST(httpRequestData);
Serial.println(httpResponseCode);
if (httpResponseCode > 0 ){
Serial.println("Succes");
}
else {
Serial.println("eror !! ");
}
delay(10000);
}