Filter löschen
Filter löschen

To receive data in the MATLAB using MQTT protocol

13 Ansichten (letzte 30 Tage)
SeongYong Park
SeongYong Park am 16 Mär. 2023
Beantwortet: Vinayak Gupta am 3 Apr. 2023
Hi, I want to utilize MQTT communication in the cloud as MATLAB input data.
The MATLAB version I am currently using is R2022b version, and I wrote the code as below.
However, 'sub_obj' is not accumulating proper data (e.g., data to date, data that is updated in real time).
Real data is updated every 3 seconds.
Is there a code line that I forgot to get real-time data?
If there is, please give me feedback.
Additionally, should the data I receive as a subscription be in the form of column 2?

Antworten (1)

Vinayak Gupta
Vinayak Gupta am 3 Apr. 2023
Hi
Your code seems to be accurate until the while loop starts. I am not sure if read function works in the way you used it.
In the documentation(Read available messages from MQTT topic), we can see there are two ways to use read, one is reading all available messages on the broker, while the other adds a filter by using a named argument for topic.
msg = read(mqttVlient,Topic=topic1);
The returned object is a table with Time, Topic and Data as the available columns.
The Payload object was available in the older mqtt client, the newer way (post R2022a) does not follow that approach.
Also, you will need to have ‘Industrial communication Toolbox’ installed for the code to work.
To read the data every 3 seconds, you can add a pause within the while loop.
The subscriptions table within the client object does not store the messages.
You can read more about MQTT protocol at MQTT Protocol Communication.

Kategorien

Mehr zu MQTT Protocol Communication finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by