diff options
author | dakkar <dakkar@thenautilus.net> | 2018-04-20 15:33:49 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2018-04-20 15:33:49 +0100 |
commit | 0decbbc7b231015b2f431fe71cbc41656807a309 (patch) | |
tree | 19b5bd0d5e1f5a91640a191be88c098178335115 /sensor | |
parent | turn off sensor while sleeping (diff) | |
download | thermostat-0decbbc7b231015b2f431fe71cbc41656807a309.tar.gz thermostat-0decbbc7b231015b2f431fe71cbc41656807a309.tar.bz2 thermostat-0decbbc7b231015b2f431fe71cbc41656807a309.zip |
add a watchdog
Diffstat (limited to 'sensor')
-rw-r--r-- | sensor/thermostat.ino | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/sensor/thermostat.ino b/sensor/thermostat.ino index 2214ae0..2b7236c 100644 --- a/sensor/thermostat.ino +++ b/sensor/thermostat.ino @@ -3,7 +3,7 @@ #include "SSD1306.h" #include "DHTesp.h" #include "BLEDevice.h" -#include "GeneralUtils.h" +#include "Ticker.h" static BLEUUID thermo_service_uuid("11111111-2222-3333-4444-000000000000"); static BLEUUID thermo_temp_uuid("11111111-2222-3333-4444-000000000001"); @@ -11,6 +11,7 @@ static BLEUUID thermo_time_uuid("11111111-2222-3333-4444-000000000002"); #define NO_SERVER_SLEEP_TIME 60 #define ON_ERROR_SLEEP_TIME 30 +#define WATCHDOG_SECONDS 30 /* Conversion factor for micro seconds to seconds */ #define uS_TO_S_FACTOR 1000000 @@ -124,11 +125,22 @@ void setup() { BLEDevice::init(""); } +void watchdog_cb() { + show("watchdog"); + enable_sensor(false); + delay(2000); + esp_sleep_enable_timer_wakeup(ON_ERROR_SLEEP_TIME * uS_TO_S_FACTOR); + esp_deep_sleep_start(); +} + void loop() { display.displayOn(); display.clear(); enable_sensor(true); + Ticker watchdog_timer; + watchdog_timer.attach(WATCHDOG_SECONDS,watchdog_cb); + BLEScan* pBLEScan = BLEDevice::getScan(); MyAdvertisedDeviceCallbacks* cb = new MyAdvertisedDeviceCallbacks(); pBLEScan->setAdvertisedDeviceCallbacks(cb); |