Created
April 17, 2021 13:03
-
-
Save Tech-TX/f334fb679b9621e34902830efc229776 to your computer and use it in GitHub Desktop.
Auto Sleep tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <Schedule.h> | |
#include <PolledTimeout.h> | |
const char* AP_SSID = ""; // your router's SSID here | |
const char* AP_PASS = ""; // your router's password here | |
void setup() { | |
Serial.begin(74880); | |
while (!Serial); | |
delay(100); | |
Serial.println("AutoLightSleep"); | |
Serial.flush(); | |
initWiFi(); | |
} | |
void loop() { | |
delay(10000); // this enters the idle task | |
Serial.println("entering auto sleep section"); | |
Serial.flush(); | |
//ESP.autoLightSleep(); // doesn't work, never goes to Auto Light Sleep | |
wifi_set_sleep_type(LIGHT_SLEEP_T); | |
//ESP.autoModemSleep(); | |
delay(10000); // this enters the idle task with auto light sleep | |
ESP.autoSleepOff(); | |
Serial.println("left auto sleep section"); | |
Serial.flush(); | |
} | |
void initWiFi() { | |
WiFi.persistent(true); // store the connection for auto-reconnect at boot | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(AP_SSID, AP_PASS); | |
Serial.print(F("connecting to WiFi ")); | |
Serial.println(AP_SSID); | |
Serial.print(F("my MAC: ")); | |
Serial.println(WiFi.macAddress()); | |
while ((!WiFi.localIP()) || (WiFi.status() != WL_CONNECTED)) { | |
delay(100); | |
} | |
Serial.println(F("WiFi connected")); | |
Serial.print(F("WiFi Gateway IP: ")); | |
Serial.println(WiFi.gatewayIP()); | |
Serial.print(F("my IP address: ")); | |
Serial.println(WiFi.localIP()); | |
WiFi.setAutoReconnect(true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment