Commit cf1171fc authored by Michael Ott's avatar Michael Ott
Browse files

Allow for more than one sensor reading in MQTT payload

parent 2591d585
......@@ -126,30 +126,21 @@ void mqttCallback(SimpleMQTTMessage *msg)
* Decode the message and put into the database.
*/
if (msg->isPublish()) {
mqttPayload buf, *payload;
uint64_t len;
uint64_t val;
uint64_t ts;
len = msg->getPayloadLength();
//In the 64 bit message case, the collect agent provides a timestamp
if(msg->getPayloadLength()==sizeof(uint64_t)) {
//printf("Providing timestamp...\n");
val = *((uint64_t*)msg->getPayload());
ts = Messaging::calculateTimestamp();
//printf("Val = %" PRIu64 ", timestamp = %" PRIu64 "\n", val, ts);
if (len == sizeof(uint64_t)) {
payload = &buf;
payload->value = *((uint64_t*)msg->getPayload());
payload->timestamp = Messaging::calculateTimestamp();
len = 2;
}
//...otherwise it just retrieves it from the MQTT message payload.
else if((msg->getPayloadLength()%sizeof(mqttPayload)==0) && (msg->getPayloadLength()>0)){
//printf("Retrieving timestamp...\n");
mqttPayload *payload = (mqttPayload*)msg->getPayload();
val = payload->value; // payload[n].value
ts = payload->timestamp;
//printf("Val = %" PRIu64 ", timestamp = %" PRIu64 "\n", val, ts);
else if((len%sizeof(mqttPayload)==0) && (len>0)){
payload = (mqttPayload*)msg->getPayload();
}
//...otherwise this message is malformed -> ignore...
else {
delete msg;
......@@ -178,8 +169,10 @@ void mqttCallback(SimpleMQTTMessage *msg)
<< "\nsensor_number: " << hex << sid.dsid.sensor_number
<< "\n";
#endif
mySensorDataStore->insert(&sid, ts, val);
mySensorCache.storeSensor(sid, ts, val);
for (uint64_t i=0; i<len/sizeof(mqttPayload); i++) {
mySensorDataStore->insert(&sid, payload[i].timestamp, payload[i].value);
mySensorCache.storeSensor(sid, payload[i].timestamp, payload[i].value);
}
//mySensorCache.dump();
}
#if 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment