필터 지우기
필터 지우기

Run backgroundPool to stream MQTT

조회 수: 3 (최근 30일)
Mathias Lund
Mathias Lund 2023년 10월 31일
댓글: Mathias Lund 2023년 12월 21일
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

답변 (1개)

Ashutosh Thakur
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.
  댓글 수: 1
Mathias Lund
Mathias Lund 2023년 12월 21일
But will it run as a background task?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by