Get Time in callback function while subscribing to MQTT Topic
Afficher commentaires plus anciens
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 commentaires
Geoff Hayes
le 5 Juil 2022
@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
le 5 Juil 2022
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur MQTT Protocol Communication dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!