필터 지우기
필터 지우기

To receive data in the MATLAB using MQTT protocol

조회 수: 13 (최근 30일)
SeongYong Park
SeongYong Park 2023년 3월 16일
답변: Vinayak Gupta 2023년 4월 3일
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?

답변 (1개)

Vinayak Gupta
Vinayak Gupta 2023년 4월 3일
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.

카테고리

Help CenterFile Exchange에서 MQTT Protocol Communication에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by