#include <WiFi.h>
#include<HTTPClient.h>
#include <ArduinoJson.h>// Click here to get the library: http://librarymanager/All#DHTesp
#include <DHTesp.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
String payload;
const String url = "http://api.thingspeak.com/channels/2306663/feeds.json?api_key=RTPS8POVWMZX9BRQ&results=2";
const String urlweather ="http://api.open-meteo.com/v1/forecast?latitude=36.8335346&longitude=10.1453841¤t_weather=true";
DHTesp dht;
WiFiClient wifi;
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void updatevaleur(){
HTTPClient http;
Serial.print();
http.begin(thingspeaksever);
http.addheader
serializeJson(doooc, payload);
}
void lecturevaleur()
{
HTTPClient http;
http.begin(urlweather);
int httpResponseCode = http.GET();
if (httpResponseCode > 0) {
Serial.print("HTTP ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println("Json file=");
Serial.println (payload);
StaticJsonDocument<1024> doooc;
deserializeJson(doooc, payload);
float temperature_weather=doooc["current_weather"]["temperature"];
Serial.println("temperature_weather = ");
Serial.println(temperature_weather);
dht.setup(15, DHTesp::DHT22); //connect DHt sensor to Gpio 17
float temperature_dht =dht.getTemperature();
Serial.println("temperature_dht=");
Serial.println("temperature_dht");
float moyenne= (temperature_weather +temperature_dht)/2;
Serial.println("moyenne");
Serial.println(moyenne);
http.end();
}
else{
Serial.print("Error code:");
Serial.println(httpResponseCode);
Serial.println(":-(");
}
delay(10000);
}
void loop()
{
lecturevaleur();
delay(8000);
}