diff options
author | dakkar <dakkar@thenautilus.net> | 2018-04-20 14:52:14 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2018-04-20 14:52:14 +0100 |
commit | fbddd8967dd34f093dc3d7d7537d8869daefb2ad (patch) | |
tree | dded6350b39bec1e983d01e3e7fc75990722aba3 /sensor/thermostat.ino | |
parent | don't stall if dht times out (diff) | |
download | thermostat-fbddd8967dd34f093dc3d7d7537d8869daefb2ad.tar.gz thermostat-fbddd8967dd34f093dc3d7d7537d8869daefb2ad.tar.bz2 thermostat-fbddd8967dd34f093dc3d7d7537d8869daefb2ad.zip |
handle exceptions from BLE
Diffstat (limited to 'sensor/thermostat.ino')
-rw-r--r-- | sensor/thermostat.ino | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/sensor/thermostat.ino b/sensor/thermostat.ino index 0b90053..e6090ac 100644 --- a/sensor/thermostat.ino +++ b/sensor/thermostat.ino @@ -82,29 +82,36 @@ uint32_t send_data_and_get_time(BLEAddress* pAddress,String* data) { String status = "SC"; status += pClient->getPeerAddress().toString().c_str(); show(status); - BLERemoteService* pThermoService = pClient->getService(thermo_service_uuid); - if (!pThermoService) { - show("NO SERVICE"); - return 60; - } - BLERemoteCharacteristic* pTemp = pThermoService->getCharacteristic(thermo_temp_uuid); - if (!pTemp) { - show("NO TEMP CHAR"); - return 60; + try { + BLERemoteService* pThermoService = pClient->getService(thermo_service_uuid); + if (!pThermoService) { + show("NO SERVICE"); + return 60; + } + BLERemoteCharacteristic* pTemp = pThermoService->getCharacteristic(thermo_temp_uuid); + if (!pTemp) { + show("NO TEMP CHAR"); + return 60; + } + show("SCw"); + pTemp->writeValue(data->c_str(),data->length()); + show("SCWr"); + BLERemoteCharacteristic* pTime = pThermoService->getCharacteristic(thermo_time_uuid); + if (!pTime) { + show("NO TIME CHAR"); + return 60; + } + std::string next_time = pTime->readValue(); + show("SCWRd"); + pClient->disconnect(); + show("SCWRD"); + return String(next_time.c_str()).toInt(); } - show("SCw"); - pTemp->writeValue(data->c_str(),data->length()); - show("SCWr"); - BLERemoteCharacteristic* pTime = pThermoService->getCharacteristic(thermo_time_uuid); - if (!pTime) { - show("NO TIME CHAR"); - return 60; + catch (...) { + show("Fail"); + pClient->disconnect(); + return 10; } - std::string next_time = pTime->readValue(); - show("SCWRd"); - pClient->disconnect(); - show("SCWRD"); - return String(next_time.c_str()).toInt(); } void setup() { |