From Simulink to Grafana using MQTT Protocol
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi,
I’m currently using Grafana to visualize data from my Simulink model in MATLAB 2021b. So far, I’ve been able to collect the data at the end of the simulation by saving it as a .mat file with the ToFile block in Simulink. Then, I use a script to convert the data into a .csv file for Grafana to read.
However, I want to transition to a real-time model where I can send the data (possibly using the MQTT protocol) while the simulation is running, and visualize it live in Grafana. Ideally, I would like to stay with MATLAB 2021b for this task.
How can I achieve this?
댓글 수: 0
답변 (1개)
Aravind
2025년 3월 5일
In MATLAB R2021b, there is no built-in support for creating an MQTT client to facilitate data communication from Simulink to Grafana. However, you can utilize REST APIs to transfer data from MATLAB to Grafana. You can achieve this by using MATLAB's "webwrite" function to send HTTP POST requests to Grafana's REST API, which allows you to dynamically publish data points as your Simulink simulation runs. For more details on the "webwrite" function, visit: https://www.mathworks.com/help/releases/R2021b/matlab/ref/webwrite.html. To incorporate the MATLAB function into your Simulink model, use a "MATLAB Function" block. This block enables the execution of MATLAB functions and code within a Simulink model. More information about this block is available at: https://www.mathworks.com/help/releases/R2021b/simulink/slref/matlabfunction.html.
Alternatively, if you can upgrade to R2022a, you can take advantage of the MQTT Client introduced in that version. This feature allows you to publish data directly from Simulink to an MQTT broker. More information is available in the documentation: https://www.mathworks.com/help/releases/R2022a/icomm/mqtt.html. You can use "MATLAB Function" blocks to incorporate these codes into your Simulink model for real-time data transmission to Grafana.
I hope this addresses your question.
참고 항목
카테고리
Help Center 및 File Exchange에서 Development Computer Setup에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!