From f085ec61273a5fa680c337d0ae7d5a85294aaeba Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 20 Jul 2015 22:31:33 +0200 Subject: o Sending only a single sample after all values have been read. --- apps/sm-get-value.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/sm-get-value.cpp b/apps/sm-get-value.cpp index 19b0066..92ef5f9 100644 --- a/apps/sm-get-value.cpp +++ b/apps/sm-get-value.cpp @@ -74,7 +74,7 @@ public: do { try { - LOG4CPLUS_INFO(execution.logger, "Connecting to device: " + device.getMac().str()); + LOG4CPLUS_INFO(execution.logger, "Connecting to device: " << device.getMac().str()); auto gatt = device.connectGatt(); withConnection(format, gatt); @@ -83,8 +83,8 @@ public: } if (loop) { - LOG4CPLUS_DEBUG(execution.logger, - "Sleeping for " + std::to_string(sleepTime) + " seconds after failure."); + LOG4CPLUS_DEBUG(execution.logger, "Sleeping for " << std::to_string(sleepTime) + << " seconds after failure."); auto targetTime = system_clock::now() + seconds(sleepTime); this_thread::sleep_until(targetTime); @@ -107,6 +107,11 @@ public: auto unique_output_stream = open_sample_output_stream(shared_ptr(&cout, noop_deleter), dict, format); shared_ptr output_stream{std::move(unique_output_stream)}; + auto sample = SampleRecord(dict) + .set(hostname_key, get_hostname()) + .set(device_key, mac) + .set(timestamp_key, std::to_string(timestamp)); + int i = 0; for (auto s : sensors) { auto sensor = s.first; @@ -117,17 +122,12 @@ public: 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(timestamp_key, std::to_string(timestamp)) - .set(sensor_key, std::to_string(value)) - .set(sensor_name_key, name); - - output_stream->write(sample); + sample.set(sensor_key, std::to_string(value)).set(sensor_name_key, name); i++; } + + output_stream->write(sample); } void withConnection(sample_format_type format, shared_ptr gatt) { -- cgit v1.2.3