projekte.haberland.it:arduino:projekte:esp-deep-sleep
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| projekte.haberland.it:arduino:projekte:esp-deep-sleep [2019/04/05 17:20] – [Code] Raffael Haberland | projekte.haberland.it:arduino:projekte:esp-deep-sleep [2020/05/12 11:45] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
|---|---|---|---|
| Zeile 5: | Zeile 5: | ||
| ===== Code ===== | ===== Code ===== | ||
| < | < | ||
| - | |||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | char ssid[] = " | ||
| - | char password[] = " | ||
| - | #define TELEGRAM_BOT_TOKEN " | ||
| - | |||
| - | // This is the Wifi client that supports HTTPS | ||
| - | WiFiClientSecure client; | ||
| - | UniversalTelegramBot bot(TELEGRAM_BOT_TOKEN, | ||
| void setup() { | void setup() { | ||
| - | | + | |
| - | boolean first = true; | + | |
| - | Serial.begin(115200); | ||
| - | Serial.println(" | ||
| - | pinMode(LED_BUILTIN, | ||
| - | digitalWrite(LED_BUILTIN, | ||
| - | |||
| - | // Set WiFi to station mode and disconnect from an AP if it was Previously connected | ||
| - | WiFi.mode(WIFI_STA); | ||
| - | WiFi.disconnect(); | ||
| - | delay(100); | ||
| - | |||
| - | // attempt to connect to Wifi network: | ||
| - | Serial.print(" | ||
| - | Serial.println(ssid); | ||
| - | WiFi.begin(ssid, | ||
| - | |||
| - | while (WiFi.status() != WL_CONNECTED) { | ||
| - | Serial.print(" | ||
| - | delay(500); | ||
| - | } | ||
| - | |||
| - | Serial.println(" | ||
| - | Serial.print(" | ||
| - | Serial.println(WiFi.localIP()); | ||
| - | |||
| - | // Only required on 2.5 Beta | ||
| - | client.setInsecure(); | ||
| - | |||
| - | bot.longPoll = 10; | ||
| - | |||
| - | int numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
| - | |||
| - | while (true) { | ||
| - | numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
| - | if (!numNewMessages && sleep) { | ||
| - | Serial.println(" | ||
| - | ESP.deepSleep(60e6); | ||
| - | } | ||
| - | else { | ||
| - | Serial.println(" | ||
| - | for (int i = 0; i < numNewMessages; | ||
| - | String chat_id = String(bot.messages[i].chat_id); | ||
| - | String text = bot.messages[i].text; | ||
| - | |||
| - | if (first) { | ||
| - | if (sleep) { | ||
| - | bot.sendMessage(chat_id, | ||
| - | } else { | ||
| - | bot.sendMessage(chat_id, | ||
| - | } | ||
| - | boolean first = false; | ||
| - | } | ||
| - | |||
| - | if (text == F("/ | ||
| - | bot.sendMessage(chat_id, | ||
| - | } | ||
| - | else if (text == F("/ | ||
| - | } | ||
| - | else if (text == F("/ | ||
| - | bot.sendMessage(chat_id, | ||
| - | sleep = false; | ||
| - | } | ||
| - | else if (text == F("/ | ||
| - | bot.sendMessage(chat_id, | ||
| - | sleep = true; | ||
| - | } | ||
| - | else { | ||
| - | Serial.println(" | ||
| - | if (sleep) { | ||
| - | bot.sendMessage(chat_id, | ||
| - | } else { | ||
| - | bot.sendMessage(chat_id, | ||
| - | } | ||
| - | bot.sendMessage(chat_id, | ||
| - | bot.sendMessage(chat_id, | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | } | ||
| } | } | ||
| void loop() { | void loop() { | ||
| + | // put your main code here, to run repeatedly: | ||
| + | |||
| + | ESP.deepSleep(60e6); | ||
| + | |||
| + | WiFi.forceSleepBegin(); | ||
| + | WiFi.forceSleepWake(); | ||
| } | } | ||
| </ | </ | ||
projekte.haberland.it/arduino/projekte/esp-deep-sleep.1554477636.txt.gz · Zuletzt geändert: 2020/05/12 11:44 (Externe Bearbeitung)
