aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/sm-get-value.h21
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++;
}
}