#include <WiFi.h>
#include <HTTPClient.h>
#include <UrlEncode.h>
// DHT Code
#include "DHTesp.h"
int pin = 15;
DHTesp sensor;
// DHT Code
const char* ssid = "Wokwi-GUEST";
const char* password = "";
//international country code + phone number
String phoneNumber = "201119669558";
String apiKey = "5007953";
void sendMessage(String message){
// Data to send with HTTP POST
String url = "https://api.callmebot.com/whatsapp.php?phone=6281252834039&apikey=3940101&text=massage";
HTTPClient http;
http.begin(url);
// Specify content-type header
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Send HTTP POST request
int httpResponseCode = http.POST(url);
if (httpResponseCode == 200) {
Serial.print("Message sent successfully");
} else {
Serial.println("Error sending the message");
Serial.print("HTTP response code: ");
Serial.println(httpResponseCode);
}
}
void setup() {
Serial.begin(115200);
// DHT Code
sensor.setup(pin,DHTesp::DHT22);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
// Send Message to WhatsAPP "Add your name + NV number + Class"
// Example: "Hello From Ebrahim - NV21058 - 12.CCP !"
TempAndHumidity data = sensor.getTempAndHumidity();
sendMessage("Temp:"+String(data.temperature,2)+"C" + "\n" + "Humidity:"+String(data.humidity,1)+"%");
}
void loop() {
// additional code will be here
}