Advertisement
Guest User

Untitled

a guest
Jan 27th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <include/WiFiState.h>
  3.  
  4. auto sleepDuration{10'000UL};
  5.  
  6. void setup() {
  7. delay (3000);
  8.  
  9. gpio_pin_wakeup_enable(D5, GPIO_PIN_INTR_HILEVEL);
  10. pinMode(LED_BUILTIN, OUTPUT);
  11. Serial.begin(9600);
  12.  
  13. WiFi.mode(WIFI_OFF);
  14. wifi_fpm_set_sleep_type (LIGHT_SLEEP_T);
  15. }
  16.  
  17. auto awakenTime{0UL};
  18.  
  19. void wakeup_cb()
  20. {
  21. wifi_fpm_close();
  22. Serial.printf("cb reached: %lums\n", (awakenTime = millis()));
  23. }
  24.  
  25. void loop()
  26. {
  27. static auto awakeTime{0UL};
  28. static auto sleepTime{0UL};
  29.  
  30. Serial.printf("going to sleep: %lums\n", (sleepTime = millis()));
  31. Serial.flush();
  32.  
  33. wifi_set_opmode_current(NULL_MODE);
  34. wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
  35. wifi_fpm_set_wakeup_cb(wakeup_cb);
  36. wifi_fpm_open();
  37. wifi_fpm_do_sleep(sleepDuration * 1000);
  38. delay(sleepDuration + 1);
  39. Serial.printf("awake: %lums\n", (awakeTime = millis()));
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement