Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <include/WiFiState.h>
- auto sleepDuration{10'000UL};
- void setup() {
- delay (3000);
- gpio_pin_wakeup_enable(D5, GPIO_PIN_INTR_HILEVEL);
- pinMode(LED_BUILTIN, OUTPUT);
- Serial.begin(9600);
- WiFi.mode(WIFI_OFF);
- wifi_fpm_set_sleep_type (LIGHT_SLEEP_T);
- }
- auto awakenTime{0UL};
- void wakeup_cb()
- {
- wifi_fpm_close();
- Serial.printf("cb reached: %lums\n", (awakenTime = millis()));
- }
- void loop()
- {
- static auto awakeTime{0UL};
- static auto sleepTime{0UL};
- Serial.printf("going to sleep: %lums\n", (sleepTime = millis()));
- Serial.flush();
- wifi_set_opmode_current(NULL_MODE);
- wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
- wifi_fpm_set_wakeup_cb(wakeup_cb);
- wifi_fpm_open();
- wifi_fpm_do_sleep(sleepDuration * 1000);
- delay(sleepDuration + 1);
- Serial.printf("awake: %lums\n", (awakeTime = millis()));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement