Connect Modbus TCP devices through an IoT Edge device gateway
Applies to: IoT Edge 1.4
If you want to connect IoT devices that use Modbus TCP or RTU protocols to an Azure IoT hub, you can use an IoT Edge device as a gateway. The gateway device reads data from your Modbus devices, then communicates that data to the cloud using a supported protocol.
This article covers how to create your own container image for a Modbus module (or you can use a prebuilt sample) and then deploy it to the IoT Edge device that will act as your gateway.
This article assumes that you're using Modbus TCP protocol. For more information about how to configure the module to support Modbus RTU, see the Azure IoT Edge Modbus module project on GitHub.
- An Azure IoT Edge device. For a walkthrough on how to set up one, see Deploy Azure IoT Edge on Windows or Linux.
- The primary key connection string for the IoT Edge device.
- A physical or simulated Modbus device that supports Modbus TCP. You will need to know its IPv4 address.
Prepare a Modbus container
If you want to test the Modbus gateway functionality, Microsoft has a sample module that you can use. You can access the module from the Azure Marketplace, Modbus, or with the image URI,
If you want to create your own module and customize it for your environment, there is an open-source Azure IoT Edge Modbus module project on GitHub. Follow the guidance in that project to create your own container image. To create a container image, refer to Develop C# modules in Visual Studio or Develop Azure IoT Edge modules using Visual Studio Code. Those articles provide instructions on creating new modules and publishing container images to a registry.
Try the solution
This section walks through deploying Microsoft's sample Modbus module to your IoT Edge device.
On the Azure portal, go to your IoT hub.
Go to Devices and select your IoT Edge device.
Select Set modules.
In the IoT Edge Modules section, add the Modbus module:
- Click the Add dropdown and select Marketplace Module.
- Search for
Modbusand select the Modbus TCP Module by Microsoft.
- The module is automatically configured for your IoT Hub and appears in the list of IoT Edge Modules. The Routes are also automatically configured. Select Review + create.
- Review the deployment manifest and select Create.
Select the Modbus module,
ModbusTCPModule, in the list and select the Module Twin Settings tab. The required JSON for the module twin desired properties is auto populated.
Look for the SlaveConnection property in the JSON and set its value to the IPv4 address of your Modbus device.
Select Review + create, review the deployment, and then select Create.
Return to the device details page and select Refresh. You should see the new
ModbusTCPModulemodule running along with the IoT Edge runtime.
View the data coming through the Modbus module:
iotedge logs modbus
You can also view the telemetry the device is sending by using the Azure IoT Hub extension for Visual Studio Code (formerly Azure IoT Toolkit extension).
- To learn more about how IoT Edge devices can act as gateways, see Create an IoT Edge device that acts as a transparent gateway.
- For more information about how IoT Edge modules work, see Understand Azure IoT Edge modules.