Run backgroundPool to stream MQTT
2 ビュー (過去 30 日間)
古いコメントを表示
Hello
Does anyone know is there is an evironment for running a background pool with an internet connection to do some streaming using MQTT?
From what i gather i cannot simply use parfeval, since this does not have any network connection since it runs inside the MATLAB environment.
Basically i just want to stream to an MQTT topic like shown below, with two variables y and q, and then return 1 argument every 1 sec.
parfeval(backgroundPool,@MqttStreaming,1,broker,port,topic,y,q) ;
function mqttClientStream = MqttStreaming(broker,port,topic,y,q)
mqttClientStream = mqttclient(broker,Port=port) ;
for i = 1:size(y,1)
string = [y(i,:),q(i)] ;
write(mqttClientStream,topic,string) ;
pause(1.0)
end
end
0 件のコメント
回答 (1 件)
Ashutosh Thakur
2023 年 12 月 21 日
Hi Mathias,
Based on your query I can understand that you want to stream a MQTT topic with two variables and return 1 argument every 1 second. The functions like "parfeval" cannot be used as they do not have direct access to the network resources.
The MATLAB functions such as "timer" could be used to perform above tasks. The "timer" functions executes a specified function called "TimerFcn" over a certain period of time.
Also based on your complete requirements you can use a single timer as well as multiple timers.
Also make sure that you are stopping or deleting the "timer" after the execution of desired "TimerFcn" has finished or not as if the timers are not stopped after execution it will affect the performance or utilize all remaining resources.
Please take reference from the following documenation link regarding timers:
I hope this helps.
参考
カテゴリ
Help Center および File Exchange で Background Processing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!