diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-19 12:55:08 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-19 12:55:08 +0200 |
commit | bfcc6e18af33d21ae3ae23def873fa6415045bec (patch) | |
tree | da9f5602419f5c702d75872ca26eaa68486dd37a | |
parent | a2da7df0347bf4e420c2cd42ff3b8ef7cbd818be (diff) | |
download | ble-toys-bfcc6e18af33d21ae3ae23def873fa6415045bec.tar.gz ble-toys-bfcc6e18af33d21ae3ae23def873fa6415045bec.tar.bz2 ble-toys-bfcc6e18af33d21ae3ae23def873fa6415045bec.tar.xz ble-toys-bfcc6e18af33d21ae3ae23def873fa6415045bec.zip |
o Changing the output format to include the indexes in the values, enabling reading from multiple sensors in one go:
This:
Sample #1: device=.., sensor=1, value=123
Sample #2: device=.., sensor=2, value=321
is hanged to:
Sample: device=.., sensor1=123, sensor2=321
-rw-r--r-- | apps/sm-get-value.h | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/apps/sm-get-value.h b/apps/sm-get-value.h index 0535f68..c98d1d4 100644 --- a/apps/sm-get-value.h +++ b/apps/sm-get-value.h @@ -6,6 +6,7 @@ #include "ble/Bluetooth.h" #include "SoilMoisture.h" #include "trygvis/sensor.h" +#include "trygvis/sensor/io.h" #include "apps.h" namespace trygvis { @@ -36,10 +37,7 @@ public: KeyDictionary dict; SampleKey* hostname_key = dict.indexOf("hostname"); SampleKey* device_key = dict.indexOf("device"); - SampleKey* sensor_key = dict.indexOf("sensor"); - SampleKey* sensor_name_key = dict.indexOf("sensor_name"); - SampleKey* timestamp_key = dict.indexOf("timestamp"); - SampleKey* value_key = dict.indexOf("value"); + SampleKey* timestamp_key = dict.indexOf("timestamp_ms"); void add_options(po::options_description_easy_init &options) override { auto default_sleep = po::value<>(&sleepTime)->default_value(0); @@ -67,9 +65,9 @@ public: return EXIT_FAILURE; } - auto MAC = vm["device"].as<string>(); + auto mac_string = vm["device"].as<string>(); - Mac mac = Mac::parseMac(MAC); + Mac mac = Mac::parseMac(mac_string); auto adapter = getAdapter(0); @@ -112,21 +110,26 @@ public: dict, format); shared_ptr<SampleOutputStream> output_stream{std::move(unique_output_stream)}; + int i = 0; for (auto s : sensors) { auto sensor = s.first; auto name = s.second; uint16_t value = soilMoisture.getValue((uint8_t) sensor); + auto sensor_key = dict.indexOf("sensor" + std::to_string(i)); + auto sensor_name_key = dict.indexOf("sensor_name" + std::to_string(i)); + auto sample = SampleRecord(dict) .set(hostname_key, get_hostname()) .set(device_key, mac) - .set(sensor_key, std::to_string(sensor)) - .set(sensor_name_key, name) .set(timestamp_key, std::to_string(timestamp)) - .set(value_key, std::to_string(value)); + .set(sensor_key, std::to_string(value)) + .set(sensor_name_key, name); output_stream->write(sample); + + i++; } } |