aboutsummaryrefslogtreecommitdiff
path: root/sm-mqtt-consumer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sm-mqtt-consumer.cpp')
-rw-r--r--sm-mqtt-consumer.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/sm-mqtt-consumer.cpp b/sm-mqtt-consumer.cpp
index e905d02..5a0a23e 100644
--- a/sm-mqtt-consumer.cpp
+++ b/sm-mqtt-consumer.cpp
@@ -6,8 +6,6 @@
namespace sm_mqtt_consumer {
-using namespace std;
-using namespace std::chrono;
using namespace trygvis::sensor;
using namespace trygvis::sensor::io;
using namespace trygvis::cassandra_support;
@@ -40,10 +38,10 @@ struct sensor_measurement {
struct device_measurement {
string device;
- long timestamp;
+ timestamp_t timestamp;
vector<sensor_measurement> sensors;
- device_measurement(string &device, long timestamp, vector<sensor_measurement> &&sensors) :
+ device_measurement(string &device, timestamp_t timestamp, vector<sensor_measurement> &&sensors) :
device(device), timestamp(timestamp), sensors(std::move(sensors)) {
};
@@ -52,7 +50,7 @@ struct device_measurement {
string str() {
stringstream buf;
buf << "device=" << device;
- buf << ", timestamp=" << timestamp;
+ buf << ", timestamp=" << timestamp.time_since_epoch().count();
std::for_each(sensors.begin(), sensors.end(), [&](auto &sensor) {
buf << ", #" << sensor.sensor << "=" << sensor.value;
});
@@ -141,12 +139,12 @@ cassandra_future2* insert_into_sm_by_day(cassandra_session *session, device_meas
stmt.bind(0, measurement.device);
- std::time_t t = measurement.timestamp;
+ std::time_t t = system_clock::to_time_t(measurement.timestamp);
char day[100];
std::strftime(day, sizeof(day), "%Y-%m-%d", std::localtime(&t));
stmt.bind(1, day);
- stmt.bind(2, measurement.timestamp * 1000);
+ stmt.bind(2, measurement.timestamp.time_since_epoch().count());
cassandra_collection sensors(CASS_COLLECTION_TYPE_LIST, measurement.sensors.size());
for_each(measurement.sensors.cbegin(), measurement.sensors.cend(), [&](auto sensor) {
@@ -223,7 +221,8 @@ void on_message(const struct mosquitto_message *message) {
return;
}
- device_measurement measurement(device, timestamp.get(), std::move(sensors));
+ timestamp_t ts(milliseconds(timestamp.get()));
+ device_measurement measurement(device, ts, std::move(sensors));
cout << "Measurement: " << measurement.str() << endl;
@@ -277,6 +276,7 @@ int main(int argc, const char **argv) {
} catch (po::required_option &e) {
cerr << "Missing required option: " << e.get_option_name() << endl;
cerr << all << endl;
+ return EXIT_FAILURE;
} catch (po::unknown_option &e) {
cerr << e.what() << endl;
return EXIT_FAILURE;