summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);