Introduction
Milesight gateway is able to work as Modbus servers (slaves) to set up communication between LoRaWAN devices and Modbus clients (masters) via Modbus RTU over TCP or Modbus TCP protocol, which can quickly and easily integrate LoRaWAN devices to BMS or PLC systems.
Requirement
- Milesight Gateway: UG65/UG67(v60.0.0.45 and later), UG56 (v56.0.0.5 and later)
- Any LoRaWAN sensor
- Modbus Client tool: take Modbus Poll as example
Configuration
Read Data
1. Go to Network Server > Payload Codec to ensure the codec library version is 1.3.5 and later if you would like to add Milesight devices to gateway.
If the codec list does not include your devices, please custom the codec referring to article How to Use Payload Codec on Milesight Gateway. If you require to receive device data, ensure your custom codec has both Decoder and Object Mapping Function; if you require to send downlink commands to devices, ensure your custom codec has both Encoder and Object Mapping Function.
2. Connect LoRaWAN node to Milesight gateway referring to article How to Connect LoRaWAN Nodes to Milesight Gateway. Note that ensure the correct payload codec is selected correctly.
3. Go to Network Server > Packets to check if there is uplink packet and click Details to check if the decoder works. If works, the JSON item will show the decoded result.
4. Go to Protocol Integration > Modbus Server > Server to add a Modbus server (slave) and configure the settings.
- Enable: enable or disable this server
- Name: customize a unique name for this server
- Network Interface: select the network interface to communicate with Modbus client (master)
- Port: customize a unique communication port for this server. This needs to ensure this port is not occupied or blocked by firewall
- Connection Type: Select Modbus TCP or Modbus RTU over TCP
- Server ID: customize a unique server ID (slave ID) for Modbus client to identify every server
5. Go to Protocol Integration > Modbus Server > Modbus Object page, select the Modbus server to add objects, then click Add to select the objects to add to this server. The register type and data format can be changed as required.
Click Save to save the settings.
6. After adding, you can check if object values are updated regularly.
Note: some objects will not update values since they are just used for sending downlink commands.
7. Open Modbus Poll tool, click Setup > Read/Write Definition to configure the read/write settings.
- Slave ID: server ID of used Modbus server
- Function: select the register type to read or write data
- Address: set the start register address to read or write the data
- Quantity: set the quantity to read or write the data
8. Click Connection >Connect to configure Modbus server information.
- Connection: if gateway server connection type is Modbus TCP, select Modbus TCP/IP; if gateway server connection type is Modbus RTU over TCP, select Modbus RTU/ASCII Over TCP/IP
- Remote Server: the IP address of the gateway
- Server Port: the port set in gateway Protocol Integration > Modbus Server > Server page
9. Click OK, then you can see the reading results of data.
Note: if the values on Modbus Poll is different from present values on the gateway, please change the reported data format.
Write Data
1. Ensure the correct payload codec is selected correctly and the fPort is configured correctly when adding this device. The default fPort is 85 for Milesight devices.
2. Go to Network Server > Packets to send downlink commands to devices, and check if any response from device.
3. Click Function page to select the register type to write. Only Coil type and Holding Register type objects support to write commands. Take Coil as example, click Write Single Coil page, then set the slave ID (server ID of used Modbus server), register address and the value, then click Send.
After sending, go to Network Server > Packets to check if there is downlink command sent and the response.
Note: when you modify the value of this kind of object, it is necessary to change the values of related objects together within 60s. Otherwise, the write operation will be failed.
-END-