Connecting PLC Modbus Data to Your ioCtrlMQ Dashboard

May 24, 2024

Bridging the Gap: From the Factory Floor to Your Dashboard

Industrial environments are filled with robust and reliable equipment like Programmable Logic Controllers (PLCs). These devices are the workhorses of automation, controlling everything from simple motors to complex manufacturing lines. Many of these PLCs communicate using the Modbus protocol—a simple, effective, and widely adopted standard.

However, Modbus was designed for local, serial networks. To bring this valuable data into a modern, cloud-based platform like ioCtrlMQ for real-time visualization and analysis, we need a bridge. This is where an MQTT gateway comes in.

Diagram showing a PLC connecting through a Modbus to MQTT Gateway, to a Broker, and finally to the ioCtrlMQ Dashboard.

What is a Modbus to MQTT Gateway?

A gateway is a device or software application that acts as a translator between two different protocols. A Modbus to MQTT gateway polls Modbus-enabled devices on a local network, reads the register data, and then publishes that data as MQTT messages to a specified broker. This allows you to seamlessly integrate legacy industrial hardware with modern IoT platforms.

Step-by-Step Guide to Connecting Your PLC

Here’s a conceptual guide to getting your PLC data onto your ioCtrlMQ dashboard. The exact hardware and software will vary, but the principles remain the same.

1. Choose Your Gateway

You have several options for a gateway:

  • Hardware Gateway: Devices from manufacturers like Advantech, Moxa, or USR-IOT are purpose-built for this task. They offer a rugged solution with a simple web-based configuration interface.
  • Software Gateway: You can run gateway software on a local computer or an embedded device like a Raspberry Pi. Popular options include Node-RED (with Modbus and MQTT nodes), or custom Python scripts using libraries like pymodbus and paho-mqtt.

2. Configure the Gateway to Read Modbus Data

In your gateway's configuration, you'll need to specify:

  • PLC IP Address & Port: The local IP address of your PLC and the Modbus TCP port (usually 502).
  • Polling Interval: How often the gateway should request data (e.g., every 5 seconds).
  • Modbus Registers: The specific addresses of the registers you want to read (e.g., holding registers starting at address 40001). You'll also specify the data type (e.g., integer, float).

3. Configure the MQTT Connection

Next, configure the gateway to publish the data to your MQTT broker:

  • Broker URL & Port: The address of your MQTT broker (e.g., test.mosquitto.org).
  • Topic Structure: Define a clear topic structure. A good practice is plc/[machine_id]/[parameter], for example, plc/press-01/pressure.
  • Credentials: Enter any required username, password, or certificates for your broker.

4. Configure Your ioCtrlMQ Widget

Now, on your ioCtrlMQ dashboard:

  1. Add a new widget, such as a Gauge or a Line Chart.
  2. In the widget's configuration sheet, enter the MQTT broker details you used in the gateway.
  3. Set the Topic to match the one you defined in the gateway (e.g., plc/press-01/pressure).
  4. If the data from the PLC is in a raw format, you can use the Data Transformation function to scale it or convert it. For example, if your PLC sends an integer 425 that represents 42.5 PSI, your transformation function would be (payload) => payload / 10.

5. Visualize and Control

Once configured, your widget will subscribe to the topic and start displaying the PLC data in real-time. You can now monitor your industrial processes from anywhere. For control, you can configure a Button or Numeric Input widget in ioCtrlMQ to publish a message back to a different topic, which the gateway can then translate into a Modbus write command to the PLC.

By bridging Modbus and MQTT, you unlock the full potential of your industrial data, enabling smarter, more efficient, and more connected operations.