From 0decbbc7b231015b2f431fe71cbc41656807a309 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 20 Apr 2018 15:33:49 +0100 Subject: add a watchdog --- sensor/thermostat.ino | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sensor/thermostat.ino') 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); -- cgit v1.2.3