Skip to content

Modbus

Introduction

The Modbus to MQTT Flux Asset Connector is a strategic component of the Coreflux ecosystem, designed to bridge the gap between Modbus master devices and MQTT communication protocols. By facilitating direct connectivity via either Modbus TCP or RTU (Serial) without employing ASCII, this connector enables efficient data exchange and management. It aligns with Coreflux's commitment to real-time data handling and seamless asset integration, making it an essential tool for system integrators, application developers, and IoT device manufacturers aiming to leverage robust, scalable IoT solutions.

Targeted at enhancing the interoperability within IoT ecosystems, the Modbus to MQTT Flux Asset Connector serves the vital function of tagging and routing data from Modbus masters to MQTT brokers. This ensures not only the secure and reliable transmission of information via protocols like Websocket over SSL Port and MQTT over TLS Port but also supports unlimited data traffic. By integrating with Coreflux's comprehensive suite, including the MQTT Broker, Asset Management, and Coreflux HUB, the connector offers a streamlined approach to IoT deployments across various platforms and devices, catering to the needs of a technologically advanced audience seeking efficient and effective IoT implementations.

Features and Benefits

The Modbus to MQTT Flux Asset Connector offers a streamlined solution for bridging traditional industrial protocols with modern IoT messaging systems. Key to this solution is the ability to connect Modbus master devices, whether they operate over TCP/IP or RTU (Serial) protocols, directly to MQTT brokers using a tag-based system, excluding ASCII.

Key Features and Benefits:

  • Dual Protocol Support: The connector seamlessly bridges devices operating on both Modbus TCP and RTU protocols with MQTT networks. This versatility ensures that a wide range of legacy industrial equipment can easily become part of modern IoT applications, enhancing the value of existing assets without extensive modification.

  • Tag-Based Messaging: Utilizing tags for MQTT topics simplifies the configuration and enhances the clarity of data streams. This approach allows for more intuitive mapping of Modbus registers to MQTT messages, making it easier for systems and people to understand and manage the data flow.

  • Streamlined Integration into Coreflux Ecosystem: Designed to fit smoothly within the Coreflux ecosystem, the connector simplifies the integration process. Users can expect a reduction in the complexity and time required to connect and configure devices, speeding up the deployment of IoT solutions.

  • Operational Efficiency: By enabling the direct flow of data from Modbus devices to MQTT brokers, the connector reduces the need for intermediary software or hardware. This not only minimizes latency and potential points of failure but also contributes to a leaner, more cost-effective operational environment.

  • Enhanced Data Exchange: With MQTT's lightweight and efficient messaging protocol, the connector facilitates real-time data exchange between industrial systems and IoT applications. This immediate access to data can drive better decision-making, faster response times, and ultimately, improved system performance.

Use Cases:

  • Real-Time Monitoring and Control: Operators can directly monitor and control Modbus-connected machinery through MQTT-enabled dashboards or control systems. This real-time capability enables rapid adjustments to operations, contributing to higher productivity and reduced downtime.

  • Data Aggregation: By funneling data from various Modbus devices into a unified MQTT stream, the connector makes it easier to aggregate and analyze data across systems. This unified view can uncover operational insights, leading to more informed decision-making.

  • IoT Integration: The connector is a key enabler for integrating industrial systems with broader IoT ecosystems. Whether aiming to leverage cloud analytics, engage in remote monitoring, or implement predictive maintenance, the connector simplifies the path from traditional operations to IoT-enhanced processes.

Prerequisites

To effectively use the Modbus to MQTT Flux Asset Connector, ensure you have the following prerequisites in place:

  • Coreflux Central account: Required for managing and monitoring the operations of the connector.
  • Coreflux MQTT Broker: Highly recommended for seamless compatibility with the asset. It is the MQTT Broker running the asset, though you can opt to use another MQTT broker.
  • MQTT Client: A tool like MQTT Explorer is necessary for testing and visualizing the MQTT messages sent by the connector.
  • Coreflux Hub: Serves as the central point for deploying and managing the connector within the Coreflux ecosystem.
  • Software dependencies related to the Modbus protocol: Since the connector deals with translating Modbus communication to MQTT, ensure all software dependencies pertaining to handling Modbus are met.
  • Hardware requirements: Adequate to support the Coreflux platform and the Modbus devices you intend to connect. This includes a compatible computer or server for running the Coreflux Hub and MQTT Broker, and Modbus-enabled devices to act as data sources.

Asset Installation

To install the Modbus to MQTT flux asset connector or environment setup in the Coreflux architecture, you will follow distinct processes depending on whether you are utilizing the Coreflux Hub UI or directly engaging with the MQTT broker for a more manual installation.

Using Coreflux Hub:

Navigate to the Coreflux Hub application on your Linux or Windows device. Access the documentation on how to get started with your first asset installation at https://docs.coreflux.org/getting-started/first-asset/. This guide provides a detailed walkthrough of the installation process using the Coreflux Hub's user interface. Follow the provided steps to seamlessly install your desired flux asset through the intuitive UI of Coreflux Hub, which connects with the underlying systems including the MQTT Broker and Asset Management components.

Without the Coreflux Hub (Directly via MQTT Broker):

Open your preferred MQTT client and connect it to the Coreflux MQTT Broker. Ensure your connection uses Websocket over SSL Port or MQTT over TLS Port for secure communication. Authenticate with the MQTT Broker by sending a login command with your Coreflux account credentials in the following format: -L myname@mydomain.com password. To view your available assets, send a list command: -l. You should receive a list including the Modbus to MQTT assets, denoted as coreflux_modbus2mqtt X/Y, where X is the number of used assets and Y the total available. To install the Modbus to MQTT asset, send an install command: -I coreflux_modbus2mqtt. Upon successful installation, a confirmation message will be published to $SYS/Coreflux/Command/Output indicating the version and the asset_guid of your newly installed coreflux_modbus2mqtt asset.

Asset Configuration

Here's a detailed table of parameters based on the configurations provided:

Parameter Description Required Example
Port MQTT broker port Yes 1883
Address MQTT broker IP address Yes 192.168.100.210
IsAnonymous Connect to MQTT broker as an anonymous client No false
Username MQTT client username No username
Password MQTT client password No password
EnableTLS Enables a secure connection between broker and client No false
EnableDebugTopic Enables a special topic for feedback on connection state No true
DebugTopic Defines the debug topic No $SYS/Coreflux/modbus2mqtt/DebugTopic
Interface Defines the connection interface Yes TCPIP or SerialRTU
IP Modbus server IP Address. Used in TCPIP interface Conditional 192.168.100.200
SerialPort Used in SerialRTU interface Conditional COM3 or /dev/ttyUSB0
Retries Number of retries Yes 2
BaudRate Data exchange speed between devices Yes 9600
PollingMs Polling of registries in milliseconds Yes 500
StopBits Number of bits to indicate the end of a data frame Yes One
Parity Parity bit for error checking during data transmission Yes None
EndianType Order of registers Yes BigEndian or LittleEndian
Name Unique Tag identifier Yes outputExample
WriteDirection Origin and destination of data Yes 1 (ToMQTT)
MQTTTopic Unique topic connecting with the specified Register Yes machine/motorStart
MQTTQoS Quality of service for the MQTT topic Yes 0 (AtMostOnce)
MQTTRetain Defines if the message should be retained Yes false
ModbusMemoryArea Defines the register, coil, or input to access Yes 0 (Coils)
ModbusMemoryAddress Defines the Modbus memory address to read/write Yes 5
ModbusDataType Defines data type to read/write Yes 0 (Boolean)
RegisterByte Defines the register byte to read/write when using ASCII Conditional 0

Example JSON for TCP configuration:

{
  "MQTTParameters": {
    "Port": 1883,
    "Address": "192.168.100.210",
    "IsAnonymous": false,
    "Username": "username",
    "Password": "password",
    "EnableTLS": false,
    "EnableDebugTopic": true,
    "DebugTopic": "$SYS/Coreflux/modbus2mqtt/DebugTopic"
  },
  "ModbusParameters": {
    "Interface": "TCPIP",
    "Port": 502,
    "SerialPort": null,
    "IP": "192.168.100.200",
    "PollingMs": 500,
    "Retries": 0,
    "BaudRate": 9600,
    "StopBits": "None",
    "Parity": "None",
    "EndianType": "BigEndian"
  },
  "Tags": [
    {
      "EndianType": "LittleEndian",
      "Name": "outputExample",
      "WriteDirection": 1,
      "MQTTTopic": "machine/motorStart",
      "MQTTQoS": 0,
      "MQTTRetain": false,
      "ModbusMemoryArea": 0,
      "ModbusMemoryAddress": 5,
      "ModbusDataType": 0,
      "ModbusRegisterBit": 0,
      "RegisterByte": 0
    },
    {
      "EndianType": "LittleEndian",
      "Name": "inputExample",
      "WriteDirection": 1,
      "MQTTTopic": "machine/presenceSensor",
      "MQTTQoS": 0,
      "MQTTRetain": false,
      "ModbusMemoryArea": 3,
      "ModbusMemoryAddress": 2,
      "ModbusDataType": 0,
      "ModbusRegisterBit": 0,
      "RegisterByte": 0
    },
    {
      "EndianType": "LittleEndian",
      "Name": "registerExampleAscii",
      "WriteDirection": 1,
      "MQTTTopic": "machine/char",
      "MQTTQoS": 0,
      "MQTTRetain": false,
      "ModbusMemoryArea": 2,
      "ModbusMemoryAddress": 22,
      "ModbusDataType": 10,
      "ModbusRegisterBit": 0,
      "RegisterByte": 0
    }
  ]
}

Tags

Tag Parameters Configuration Table

Parameter Description Required Example
Name Unique Tag identifier Yes outputExample
WriteDirection Origin and destination of data Yes 1 (ToMQTT)
MQTTTopic MQTT topic connected to the Modbus register Yes machine/motorStart
MQTTQoS Quality of service for the topic Yes 0 (AtMostOnce)
MQTTRetain Define if the message is retained Yes false
ModbusMemoryArea Defines the register, coil or input to access Yes 0 (Coils)
ModbusMemoryAddress Modbus memory address to read/write Yes 5
ModbusDataType Define the data type to read/write Yes 0 (Boolean)
ModbusRegisterBit Defines the specific bit within a register (if applicable) No 0
RegisterByte Define the register byte for ASCII data type No 0

ModbusMemoryArea Table

ModbusMemoryArea Value Description
0 Coils (also known as outputs, are writable)
1 Discrete Inputs (read-only boolean values)
2 Input Registers (read-only numerical values)
3 Holding Registers (writable numerical values)

ModbusDataType Table

ModbusDataType Value Data Type Description
0 Boolean Single bit, read/write
1 BYTE 8-bit data, read/write
2 INT16 16-bit integer, read/write
3 UINT16 16-bit unsigned integer, read/write
4 INT32 32-bit integer, read/write
5 UINT32 32-bit unsigned integer, read/write
6 INT64 64-bit integer, read/write
7 Float32 32-bit floating point, read/write
8 Float64 64-bit double precision floating point, read/write
9 ASCII ASCII characters, read/write (specific handling for ASCII data)

Example JSON Configuration for Tags

{
  "Tags": [
    {
      "EndianType": "LittleEndian",
      "Name": "outputExample",
      "WriteDirection": 1,
      "MQTTTopic": "machine/motorStart",
      "MQTTQoS": 0,
      "MQTTRetain": false,
      "ModbusMemoryArea": 0,
      "ModbusMemoryAddress": 5,
      "ModbusDataType": 0,
      "ModbusRegisterBit": 0,
      "RegisterByte": 0
    },
    {
      "EndianType": "LittleEndian",
      "Name": "inputExample",
      "WriteDirection": 1,
      "MQTTTopic": "machine/presenceSensor",
      "MQTTQoS": 0,
      "MQTTRetain": false,
      "ModbusMemoryArea": 3,
      "ModbusMemoryAddress": 2,
      "ModbusDataType": 0,
      "ModbusRegisterBit": 0,
      "RegisterByte": 0
    },
    {
      "EndianType": "LittleEndian",
      "Name": "registerExampleAscii",
      "WriteDirection": 1,
      "MQTTTopic": "machine/char",
      "MQTTQoS": 0,
      "MQTTRetain": false,
      "ModbusMemoryArea": 2,
      "ModbusMemoryAddress": 22,
      "ModbusDataType": 10,
      "ModbusRegisterBit": 0,
      "RegisterByte": 0
    }
  ]
}
This JSON example comprehensively outlines the configurations necessary for utilizing tag parameters within a Modbus to MQTT flux asset system. Each tag contains parameters that define its function, communication specifics between Modbus and MQTT, and data handling preferences necessary for proper operation.

Saving the Configuration

To ensure the final Modbus to MQTT flux asset connector configuration is saved correctly with coreflux_modbus2mqtt, follow these instructions carefully. Accuracy in this process is crucial to guarantee the connector operates as expected. This guide assumes you're already logged in and have an asset installed. If not, please complete those steps first.

Save Configuration

First, you need to save the configuration by sending a payload to a specific MQTT topic. Use the command below, replacing <asset_guid> with the actual GUID of your asset and <configuration> with your configuration details in JSON format.

-assetConfigSave <asset_guid> <configuration>

To find your asset GUID, you can consult the $SYS/Coreflux/Assets topic.

Example:

-assetConfigSave 64b569da-7941-4398-9565-e63f3e6c5e04 { "config": "your_json_configuration_here" }

Make sure to replace { "config": "your_json_configuration_here" } with your actual JSON configuration.

Check Configuration (Optional)

After saving, you may want to verify that your configuration has been correctly saved. This is an optional step but recommended to confirm the settings are correctly applied. Use the command below, replacing <asset_guid> with your asset’s GUID.

-assetConfigLoad <asset_guid>

This step retrieves the currently saved configuration for the specified asset, allowing you to confirm it matches your intended settings.

Remember, clear and simple configurations are essential for smooth operation. Avoid complexity and ensure your JSON configuration is accurate and tailored to your asset’s requirements.