#include #include #include // https://github.com/tzapu/WiFiManager WiFiManager wm; WiFiUDP Udp; #define WAKE_UP_PIN D3 // D3/GPIO0 void doSomeWifi() { Udp.begin(31337); Udp.beginPacket("255.255.255.255", 31337); Udp.write("Hello from ESP!\n"); Udp.endPacket(); } void setup() { WiFi.mode(WIFI_STA); Serial.begin(115200); wm.setConnectTimeout(60); //Autoconnect to Wifi (or do soft AP) bool res; res = wm.autoConnect(); if(!res) { Serial.println("Failed to connect"); } else { Serial.println("connected..."); } pinMode(WAKE_UP_PIN, INPUT_PULLUP); //Start webPortal std::vector menu = {"wifi","info","param","sep","erase", "restart"}; wm.setMenu(menu); wm.startWebPortal(); WiFi.setSleepMode(WIFI_LIGHT_SLEEP, 3); // Automatic Light Sleep, DTIM listen interval = 3 } const unsigned long AWAKE_SECONDS = 10; static uint32_t millis_last_reset = 0; void loop() { wm.process(); //Stay awake for a few seconds if (millis()-millis_last_reset > AWAKE_SECONDS * 1000) { Serial.println("Going to sleep"); while (digitalRead(WAKE_UP_PIN)) { delay(350); // Any value between 100--500 will work, higher value more power savings // but also slower wakeup! wm.process(); } Serial.println("Woke up!"); doSomeWifi(); while (!digitalRead(WAKE_UP_PIN)) { // now wait for them to release the pushbutton delay(10); } millis_last_reset = millis(); } }