Get Time in callback function while subscribing to MQTT Topic
显示 更早的评论
Hello,
I use the Industrial Communication Toolbox to subscribe to an MQTT Topic. To receive the data, I subscribe to to an MQTT Topic with a Callback Function. The callback function looks like that: function showmessage(topic, data) and therefore has as Input just topic and data. data looks in my example like that:
I need the timestamp from data which here just includes seconds, no milliseconds. But when I use the read(...) function to read from my mqttClient, I get a timetable which includes Time and also milliseconds (not shown on screenshot but could be observed on plots), Topic, but also Data.

Now my question comes up: is it possible to receive the Time like shown in the above screenshot also in the callback function? I tried to have time as third input to my callback function but I get an error when I execute line 32. As other option I tried to use read(...) in my callback function (like line 31), but this also doesn't work. I know both together could not work, it's just in the screenshot to keep my question as short as possible.

Thanks in advance for your help!
2 个评论
Geoff Hayes
2022-7-5
@Stephan Zimmermann - is the issue that you don't have milliseconds in your time response? Or that you just can't extract the ts from the data json (or something like a json format)?
Stephan Zimmermann
2022-7-5
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 MQTT Protocol Communication 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!