summaryrefslogtreecommitdiff
path: root/sensor/thermostat.ino
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2018-08-03 11:52:24 +0100
committerdakkar <dakkar@thenautilus.net>2018-08-03 11:52:24 +0100
commit91684eb9d20606a134ed0da5756dc6551d61874a (patch)
tree8018bd9df70cc2336ecea3f9f9d4ffe376c4d61b /sensor/thermostat.ino
parentworking CHIP sender (diff)
downloadthermostat-91684eb9d20606a134ed0da5756dc6551d61874a.tar.gz
thermostat-91684eb9d20606a134ed0da5756dc6551d61874a.tar.bz2
thermostat-91684eb9d20606a134ed0da5756dc6551d61874a.zip
move stuff to setup() & teardown
Diffstat (limited to 'sensor/thermostat.ino')
-rw-r--r--sensor/thermostat.ino46
1 files changed, 22 insertions, 24 deletions
diff --git a/sensor/thermostat.ino b/sensor/thermostat.ino
index 2416caa..b6d4102 100644
--- a/sensor/thermostat.ino
+++ b/sensor/thermostat.ino
@@ -36,6 +36,8 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
BLEAdvertisedDeviceCallbacks(),
pServerAddress(0)
{}
+
+ ~MyAdvertisedDeviceCallbacks() { if (pServerAddress) delete pServerAddress; }
void onResult(BLEAdvertisedDevice advertisedDevice) {
// We have found a device, let us now see if it contains the service we are looking for.
@@ -126,25 +128,33 @@ uint32_t send_data_and_get_time(BLEAddress* pAddress,String* data) {
void setup() {
display.init();
display.connect();
+ display.displayOn();
+ display.clear();
+ show("setup");
BLEDevice::init("");
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, BLE_POWER);
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, BLE_POWER);
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, BLE_POWER);
+ show("setup+bt");
+ enable_sensor(true);
+ show("setup+bt+sensor");
}
-void watchdog_cb() {
- show("watchdog");
+void teardown_and_sleep(int next_time) {
enable_sensor(false);
+ //BLEDevice::uninit();
+ //esp_wifi_stop();
delay(2000);
- esp_sleep_enable_timer_wakeup(ON_ERROR_SLEEP_TIME * uS_TO_S_FACTOR);
+ esp_sleep_enable_timer_wakeup(next_time * uS_TO_S_FACTOR);
esp_deep_sleep_start();
}
-void loop() {
- display.displayOn();
- display.clear();
- enable_sensor(true);
+void watchdog_cb() {
+ show("watchdog");
+ teardown_and_sleep(ON_ERROR_SLEEP_TIME);
+}
+void loop() {
Ticker watchdog_timer;
watchdog_timer.attach(WATCHDOG_SECONDS,watchdog_cb);
@@ -177,24 +187,12 @@ void loop() {
next_time = NO_SERVER_SLEEP_TIME;
}
+ delete cb;
+
String nt = "Next time:";nt+=next_time;
display.drawString(0,20,nt);display.display();
- enable_sensor(false);
- delay(2000);
- esp_sleep_enable_timer_wakeup(next_time * uS_TO_S_FACTOR);
- esp_deep_sleep_start();
-
- /* display.clear(); */
+ teardown_and_sleep(next_time);
- /* String line; */
- /* line = "T:"; line += temperature; */
- /* display.drawString(0,0,line); */
- /* line = "H:"; line += humidity; */
- /* display.drawString(50,0,line); */
- /* display.drawString(0,10,dht.getStatusString()); */
-
- /* display.drawProgressBar(5,25,120,10,int(temperature)); */
- /* display.drawProgressBar(5,40,120,10,int(humidity)); */
-
- /* display.display(); */
+ show("woken up");
+ delay(2000);
}