Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const bool debug = true;
- #define TIME_TO_SLEEP 20000
- #define mS_TO_S_FACTOR 1000
- #define NUM_LIGHTS 63
- typedef struct {
- byte id; // Id of the the light in the bridge
- byte type; //1=Dimmable light, 2=Color temperature light, 3=Color light, 4=Smart Plug
- } light_t;
- typedef struct {
- light_t lights[NUM_LIGHTS];
- // other persistent info goes here
- } rtc_data_t;
- RTC_DATA_ATTR rtc_data_t saved_state;
- RTC_DATA_ATTR int bootCount = 0;
- void deepSleep() {
- esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * mS_TO_S_FACTOR);
- if (debug) {
- Serial.println("Going to sleep now for " + String(TIME_TO_SLEEP) + " milliseconds");
- Serial.println("");
- }
- if (debug) Serial.flush();
- esp_deep_sleep_start();
- }
- void setSerial() {
- Serial.begin(115200);
- while (!Serial) continue;
- }
- void setup() {
- if (debug) setSerial();
- ++bootCount;
- if (bootCount == 1) {
- light_t light_1 = { 1, 1 };
- light_t light_2 = { 2, 1 };
- light_t saved_state[NUM_LIGHTS];
- saved_state[0] = light_1;
- saved_state[1] = light_2;
- //saved_state = { light_1, light_2 };
- } else {
- //print RTC contents..
- ?
- }
- deepSleep();
- }
- void loop() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement