How do I receive the message when I subscribe to a topic using "MQTT in Matlab"?

4 ビュー (過去 30 日間)
Sven Fießer
Sven Fießer 2018 年 6 月 2 日
回答済み: Shubham 2023 年 8 月 28 日
Hello!
Right now I am using the toolbox "MQTT for Matlab". Pubishing messages works fine. But when I'm subscribing to any topic I can't get the content of the message. The "MessageCount" goes up for every message I'm publishing to that topic but Matlab isn't showing me any content at all for my subscription.
The code I used: myMQTT = mqtt('tcp://broker.hivemq.com'); mySub = subscribe(myMQTT,'testtopic')
Sven
  3 件のコメント
eman karim
eman karim 2019 年 7 月 20 日
Hello, I have the same problem .. Have you reached a solution?
Eman
Faraz Azmi
Faraz Azmi 2020 年 5 月 15 日
編集済み: Faraz Azmi 2020 年 5 月 15 日
when i do message = read(mySub) , it says there are no messages waiting to be read. the message count stays 0 everytime but i do have data being published under the topic. what can i do about solving this. i asked this question in MATLAB answers but no answers yet, can u please help.
link to my question which contains screenshots
https://in.mathworks.com/matlabcentral/answers/524900-read-function-in-mqtt-says-there-are-no-messages-waiting-to-be-read

サインインしてコメントする。

回答 (1 件)

Shubham
Shubham 2023 年 8 月 28 日
Hi Sven,
In MATLAB, you can use the read() function to retrieve messages from different MQTT subscriptions. Additionally, when subscribing to a topic, you can assign a callback function that will be triggered whenever a message is received. This allows you to obtain real-time messages from multiple topics and perform actions on them.
Read here to know more about declaring and assigning callback functions while subscribing to a topic.

カテゴリ

Help Center および File ExchangeHelp and Support についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by