Get Time in callback function while subscribing to MQTT Topic
Mostrar comentarios más antiguos
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 comentarios
Geoff Hayes
el 5 de Jul. de 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
el 5 de Jul. de 2022
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MQTT Protocol Communication en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!