How can I interface MATLAB with Azure Digital Twins (DTDL models) to exchange telemetry and parameters for dynamic simulation and control

23 views (last 30 days)
I am working on a project where I want to use MATLAB/Simulink to simulate the dynamic behavior of a physical process (e.g., a heat exchanger) and run a feedback control loop.
Since DTDL models in Azure Digital Twins (ADT) cannot perform calculations, I want MATLAB to:
  1. Read parameters from the digital twin (e.g., temperature from a transmitter twin, setpoint from an operator twin).
  2. Run the control simulation in MATLAB/Simulink (e.g., PID control to calculate valve position and outlet temperature).
  3. Write telemetry updates back to the Azure Digital Twin in JSON format so the twin always reflects the updated system behavior.
I would like to know:
  • What is the best way to connect MATLAB with Azure ADT?
  • Can I use webread and webwrite in MATLAB to call ADT REST APIs for reading/writing telemetry?
  • Are there any example codes or workflows that show how to structure this interface?
  • How do I authenticate MATLAB with Azure (e.g., using tokens for the ADT REST API)?

Answers (1)

Satyam
Satyam 10 minutes ago
Hi,
You can integrate MATLAB/Simulink with Azure Digital Twins (ADT) for your use case i.e. reading parameters, running control simulations, and writing telemetry updates.
Connection between MATLAB and Azure ADT
  • MATLAB can interact with Azure Digital Twins REST APIs directly using built-in HTTP functions.
  • You can use MATLAB’s webread, webwrite, and weboptions functions to communicate with ADT endpoints for reading and updating twin properties or relationships.
Reading/Writing Telemetry and Parameters
  • You can periodically poll or subscribe to ADT data to update your Simulink model inputs.
  • After simulation, use webwrite to send updated telemetry (e.g., temperatures, valve positions) back to ADT in JSON format.
  • MATLAB provides convenient JSON encoding via jsonencode and decoding via jsondecode.
Authentication with Azure
  • To authenticate MATLAB with Azure ADT, you’ll need to acquire an OAuth 2.0 bearer token using Azure Active Directory (AAD).
  • You can generate tokens programmatically using matlab.net.http.RequestMessage or external tools like the Azure CLI.
While there isn’t a direct example specifically for ADT, similar workflows exist for integrating MATLAB with other RESTful cloud services (e.g., AWS, ThingSpeak, Azure IoT). Here are a few references:
Communicate with Web services from MATLAB: https://www.mathworks.com/help/matlab/web-services.html
RESTful API for MATLAB Function Execution: https://www.mathworks.com/help/mps/restfuljson/restful-api.html

Categories

Find more on ThingSpeak in Help Center and File Exchange

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!