Modbus TCP to MQTT using Hive MQTT 1: Difference between revisions

From Silbo Networks
(Created page with "=== 1. Summary === * In this guide, Modbus TCP to MQTT function will be configured using third-party MQTT broker services (in this example <nowiki>https://www.hivemq.com/</nowiki>). * The Router will be used as TCP Master and MODSIM (application) will be used as TCP slave. * PC will act as MQTT Publisher and Subscriber. === 2. Prerequisites: === * Connecting board to device: <br/>Connect your router to your device via * Ethernet cable: <br/>Directly connect router por...")
 
No edit summary
 
Line 25: Line 25:
# TCP port : 502
# TCP port : 502
# Click ok
# Click ok
[[File:Configure Modbus TCP Slave .png|alt=Configure Modbus TCP Slave |none|thumb|650x650px|                                             ''*Modbus TCP Slave (MODSIM) has been configured*'']]
[[File:Configure Modbus TCP Slave .png|none|thumb|650x650px|''*Modbus TCP Slave (MODSIM) has been configured*'']]
 
=== 5. Configure Modbus TCP Master (Router):  ===
=== 5. Configure Modbus TCP Master (Router):  ===
After login, go to configuration=> Modbus configuration,
After login, go to configuration=> Modbus configuration,


==== 1. Click on Add Device  ====
==== 1. Click on Add Device  ====
[[File:Configure Modbus TCP Master .png|alt=Configure Modbus TCP Master |none|thumb|650x650px|Configure Modbus TCP Master ]]
[[File:Configure Modbus TCP Master .png|none|thumb|650x650px|Configure Modbus TCP Master]]


==== 2. Parameters Configuration: ====
==== 2. Parameters Configuration: ====
[[File:Configure Modbus TCP Master - Parameters Configuration.png|alt=Configure Modbus TCP Master - Parameters Configuration|none|thumb|650x650px|''                                     *Refer the table below for input details*'']]
[[File:Configure Modbus TCP Master - Parameters Configuration.png|none|thumb|650x650px|''                                                            *Refer the table below for input details*'']]
{| class="wikitable sortable"
{| class="wikitable sortable"
!Field
!Field
Line 109: Line 110:


==== 3. Register config: ====
==== 3. Register config: ====
[[File:Configure Modbus TCP Master (Router)-Register config.png|alt=Configure Modbus TCP Master (Router)-Register config|none|thumb|650x650px|Configure Modbus TCP Master (Router)-Register config]]
[[File:Configure Modbus TCP Master (Router)-Register config.png|none|thumb|650x650px|Configure Modbus TCP Master (Router)-Register config]]
*If you want to add additional parameters in single slave Address <br/>Option 1: Default mapping  <br/>Option 2: Custom mapping
*If you want to add additional parameters in single slave Address <br/>Option 1: Default mapping  <br/>Option 2: Custom mapping
{| class="wikitable"
{| class="wikitable"
Line 153: Line 154:
# RS485 Topic (optional): Give a topic name and copy it
# RS485 Topic (optional): Give a topic name and copy it
# Save
# Save
 
[[File:Cloud Configuration (MQTT Gateway) on Modbus TCP Master.png|none|thumb|650x650px|Cloud Configuration (MQTT Gateway) on Modbus TCP Master]]
[[File:Cloud Configuration (MQTT Gateway) on Modbus TCP Master.png|alt=Cloud Configuration (MQTT Gateway) on Modbus TCP Master|none|thumb|650x650px|Cloud Configuration (MQTT Gateway) on Modbus TCP Master]]


=== 7. Configure hivemq.com MQTT Broker: ===
=== 7. Configure hivemq.com MQTT Broker: ===
Line 166: Line 166:
# Paste the topic name copied from MQTT Gateway (refer cloud configuration)
# Paste the topic name copied from MQTT Gateway (refer cloud configuration)
# Click on subscribe
# Click on subscribe
 
[[File:Configure hivemq.com MQTT Broker.png|none|thumb|650x650px|''*MQTT Broker is ready to publish data*'']]
[[File:Configure hivemq.com MQTT Broker.png|alt=Configure hivemq.com MQTT Broker|none|thumb|650x650px|''*MQTT Broker is ready to publish data*'']]


=== 8. Testing MQTT Publisher and Subscriber on hivemq.com: ===
=== 8. Testing MQTT Publisher and Subscriber on hivemq.com: ===
Line 173: Line 172:
# Navigate to Appmanagerà '''->'''IO Utilities
# Navigate to Appmanagerà '''->'''IO Utilities
# Enter Slave ID assigned (in this example slave id = 1)
# Enter Slave ID assigned (in this example slave id = 1)
# Click Read to generate output.[[File:Testing MQTT Publisher and Subscriber on hivemq.com- Click Read to generate output..png|alt=Testing MQTT Publisher and Subscriber on hivemq.com: Click Read to generate output.|none|thumb|650x650px|Testing MQTT Publisher and Subscriber on hivemq.com: Click Read to generate output.]]
# Click Read to generate output.[[File:Testing MQTT Publisher and Subscriber on hivemq.com- Click Read to generate output.png|none|thumb|650x650px|Testing MQTT Publisher and Subscriber on hivemq.com: Click Read to generate output.]]
# Output
# Output
# Once you see “TCP Modbus read successful” we can publish data on hive MQTT.[[File:TCP Modbus read successful” we can publish data on hive MQTT..png|alt=TCP Modbus read successful” we can publish data on hive MQTT.|none|thumb|650x650px|TCP Modbus read successful” we can publish data on hive MQTT.]]
# Once you see “TCP Modbus read successful” we can publish data on hive MQTT.[[File:TCP Modbus read successful” we can publish data on hive MQTT.png|none|thumb|650x650px|TCP Modbus read successful” we can publish data on hive MQTT.]]
# Navigate to Appmanager à Application start/stop
# Navigate to Appmanager à Application start/stop
# click on start, wait until the sign turns to stop [[File:Testing MQTT Publisher and Subscriber on hivemq.com-click on start, wait until the sign turns to stop .png|alt=Testing MQTT Publisher and Subscriber on hivemq.com-click on start, wait until the sign turns to stop |none|thumb|650x650px|Testing MQTT Publisher and Subscriber on hivemq.com-click on start, wait until the sign turns to stop ]]Open Hivemq.com and data should start publishing, ''this means that MQTT Gateway on Modbus TCP Master router is working correctly, and Modbus TCP Slave receives request''[[File:Hive Mq.png|alt=Hive Mq|none|thumb|650x650px|Hive Mq]]
# click on start, wait until the sign turns to stop[[File:Testing MQTT Publisher and Subscriber on hivemq.com-click on start, wait until the sign turns to stop .png|none|thumb|650x650px|Testing MQTT Publisher and Subscriber on hivemq.com-click on start, wait until the sign turns to stop]]Open Hivemq.com and data should start publishing, ''this means that MQTT Gateway on Modbus TCP Master router is working correctly, and Modbus TCP Slave receives request''[[File:Hive Mq.png|none|thumb|650x650px|Hive Mq]]

Latest revision as of 12:17, 30 May 2024

1. Summary

  • In this guide, Modbus TCP to MQTT function will be configured using third-party MQTT broker services (in this example https://www.hivemq.com/).
  • The Router will be used as TCP Master and MODSIM (application) will be used as TCP slave.
  • PC will act as MQTT Publisher and Subscriber.

2. Prerequisites:

  • Connecting board to device:
    Connect your router to your device via
  • Ethernet cable:
    Directly connect router port with RJ45 wire to your device.
  • Wireless network connection:
    Connect router to your device using Wi-Fi, check device name and password on the device’s label.
    For Example: SSID: APClient_37B11241001                            
                PWD: 12345678

3. Login to device:

  • To enter the router’s Web interface (web IU), type 192.168.100.1 (wireless LAN IP) into the URL field of your internet browser.
  • Use the following login information when prompted for authentication.
    Username: admin
Login to device
Login to device


4. Configure Modbus TCP Slave (MODSIM): Download and Open MODSIM:

  1. Click on File
  2. New
  3. Address: Start bit address
  4. Length: No of registers to be read
  5. Select based on parameters to read
  6. Device Id: Set Slave ID
  7. Connect to Modbus TCP service port
  8. TCP port : 502
  9. Click ok
*Modbus TCP Slave (MODSIM) has been configured*

5. Configure Modbus TCP Master (Router):

After login, go to configuration=> Modbus configuration,

1. Click on Add Device

Configure Modbus TCP Master

2. Parameters Configuration:

                                      *Refer the table below for input details*
Field Value Description
Device Name Invendis Any name of your choice.
Port no 1.) RS485 Port-1

2.) RS232 Port-2

Depending on the port that is available on your router.
Meter ID Default = 1 Can change as per your device.
Meter Model abcd Any name of your choice.
Function code Read coils (1)

Read input coils (2)

Read holding registers (3)

Read input registers (4)

Specifies the type of register being addressed by Modbus request.
Slave Address 1 According to the device connected to poll data, slave ID is mentioned.
Modbus Protocol 1.) RTU = 300 | 1200 | 1800 | 2400 | 4800 | 19200 | 38400 | default: 9600

2.) TCP

*Modbus Comm IP

-192.168.10.147

*Modbus Comm Port

-502 (default)

*Modbus Comm Timeout

-10

1.) Serial data transmission rate (in bits per second).

2.)

*Modbus Comm IP = IP of the device you are communicating with.

*Modbus Comm Port = TCP port number

*Modbus Comm Timeout = As per your requirement.

Start Register 0 First Modbus register from which data will be read.
No of Register 10 Number of Modbus registers that will be read during the request.

3. Register config:

Configure Modbus TCP Master (Router)-Register config
  • If you want to add additional parameters in single slave Address
    Option 1: Default mapping
    Option 2: Custom mapping
Field Value Description
Default mapping 1.) Tag Name = (Ex: FQ)

2.) Data type = 8bit INT | 8bit UINT | 16bit INT, high byte first | 16bit INT, low byte first | 16bit UINT, high byte first | 16bit UINT, low byte first | 32bit float (various Byte order) | 32bit INT (various Byte order) | 32bit UINT (various Byte order) | 1 bit; default: Hexadecimal

1.) Input value name.

2.) Defines how read data will be stored.

Custom mapping 1.) Register name:

2.) Start register:

3.) Register count:

4.) Data type = 8bit INT | 8bit UINT | 16bit INT, high byte first | 16bit INT, low byte first | 16bit UINT, high byte first | 16bit UINT, low byte first | 32bit float (various Byte order) | 32bit INT (various Byte order) | 32bit UINT (various Byte order) | 1 bit; Hexadecimal; default: 32-bit floating point

1.) Input value name.

2.) First register in custom register block.

3.) Path to file in which the custom register block will be stored.

4.) Defines how read data will be stored.

*Modbus TCP Master (router) has been configured*

6. Cloud Configuration (MQTT Gateway) on Modbus TCP Master:

Open routers WebUI and navigate to Configuration à Cloud Configuration

  1. Site ID: Give name accordingly
  2. Cloud/Protocol: HTTP; MQTT; Azure à Select protocol in use
  3. MQTT Host: Host name as per the MQTT broker selected ( in use hivemq.com)
  4. MQTT Port: 1883 (default)
  5. Authentication Mode: no authentication; username/password; TLS                                                    (further added procedure if selected the other two)
  6. RS485 Topic (optional): Give a topic name and copy it
  7. Save
Cloud Configuration (MQTT Gateway) on Modbus TCP Master

7. Configure hivemq.com MQTT Broker:

It is an open server so no need to login

  1. Click MQTT
  2. Public MQTT Broker
  3. Try MQTT Browse client
  4. Click on connect, wait until the light turns green
  5. Click on Add new subscription
  6. Paste the topic name copied from MQTT Gateway (refer cloud configuration)
  7. Click on subscribe
*MQTT Broker is ready to publish data*

8. Testing MQTT Publisher and Subscriber on hivemq.com:

  1. Navigate to Appmanagerà ->IO Utilities
  2. Enter Slave ID assigned (in this example slave id = 1)
  3. Click Read to generate output.
    Testing MQTT Publisher and Subscriber on hivemq.com: Click Read to generate output.
  4. Output
  5. Once you see “TCP Modbus read successful” we can publish data on hive MQTT.
    TCP Modbus read successful” we can publish data on hive MQTT.
  6. Navigate to Appmanager à Application start/stop
  7. click on start, wait until the sign turns to stop
    Testing MQTT Publisher and Subscriber on hivemq.com-click on start, wait until the sign turns to stop
    Open Hivemq.com and data should start publishing, this means that MQTT Gateway on Modbus TCP Master router is working correctly, and Modbus TCP Slave receives request
    Hive Mq