summaryrefslogtreecommitdiff
path: root/sensor/thermostat.ino
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2018-04-20 14:55:53 +0100
committerdakkar <dakkar@thenautilus.net>2018-04-20 14:55:53 +0100
commit14c2fd256653b6f7c657c93303183090cf211922 (patch)
tree3a145034f96f102ad90be1c229e3cad67d98f99a /sensor/thermostat.ino
parentuse standard BLE library (diff)
downloadthermostat-14c2fd256653b6f7c657c93303183090cf211922.tar.gz
thermostat-14c2fd256653b6f7c657c93303183090cf211922.tar.bz2
thermostat-14c2fd256653b6f7c657c93303183090cf211922.zip
factor out sleep times
Diffstat (limited to 'sensor/thermostat.ino')
-rw-r--r--sensor/thermostat.ino24
1 files changed, 11 insertions, 13 deletions
diff --git a/sensor/thermostat.ino b/sensor/thermostat.ino
index d90404b..243c80b 100644
--- a/sensor/thermostat.ino
+++ b/sensor/thermostat.ino
@@ -9,7 +9,8 @@ static BLEUUID thermo_service_uuid("11111111-2222-3333-4444-000000000000");
static BLEUUID thermo_temp_uuid("11111111-2222-3333-4444-000000000001");
static BLEUUID thermo_time_uuid("11111111-2222-3333-4444-000000000002");
-#define DEFAULT_SLEEP_TIME 60
+#define NO_SERVER_SLEEP_TIME 60
+#define ON_ERROR_SLEEP_TIME 30
/* Conversion factor for micro seconds to seconds */
#define uS_TO_S_FACTOR 1000000
@@ -74,7 +75,7 @@ uint32_t send_data_and_get_time(BLEAddress* pAddress,String* data) {
bool ok = pClient->connect(*pAddress);
if (!ok) {
show("connect fail");
- return 10;
+ return ON_ERROR_SLEEP_TIME;
}
String status = "SC";
status += pClient->getPeerAddress().toString().c_str();
@@ -107,7 +108,7 @@ uint32_t send_data_and_get_time(BLEAddress* pAddress,String* data) {
catch (...) {
show("Fail");
pClient->disconnect();
- return 10;
+ return ON_ERROR_SLEEP_TIME;
}
}
@@ -127,13 +128,13 @@ void loop() {
pBLEScan->setActiveScan(true);
show("s");
BLEScanResults foundDevices = pBLEScan->start(30);
+ int next_time;
if (cb->pServerAddress) {
show("S");
float humidity, temperature;
bool ok = read_sensor(&humidity,&temperature);
- int next_time;
if (ok) {
String data = String(BLEDevice::getAddress().toString().c_str()) + " " + String(humidity) + " " + String(temperature) + "\n";
show(data);
@@ -142,21 +143,18 @@ void loop() {
}
else {
show("no thermo");
- next_time=10;
+ next_time=ON_ERROR_SLEEP_TIME;
}
- String nt = "Next time:";nt+=next_time;
- display.drawString(0,20,nt);display.display();
- delay(2000);
- esp_sleep_enable_timer_wakeup(next_time * uS_TO_S_FACTOR);
}
else {
display.drawString(0,0,"s!");display.display();
- String nt = "Next time:";nt+=DEFAULT_SLEEP_TIME;
- display.drawString(0,20,nt);display.display();
- delay(2000);
- esp_sleep_enable_timer_wakeup(DEFAULT_SLEEP_TIME * uS_TO_S_FACTOR);
+ next_time = NO_SERVER_SLEEP_TIME;
}
+ String nt = "Next time:";nt+=next_time;
+ display.drawString(0,20,nt);display.display();
+ delay(2000);
+ esp_sleep_enable_timer_wakeup(next_time * uS_TO_S_FACTOR);
esp_deep_sleep_start();
/* display.clear(); */