Benutzer-Werkzeuge

Webseiten-Werkzeuge


projekte.haberland.it:arduino:projekte:esp-deep-sleep

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
projekte.haberland.it:arduino:projekte:esp-deep-sleep [2019/04/05 17:20] – [Code] Raffael Haberlandprojekte.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 =====
 <code> <code>
- 
- 
-#include <ESP8266WiFi.h> 
-#include <WiFiClientSecure.h> 
-#include <UniversalTelegramBot.h> 
-#include <ArduinoJson.h> 
- 
-char ssid[] = "WLAN-SSID";         // your network SSID (name) 
-char password[] = "WLAN-PASS"; // your network password 
-#define TELEGRAM_BOT_TOKEN "yyyyyy-zzzz" 
- 
-// This is the Wifi client that supports HTTPS 
-WiFiClientSecure client; 
-UniversalTelegramBot bot(TELEGRAM_BOT_TOKEN, client); 
  
 void setup() { void setup() {
-  boolean sleep = false; +  // put your setup code here, to run once:
-  boolean first = true;+
  
-  Serial.begin(115200); 
-  Serial.println("initial"); 
-  pinMode(LED_BUILTIN, OUTPUT); 
-  digitalWrite(LED_BUILTIN, LOW); 
- 
-  // 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("Connecting Wifi: "); 
-  Serial.println(ssid); 
-  WiFi.begin(ssid, password); 
- 
-  while (WiFi.status() != WL_CONNECTED) { 
-    Serial.print("."); 
-    delay(500); 
-  } 
- 
-  Serial.println("WiFi connected"); 
-  Serial.print("IP address: "); 
-  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("sleeping"); 
-      ESP.deepSleep(60e6); //sleep for 10 seconds max 71min 
-    } 
-    else { 
-      Serial.println("else"); 
-      for (int i = 0; i < numNewMessages; i++) { 
-        String chat_id = String(bot.messages[i].chat_id); 
-        String text = bot.messages[i].text; 
- 
-        if (first) { 
-          if (sleep) { 
-            bot.sendMessage(chat_id, "sleep : true\n", "Markdown"); 
-          } else { 
-            bot.sendMessage(chat_id, "sleep : false\n", "Markdown"); 
-          } 
-          boolean first = false; 
-        } 
- 
-        if (text == F("/ip")) { 
-          bot.sendMessage(chat_id, "local IP: 127.0.0.1\n", "Markdown"); 
-        } 
-        else if (text == F("/temp")) { 
-        } 
-        else if (text == F("/wake")) { 
-          bot.sendMessage(chat_id, "sleep : false\n", "Markdown"); 
-          sleep = false; 
-        } 
-        else if (text == F("/sleep")) { 
-          bot.sendMessage(chat_id, "sleep : true\n", "Markdown"); 
-          sleep = true; 
-        } 
-        else { 
-          Serial.println("else"); 
-          if (sleep) { 
-            bot.sendMessage(chat_id, "sleep : true\n", "Markdown"); 
-          } else { 
-            bot.sendMessage(chat_id, "sleep : false\n", "Markdown"); 
-          } 
-          bot.sendMessage(chat_id, "/sleep : go to sleep for 1 minute\n", "Markdown"); 
-          bot.sendMessage(chat_id, "/wake : stay awake\n", "Markdown"); 
-        } 
-      } 
-    } 
-  } 
 } }
  
 void loop() { void loop() {
 +  // put your main code here, to run repeatedly: 
 +   
 +  ESP.deepSleep(60e6); //sleep for 60 seconds maximal 71 minutes 
 +   
 +  WiFi.forceSleepBegin(); 
 +  WiFi.forceSleepWake();
 } }
  
 </code> </code>
projekte.haberland.it/arduino/projekte/esp-deep-sleep.1554477636.txt.gz · Zuletzt geändert: 2020/05/12 11:44 (Externe Bearbeitung)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki