Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
cf1171fc
Commit
cf1171fc
authored
Jan 27, 2017
by
Michael Ott
Browse files
Allow for more than one sensor reading in MQTT payload
parent
2591d585
Changes
1
Hide whitespace changes
Inline
Side-by-side
CollectAgent/collectagent.cpp
View file @
cf1171fc
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment