#include <WiFi.h>
#include <HTTPClient.h>
#include <UrlEncode.h>
#include "DHTesp.h"
const int DHT_PIN = 13;
DHTesp dhtSensor;
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// +international_country_code + phone number
// Brasil +55, example:
String phoneNumber = "+5521";
String apiKey = "";
void sendMessage(String message){
// Data to send with HTTP POST
String url = "https://api.callmebot.com/whatsapp.php?phone=" + phoneNumber + "&apikey=" + apiKey + "&text=" + urlEncode(message);
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\n");
}
else{
Serial.println("Error sending the message");
Serial.print("HTTP response code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
float temperature;
float humidity;
String temperatureString = "";
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_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
sendMessage("Olá ESP32!");
delay(1000);
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
// Get latest sensor readings
humidity = data.humidity;
temperature = data.temperature;
temperatureString = "Temp. agora " + String(temperature) + " ºC, com umidade de " + String(humidity) + " %";
sendMessage(temperatureString);
delay(10000);
}
; // this speeds up the simulation