aboutsummaryrefslogtreecommitdiff
path: root/apps/sm-get-value.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'apps/sm-get-value.cpp')
-rw-r--r--apps/sm-get-value.cpp21
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++;
}