#include "DHT.h"
#include <HTTPClient.h>
#include <WiFi.h>
#include <UrlEncode.h>
const int DHT_PIN = 15;
DHT dht(DHT_PIN, DHT22);
String apiKey = "9205800";
String phoneNumber = "212634653426";
const char* ssid = "Wokwi-GUEST";
const char* password = "";
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
Serial.print("Connection en cours");
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(100);
}
Serial.println("\nConnecte");
}
void loop() {
float hum = dht.readHumidity();
float temp = dht.readTemperature();
String msg = "";
if (isnan(hum) || isnan(temp) ){
Serial.println(F("Failed to read from DHT sensor!"));
}else{
String Temp = "Temperature : "+String(temp)+" C";
String Hum = "Humidite : "+String(hum)+" %";
msg = Temp+"\n"+Hum;
String url = "https://api.callmebot.com/whatsapp.php?phone="+phoneNumber+"&text="+urlEncode(msg)+"&apikey="+apiKey;
HTTPClient http;
http.begin(url);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int code = http.POST(url);
http.end();
if(code == 200){
Serial.println("Envoie avec succes");
}else{
Serial.println("Erreur dans l'envoie a L'API");
}
}
delay(10000);
}