ADVANTECH Modbus To MQTT Router App User Guide

June 13, 2024
Advantech

Modbus to MQTT

Advantech Czech s.r.o., Sokolska 71, 562 04 Usti nad Orlici, Czech Republic
Document No. APP-0087-EN, revision from 12th October, 2023.

Modbus To MQTT Router App

© 2023 Advantech Czech s.r.o. No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photography, recording, or any information storage and retrieval system without written consent. Information in this manual is subject to change without notice, and it does not represent a commitment on the part of Advantech.
Advantech Czech s.r.o. shall not be liable for incidental or consequential damages resulting from the furnishing, performance, or use of this manual.
All brand names used in this manual are the registered trademarks of their respective owners. The use of trademarks or other designations in this publication is for reference purposes only and does not constitute an endorsement by the trademark holder.

Used symbols

| Danger – Information regarding user safety or potential damage to the router.
---|---
| Attention – Problems that can arise in specific situations.
| Information – Useful tips or information of special interest.
| Example – Example of function, command or script.

Changelog

  1. Modbus to MQTT Changelog
    v2.0.5
    • Change openssl (1.0.2u) to static library.
    v2.0.6
    • Add option of Azure SAS-token generation.
    • Need to install Python3 user module.
    • Add Data Type: Double World – Frame.
    • Add “Byte Swap” field in csv file.
    • Add supported Data type “String”.
    • Add “Word Swap” and “Byte Swap” for String Data Type.
    v2.0.7
    • Add show mosquitto error code and error message in the connected/disconnected function.
    v2.0.8
    • Add upload local cert and local key features for AWS.
    v2.0.9
    • Change modbus command maximum from 100 to 500.
    v2.0.10
    • Add polling the user module processes for each 5 seconds, if the user module crashed, it will run again.
    v2.0.11
    • Add “Custom2 Field” field in csv file.
    • Add “Send Group” field in csv file, for MQTT send group feature.
    • Add “Send interval” field in csv file, for MQTT send group feature.
    v2.0.12
    • Add Azure SAS-token generation (without Python3 user module). When Python3 user module installed, it will to use SAS-token generation by python.
    v2.0.13
    • Added ability to edit CSV, CA certificate, Local certificate and Local Private Key from WebUI.
    v2.0.14
    Fixed issue when the Router App mb2mqtt is loading default configuration after Firmware update.
    v2.0.15
    • Fixed an issue with displaying space values in the Mapping Table page.
    • Fixed an issue where the old value was displayed in the Mapping Table page when the configuration value was empty. v2.0.16
    • For WADMP: Fixed the issue that the default value has whitespaces.
    v2.0.17
    • To support Integer with 2 bytes size (Example: convert 0xFFFF to -1).
    • Set permissions to 755 for all files in the User Module.
    v2.0.18
    Fixed an issue with integer-to-float conversion.
    • Add more log message for MQTT value.
    v2.0.19
    • Increase Custom Fields to 10 (CSV configuration fields : Q, R, U AB)
    v2.0.20
    Fixed an issue where configuration comments were causing issues in the management system WADMP.

Description of the module

This Router app is not contained in the standard router firmware. Uploading of this router app is described in the Configuration manual (see Chapter Related Documents).
The router app is v2 router platform compatible.
Modbus to MQTT is an router app for providing seamless communication between Modbus/TCP devices and MQTT device. Modbus to MQTT works as Modbus/TCP master to communicate with Modbus/TCP devices, and works as MQTT publisher/subscriber to communicate with MQTT broker.

Web Interface

Once the installation of the module is complete, the module’s GUI can be invoked by clicking the module name on the Router Apps page of router’s web interface.
Left part of this GUI contains menu with Router menu section. Return to Router menu section switches back from the module’s web page to the router’s web configuration pages. The main menu of module’s GUI is shown on Figure 1.

  1. Router
    1.1 Settings
    Configuration of this router app can be done on Settings page, under Router menu section. All configuration items for Settings configuration page are described in the table below.
    ADVANTECH Modbus To MQTT Router App - Web Interface 2
Item Description
Service Enable Enabled, Modbus to MQTT APN functionality of the module is

turned on.
Log Enable APN| Enable the Service Log.
Broker Address| Enter the remote Broker Server Address.
Broker Server Port| Enter Broker Server Port Number (1-65535).
MQTT Keepalive| Enter MQTT keepalive interval (1-3600).
MQTT QoS| Enter MQTT QoS value (0,1,2).
MQTT Retain| Enable for message retaining.
Client ID| Enter Client ID.
MQTT Anonymous| Enable MQTT Anonymous
MQTT Username| Enter MQTT Username.
MQTT Password| Enter MQTT Password.
MQTT TLS| Enable MQTT TLS.
Interval(ms)| Enter Modbus TCP Polling Interval.
Timeout(ms)| Enter Modbus TCP Timeout.
CSV Config| Upload the file containing your CSV config here.
CA Certificate| Upload your CA Certificate here.
Local Certificate| Upload your Local Certificate here.
Local Private Key| Upload your Local Private Key here.

Table 1: Settings Example Items Description
1.2 Config file
In Modbus to MQTT, user configures the mapping between Modbus/TCP and MQTT through CSV file. In the csv file, the field separator (delimiter) is a comma.
ADVANTECH Modbus To MQTT Router App - Web Interface 3

Item Description
Topic MQTT topic
Name The name to identify the mapping.
IP The Modbus device IP address.
Port The TCP port number of the remote Modbus slave device.
Device ID The Modbus/TCP slave ID.
Function Code Modbus Function Code (FC). In Modbus to MQTT, supported

function codes are: 1, 2, 3, 4, 5, 6, 15, 16
01: Read coils;
02: Read discrete inputs;
03: Read holding registers;
04: Read input register;
05: Write single coil;
06: Write single register;
15: Write multiple coils;
16: Write multiple registers.
Address| Designate the read from/write to starting address for the Modbus registry.
Data length| When FC=1, 2, 5 or 15, the unit is bit(s)
When FC=3, 4, 6 or 16, the unit is word(s)
Modbus Data type| Modbus data type.
Options: Boolean, Integer, Unsigned Integer, Float
Data Swap| The Data Swap field determines the order in which the particular bytes of the received/transmitted data are delivered.
None: Do not swap; Word: 0x01, 0x02 becomes 0x02, 0x01;
Double Word: 0x01, 0x02, 0x03, 0x04 becomes 0x04, 0x03, 0x02, 0x01.
Double Word – Frame: 0x01, 0x02, 0x03, 0x04 becomes 0x04, 0x03, 0x02, 0x01.
Quad Word: 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07980 becomes 0x07980, 0x05, 0x06, 0x03, 0x04, 0x01, 0x02.
Byte Swap| Option: True, False
When option is True: 0x01, 0x02 becomes 0x01, 0x02.
0x01, 0x02, 0x03, 0x04 becomes 0x01, 0x02, 0x03, 0x04.
MQTT Data type| MQTT data type.
Options: Boolean, Integer, Unsigned Integer, Float, Long Integer, Unsigned
Multiplier| The value used to multiply the data value.
Offset| The value used to add/substract the data value.
Polling Interval (ms)| Modbus Polling Interval, unit: milliseconds.
The value range: 1 10000000
Send When Change| Select that the data is sent immediately when change happens on modbus slave.
Options: Yes, No
Custom Field| Custom definition value
Custom2 Field| Custom definition value
Send Group| Set group number for MQTT multiple messages to one message.
The value range is from 0 to 500. When the value is 0, this feature is disabled.
Send Interval| Send MQTT message interval for the group in seconds. The value range is from 1 to 10000 seconds.

Table 2:Configuration items description
The CSV file can be imported into Advantech router in router app Setting WEB page. After import CSV file and click “Save” button, the new mapping configuration will take effect immediately.
ADVANTECH Modbus To MQTT Router App - Web Interface 4 1.3Mapping table
The Modbus/TCP to MQTT mapping will be shown in Mapping Table WEB page.
ADVANTECH Modbus To MQTT Router App - Web Interface 7 1.4MQTT Data Format
When Modbus/TCP FC is 1, 2, 3 or 4, Modbus to MQTT will work as MQTT publisher to post Modbus/TCP data in JSON format to MQTT broker. When Modbus/TCP FC is 5, 6, 15 or 16, Modbus to MQTT will work as MQTT subscriber to ask subscription information, and forward the data to Modbus/TCP device.
Here are the example of MQTT data that is published from Modbus to MQTT.
ADVANTECH Modbus To MQTT Router App - Web Interface 5Note that Modbus to MQTT verify just topic, name and value fields of the received subscription information.
ADVANTECH Modbus To MQTT Router App - Web Interface 6

Related Documents

You can obtain product-related documents on Engineering Portal at icr.advantech.cz address.
To get your router’s Quick Start Guide, User Manual, Configuration Manual, or Firmware go to the Router Models page, find the required model, and switch to the Manuals or Firmware tab, respectively.
The Router Apps installation packages and manuals are available on the Router Apps page.
For the Development Documents, go to the DevZone page.

Modbus to MQTT Manual

Documents / Resources

| ADVANTECH Modbus To MQTT Router App [pdf] User Guide
Modbus To MQTT Router App, Modbus, To MQTT Router App, MQTT Router App, Router App
---|---

References

Read User Manual Online (PDF format)

Read User Manual Online (PDF format)  >>

Download This Manual (PDF format)

Download this manual  >>

Related Manuals