Je veux instant Alertes SMS de votre ESP32 sans compter sur un module GSM volumineux? Qu’il s’agisse de détection de mouvement, d’un pic de température soudain ou d’une ouverture de porte de casier non autorisée, votre ESP32 peut désormais envoyer des notifications SMS en temps réel directement à votre téléphone, en utilisant simplement le Wi-Fi et une API gratuite de Circuit Digest Cloud.
La plupart des projets IoT vous obligent à vérifier constamment une application ou un tableau de bord Web pour rester à jour. Mais avec ce système d’alerte basé sur SMS intelligent, votre ESP32 devient un chien de garde proactif, poussant des mises à jour importantes directement dans votre boîte de réception de smartphone, même lorsque vous êtes hors ligne à partir d’applications ou de tableaux de bord. Et la meilleure partie? Pas de frais mensuels, pas de cartes SIM, juste du code et du Wi-Fi.
Dans cet article, nous allons vous montrer comment vous pouvez lire les données de température d’un DHT11 et envoyer les valeurs à un smartphone en tant que SMS à l’aide de la carte ESP32. Alors commençons.








#include
#include
#include
#define Temp_SensorPin 23
DHT_Unified dht(Temp_SensorPin, DHT11);
// WiFi credentials
const char *ssid = "Semicon Media"; // Your network SSID (from arduino_secrets.h)
const char *password = "xxxxxxxxxx"; // Your network password (from arduino_secrets.h)
float temperature = 0.0;
//Functiom to read the temperature data from the DHT11 sensor
void read_temperature(){
sensors_event_t event;
dht.temperature().getEvent(&event);
temperature = event.temperature;
Serial.println(temperature);
delay(200);
}
void sendSMS() {
if (WiFi.status() == WL_CONNECTED) {
WiFiClient client; // Initialize WiFi client
String apiUrl = "/send_sms?ID=" + String(templateID);
Serial.print("Connecting to server...");
if (client.connect("www.raspberryme.cloud", 80)) { // Connect to the server
Serial.println("connected!");
// Create the HTTP POST request
String payload = "{\"mobiles\":\"" + String(mobileNumber) +
"\",\"var1\":\"" + String(var1) +
"\",\"var2\":\"" + String(var2) + "\"}";
// Send HTTP request headers
client.println("POST " + apiUrl + " HTTP/1.1");
client.println("Host: www.raspberryme.cloud");
client.println("Authorization: " + String(apiKey));
client.println("Content-Type: application/json");
client.println("Content-Length: " + String(payload.length()));
client.println(); // End of headers
client.println(payload); // Send the JSON payload
// Wait for the response
int responseCode = -1; // Variable to store HTTP response code
while (client.connected() || client.available()) {
if (client.available()) {
String line = client.readStringUntil('\n'); // Read a line from the response
Serial.println(line); // Print the response line (for debugging)
// Check for the HTTP response code
if (line.startsWith("HTTP/")) {
responseCode = line.substring(9, 12).toInt(); // Extract response code (e.g., 200, 404)
Serial.print("HTTP Response Code: ");
Serial.println(responseCode);
}
// Stop reading headers once we reach an empty line
if (line == "\r") {
break;
}
}
}
// Check response
if (responseCode == 200) {
Serial.println("SMS sent successfully!");
} else {
Serial.print("Failed to send SMS. Error code: ");
Serial.println(responseCode);
}
client.stop(); // Disconnect from the server
} else {
Serial.println("Connection to server failed!");
}
} else {
Serial.println("WiFi not connected!");
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// We start by connecting to a WiFi network
Serial.println();
Serial.println("******************************************************");
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
dht.begin();
}
void loop() {
read_temperature();
if(temperature >= 30.00){
sendSMS();
//Stop sending further SMS alerts until the temperature gets back to 28
while(temperature > 28){
read_temperature();
}
}
}



Projets utilisant une API SMS Digest Circuit





Retrouvez l’histoire de Raspberry Pi dans cette vidéo :

-
ELEGOO 3PCS Carte de Développement ESP32 Type-C, 2,4 GHz WiFi + Bluetooth Dual Core Carte de Contrôle pour Arduino, Support MicroPython, NodeMCU, AP/STA/AP+STA, Puce CP2102
-
Ulegqin avec ESP32 S3 ESP32-S3 DevKitC-1-N16R8 Carte de développement avec Deux interfaces Type-C et 2,4-GHz WLAN Bluetooth 5.0 Soudure Compatible avec Arduino(2 Pièces)
