MQTT subscribe callback function not executed in AppDesigner
조회 수: 2 (최근 30일)
이전 댓글 표시
I am developing a graphic user interface on AppDesigner with the purpose of displaying the result of a classification algorithm using data coming via MQTT protocol. The “subscribe” function (related to the “mqtt” function) requires the use of a callback to perform tasks whenever data are received. This procedure works fine when applied outside AppDesigner, while within AppDesigner it seems like the callback function is never executed. An attempt to address this issue was using global variable (see code below) but it did not work.
function StartButtonPushed(app, event)
% Connection to MQTT
mqttAddress = 'tcp://10………';
mObj = mqtt(mqttAddress,'Port',1883);
mySub = subscribe(mObj,'sensors','callback',@appCallback);
function appCallback(~,~)
app.GoodLamp.Color = 'Green';
end
end
How can this issue be addressed?
댓글 수: 0
채택된 답변
Sean de Wolski
2019년 2월 21일
(This is a guess)
When the function exits, the mObj and mySub are destroyed. Set them to be properties of the app (add properties and then app.mObj = ...) so that they exist after the function call completes.
댓글 수: 2
Faraz Azmi
2020년 5월 15일
Hello Mr. Sean,
you seem to know how mqtt works on matlab properly. I have a problem where it shows that there are no messages waiting to be read in the topic but i do have data published under it.
link to my question which contains the screenshots and dont have any answers yet
https://in.mathworks.com/matlabcentral/answers/524900-read-function-in-mqtt-says-there-are-no-messages-waiting-to-be-read
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Help and Support에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!