How to receive an full binary data using mqtt callback function

7 ビュー (過去 30 日間)
Gavrila Pi
Gavrila Pi 2024 年 8 月 3 日
コメント済み: dpb 2024 年 8 月 5 日
I have sent a binary blob (for example 4k) from C++ app by mqtt mosquitto. In matlab only a chunk of sending data is received. This chunk is limited by the first zero byte which is in the blob. How to receive a full message?
Short code snippest below:
mqttClient = mqttclient("tcp://127.0.0.1");
mySub = subscribe(mqttClient, "topic", Callback=@MsgCallvBack)
%
function MsgCallvBack(topic, data)
fprintf("topic=%s, data size=%u\n", topic, length(data));
end
Result for 4 sending attempts of random 4k blob:
>topic=testtopic, data size=40
>topic=testtopic, data size=22
>topic=testtopic, data size=3
>topic=testtopic, data size=241
  3 件のコメント
Gavrila Pi
Gavrila Pi 2024 年 8 月 5 日
> I don't know of another workaround other than by using another protocol instead that does support binary data in MATLAB or try to link to Python or find C opensource and create a mex file of your own.
MATLAB cannot be proud of a large number of interaction protocols. Writing your own MEX will require significant time investment.
Thank you for your help.
dpb
dpb 2024 年 8 月 5 日
They (new protocols) seem to spring up like weeds; trying to support them all is a Herculean task it would seem and requires resources that must divert away from core development...

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

回答 (1 件)

dpb
dpb 2024 年 8 月 3 日
編集済み: dpb 2024 年 8 月 3 日
mqttclient and subsequent subscribe shows the callback function is to read the subscribed-to channel and the input function is an overloaded read method. Never heard of it before so no experience, but it appears it is a text-based messaging system so null bytes will be interpreted as character terminators unless treated specifically as text (like embedding as char(0) and the like for construction), but are highly likely to be considered terminators on reading internally.
From a quick look, it wouldn't seem to be a suitable transmission choice for arbitrary binary data...
  7 件のコメント
Gavrila Pi
Gavrila Pi 2024 年 8 月 4 日
Do you have a plan to open a bug request?
dpb
dpb 2024 年 8 月 4 日
Personally, no, since I have no background in the protocol. See <product support link> for how to get in touch...

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

カテゴリ

Help Center および File ExchangeThird-Party Cluster Configuration についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by