MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

MQTT subscribe callback function not executed in AppDesigner

Alberto Franzini さんによって質問されました 2019 年 2 月 21 日
最新アクティビティ Alberto Franzini さんによって コメントされました 2019 年 2 月 21 日
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 件のコメント

サインイン to comment.

1 件の回答

回答者: 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.

  1 件のコメント

Thank you very much, it works!

サインイン to comment.



Translated by