From bfcc6e18af33d21ae3ae23def873fa6415045bec Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 19 Jul 2015 12:55:08 +0200 Subject: 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 --- apps/sm-get-value.h | 21 ++++++++++++--------- 1 file 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(); + auto mac_string = vm["device"].as(); - Mac mac = Mac::parseMac(MAC); + Mac mac = Mac::parseMac(mac_string); auto adapter = getAdapter(0); @@ -112,21 +110,26 @@ public: dict, format); shared_ptr 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++; } } -- cgit v1.2.3