Run backgroundPool to stream MQTT
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Ashutosh Thakur
on 21 Dec 2023
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.
See Also
Categories
Find more on Background Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!