Marijn78

Untitled

Jul 6th, 2020
87
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const bool debug = true;
  2. #define TIME_TO_SLEEP 20000
  3. #define mS_TO_S_FACTOR 1000
  4. #define NUM_LIGHTS 63
  5. typedef struct {
  6.   byte id; // Id of the the light in the bridge
  7.   byte type; //1=Dimmable light, 2=Color temperature light, 3=Color light, 4=Smart Plug
  8. } light_t;
  9. typedef struct {
  10.   light_t lights[NUM_LIGHTS];
  11.   // other persistent info goes here
  12. } rtc_data_t;
  13. RTC_DATA_ATTR rtc_data_t saved_state;
  14. RTC_DATA_ATTR int bootCount = 0;
  15.  
  16. void deepSleep() {
  17.   esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * mS_TO_S_FACTOR);
  18.   if (debug) {
  19.     Serial.println("Going to sleep now for " + String(TIME_TO_SLEEP) + " milliseconds");
  20.     Serial.println("");
  21.   }
  22.   if (debug) Serial.flush();
  23.   esp_deep_sleep_start();
  24. }
  25.  
  26. void setSerial() {
  27.   Serial.begin(115200);
  28.   while (!Serial) continue;
  29. }
  30.  
  31. void setup() {
  32.   if (debug) setSerial();
  33.   ++bootCount;
  34.  
  35.   if (bootCount == 1) {
  36.     light_t light_1 = { 1, 1 };
  37.     light_t light_2 = { 2, 1 };
  38.     light_t saved_state[NUM_LIGHTS];
  39.     saved_state[0] = light_1;
  40.     saved_state[1] = light_2;
  41.     //saved_state = { light_1, light_2 };  
  42.   } else {
  43.     //print RTC contents..
  44.     ?
  45.   }
  46.   deepSleep();
  47. }
  48.  
  49. void loop() {
  50.  
  51. }
RAW Paste Data