diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-26 18:33:15 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-26 18:41:40 +0200 |
commit | d720fa36ad4768ed1b948a92ba5287c30093fbec (patch) | |
tree | 3d566e0d4ab47981af85a783f81ebbd363d57f15 /apps/sm-get-value.cpp | |
parent | 33c537c84fea53c899fb5275256518598f66101e (diff) | |
download | ble-toys-d720fa36ad4768ed1b948a92ba5287c30093fbec.tar.gz ble-toys-d720fa36ad4768ed1b948a92ba5287c30093fbec.tar.bz2 ble-toys-d720fa36ad4768ed1b948a92ba5287c30093fbec.tar.xz ble-toys-d720fa36ad4768ed1b948a92ba5287c30093fbec.zip |
o Overhaul of the bluetooth code.
- Adding support for reading FLOAT (specified in IEEE 11073-20601) values from a bluetooth device.
- More shared pointers to help keep track of the object's lifecycle. Makes sure that the connections are released back to Linux, Linux is way to sensitive with crashing applications.
o Adding support for reading the temperature sensors from the SoilMoisture device.
Diffstat (limited to 'apps/sm-get-value.cpp')
-rw-r--r-- | apps/sm-get-value.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/apps/sm-get-value.cpp b/apps/sm-get-value.cpp index 92ef5f9..5d66320 100644 --- a/apps/sm-get-value.cpp +++ b/apps/sm-get-value.cpp @@ -50,7 +50,7 @@ public: } int main(app_execution &execution) override { - __attribute__((unused)) BluetoothSystem bluetoothSystem; + BluetoothSystem bluetoothSystem; auto desc = execution.desc; auto vm = execution.vm; @@ -66,18 +66,20 @@ public: Mac mac = Mac::parseMac(mac_string); - auto adapter = getAdapter(0); + auto adapter = bluetoothSystem.getAdapter("0"); - auto &device = adapter->getDevice(mac); + auto device = adapter->getDevice(mac); loop = sleepTime > 0; do { try { - LOG4CPLUS_INFO(execution.logger, "Connecting to device: " << device.getMac().str()); - auto gatt = device.connectGatt(); + LOG4CPLUS_INFO(execution.logger, "Connecting to device: " << device->getMac().str()); + auto gatt = device->connectGatt(); withConnection(format, gatt); + } catch (BluetoothException &e) { + LOG4CPLUS_ERROR(execution.logger, "Bluetooth error: " << e.what()); } catch (runtime_error &e) { LOG4CPLUS_ERROR(execution.logger, "Exception: " << e.what()); } @@ -112,6 +114,11 @@ public: .set(device_key, mac) .set(timestamp_key, std::to_string(timestamp)); + auto tempO = soilMoisture.readTemperature(); + if (tempO) { + sample.set(dict.indexOf("temperature"), std::to_string(tempO.get())); + } + int i = 0; for (auto s : sensors) { auto sensor = s.first; @@ -122,7 +129,9 @@ public: auto sensor_key = dict.indexOf("sensor" + std::to_string(i)); auto sensor_name_key = dict.indexOf("sensor_name" + std::to_string(i)); - sample.set(sensor_key, std::to_string(value)).set(sensor_name_key, name); + sample + .set(sensor_key, std::to_string(value)) + .set(sensor_name_key, name); i++; } |