Sommaire
Dans ce tutoriel, nous allons découvrir comment faire clignoter une LED branchée à un ESP8266 dès lors qu’on a un SMS non lu, en clair un “Alerteur d’SMS connecté » !
Prérequis
Pour réaliser ce tutoriel, vous aurez besoin :
- D’un ESP8266
- D’une LED (et sa résistance)
- Du package PushBullet
- D’un smartphone Android
Configuration
// A venir ..
Montage
// A venir ..
Code
// A venir ..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
#include <Constellation.h> #include <ESP8266WiFi.h> char ssid[] = "MON-RESEAU-WIFI"; char password[] = "clé WIfi ici !!!!"; Constellation<WiFiClient> constellation("serveur.constellation.lan", 8888, "ESP8266", "SMSNotifier", "AccessKeyIci"); bool blinkLed = false; int ledState = LOW; unsigned long previousMillis = 0; const int ledPin = D5; // ou LED_BUILTIN; const long interval = 1000; void setup(void) { // Init Serial Serial.begin(115200); delay(10); // Init LED pinMode(ledPin, OUTPUT); // Connecting to Wifi Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi connected. IP: "); Serial.println(WiFi.localIP()); // Register the MessageCallback constellation.registerMessageCallback("ReceiveEphemeral", [](JsonObject & json) { String type = String(json["Data"]["type"].asString()); if (type == "sms_changed") { Serial.println("New SMS received"); blinkLed = true; } else if (type == "dismissal") { Serial.println("SMS readed"); blinkLed = false; } }); // Subscribe to PushBullet group constellation.subscribeToGroup("PushBullet"); // Ready constellation.writeInfo("SMS Notifier started !"); } void driveLed() { if (blinkLed) { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; ledState = (ledState == LOW) ? HIGH : LOW; // Switches led state } } else ledState = LOW; digitalWrite(ledPin, ledState); } void loop(void) { constellation.loop(); driveLed(); } |
// A venir ..
Conclusion
// A venir ..
Etre alerté d’un SMS avec une LED et un Arduino/ESP
Editer la page sur GitHub
Démarrez la discussion sur le forum Constellation