summaryrefslogtreecommitdiff
path: root/sensor/thermostat.ino
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2018-04-20 15:33:49 +0100
committerdakkar <dakkar@thenautilus.net>2018-04-20 15:33:49 +0100
commit0decbbc7b231015b2f431fe71cbc41656807a309 (patch)
tree19b5bd0d5e1f5a91640a191be88c098178335115 /sensor/thermostat.ino
parentturn off sensor while sleeping (diff)
downloadthermostat-0decbbc7b231015b2f431fe71cbc41656807a309.tar.gz
thermostat-0decbbc7b231015b2f431fe71cbc41656807a309.tar.bz2
thermostat-0decbbc7b231015b2f431fe71cbc41656807a309.zip
add a watchdog
Diffstat (limited to 'sensor/thermostat.ino')
-rw-r--r--sensor/thermostat.ino14
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);