How to use Modbus


Introduction

Modbus is a communication protocol commonly used in industrial automation to facilitate the exchange of data between different devices, such as sensors, controllers, and actuators. Modbus can be used to query and set Node configuration options from LAN devices. LAN device executing the query can then relay the data forward for example to a SCADA supervisory system.

Modbus has become a widely adopted standard in the industry. There are variants of the Modbus protocol of which Tosibox implementation support the Modbus TCP/IP. Modbus standard ensures interoperability and compatibility between devices from different manufacturers that support Modbus communication.

 

Modbus is supported on Lock 150, 210, 250, 500 and Tosibox 175, 350, 375, 610, 650, 670, 675, 695 starting with firmware 5.5.0.

 

Configuring the Node

Enabling and configuring Modbus is done on the Advanced Settings page.

Settings:

After enabling the Modbus server it listens on port 502 on WLAN access point and all physical LAN interfaces. Modbus data update rate is around 10 seconds.

If Modbus clients asks data rarely (e.g. once a minute), first query may yield 0xFFFF value. Client must wait a few seconds and ask again.

Modbus uses simple TCP/IP request-response protocol, it does not have connected/disconnected states. If a Modbus client goes offline Modbus server on the Node will not be notified. Node keeps the last state that was set until explicitly changed.

Connectivity

Connectivity starting with firmware version 5.7.0

After enabling the Modbus server it listens on port 502 on WLAN access point and all physical LAN interfaces. Modbus data update rate is around 10 seconds.

If Modbus clients asks data rarely (e.g. once a minute), first query may yield 0xFFFF value. Client must wait a few seconds and ask again.

SMS sending

SMS sending via Modbus is supported on Lock 500i and Tosibox 175, 375, 670, 675, 695 starting with firmware 5.7.0. Device with an internal modem is required, devices with external modem are not supported. Also ensure that the used SIM plan has SMS capability.

Recommended procedure:

1.Write the phone number to registers 49-58

2. Write message to registers 59-138

3. Write 1 to register 47. This triggers system to set the SMS status register 48 to 0 and initiate messaging.

4. Poll register 48 to see the status. Keep polling level decent, 1 poll per 2 seconds. While status is 0, do not alter any other SMS field until status indicates sending is finished.

5. If sending fails, send again repeating from step 3, phone number and message are preserved, or if new message is wanted start from step 1.

Composing the phone number and the message

Following instructions apply to forming the phone number and the message string. If the Modbus client accepts ASCII, you can input the phone number and message normally on the UI and these instructions should not be needed.

If ASCII or hexadecimals are not supported, but decimals are supported:

Extracting GNSS and time

Following example applies to composing the GNSS coordinates and UTC time. GNSS coordinates for Tosibox offices displayed on Tosi gateway UI are

Latitude 65° 03.417123 is reported as a 64-bit floating point as 6503.417123 by the Modbus. Modbus registers for GNSS latitude, longitude and UTC time are little-endian but the bytes within a single register are big-endian. For the example in question registers are:

Combining the registers to a 64-bit floating point in reverse (little-endian) order 3, 2, 1, 0 yields the reported GNSS latitude 6503.417123.

Registers

DataData valueRegisters first - last relative to 40001Return value if data is not availableComment

GNSS latitude

64-bit IEEE-754 floating point (little-endian)

0 - 3

Registers: 4

NaN

Returns 0xFFFF on devices without GNSS

GNSS longitude

64-bit IEEE-754 floating point (little-endian)

4 - 7

Registers: 4

NaN

Returns 0xFFFF on devices without GNSS

GNSS UTC time, seconds since midnight

64-bit IEEE-754 floating point (little-endian)

8 - 11

Registers: 4

NaN

GNSS data does not outdate, i.e. the latest info will be be posted as long as there is no new coordinates.

Returns 0xFFFF on devices without GNSS

GNSS talker ID

two-byte talker ID

12

Registers: 1

0

List of talkers can be found e.g. from NMEA Revealed 

Bytes are written in memcpy style so first byte is little end. For example if receiving value is 20551 = 0x5047, little end is 0x47 ('G') and big end 0x50 ('P') → 20551 means talker ID 'GP'.

Returns 0xFFFF on devices without GNSS

GNSS locking/fix status either as quality or as pos mode

Unsigned 16-bit integer (little-endian)

13

Registers: 1

0xFFFF

Values 0-9

  • 0 - Fix not available

  • 1 - GPS fix

  • 2 - Differential GPS fix

  • 3 - PPS fix

  • 4 - Real Time Kinematic

  • 5 - RTK float

  • 6 - Estimated (dead reckoning)

  • 7 - Manual input mode

  • 8 - Simulation mode

Values > 32: pos mode character as ASCII

  • N - No fix

  • A - Autonomous GNSS fix

  • D - Differential GNSS fix

  • E - Estimated/Dead reckoning fix

  • F - RTK float

  • R - RTK fixed

Returns 0xFFFF on devices without GNSS and if value is not available

Mobile signal strength (RSRP in dBm)

Unsigned 16-bit integer (little-endian)

14

Registers: 1

0xFFFF

Supports both internal and external modems. If both modems are in one Node, internal modem gets priority over external modem

Mobile signal strength (RSSI in dBm)

Unsigned 16-bit integer (little-endian)

15

Registers: 1

0xFFFF

Supports both internal and external modems. If both modems are in one Node, internal modem gets priority over external modem

Internet connection interface

Unsigned 16-bit integer (little-endian)

16

Registers: 1

0xFFFF

  • 0 - Not Connected

  • 1 - WAN Connected

  • 2 - Cellular connected internal modem

  • 3 - Cellular connected external modem

  • 4 - LAN connected

  • 5 - WLAN client

  • 10 - connected with unknown interface

Tosibox Cloud connection status

Unsigned 16-bit integer (little-endian)

17

Registers: 1

0xFFFF

  • 0 - Not OK

  • 1 - OK

VPN connection count

Unsigned 16-bit integer (little-endian)

18

Registers: 1

0xFFFF

Number of open VPN tunnels. 

Count may include also VPNs that are not actually functional (e.g. VPN's that are still being established or malfunctioning, but not yet closed).

Internet access enabled

(Read/Write)

Unsigned 16-bit integer (little-endian)

19

Registers: 1

0xFFFF

  • Change takes control and remains in effect until disabling Modbus server from UI

  • If “Master for Internet/VPN access states“ is disabled, writing will result in Modbus exception: illegal data address

Read and write values:

  • 0 - internet access disabled

  • 1 - internet access enabled

VPN access enabled

(Read/Write)

Unsigned 16-bit integer (little-endian)

20

Registers: 1

0xFFFF

  • Change takes control and remains in effect until disabling Modbus server from UI

  • Note that this will cut Tosibox Cloud connection and it will be indicated on the Node Status page

  • If “Master for Internet/VPN access states“ is disabled, writing will result in Modbus exception: illegal data address

Read and write values:

  • 0 - VPN access disabled

  • 1 - VPN access enabled

Firmware major version number 

Unsigned 16-bit integer (little-endian)

21

Registers: 1

0xFFFF

Returns the first of the three numbers in the end-point device firmware release version.

For example in a version 1.2.3 this is the number 1.

Introduced in firmware version 5.6.0

Firmware minor version number 

Unsigned 16-bit integer (little-endian)

22

Registers: 1

0xFFFF

Returns the second of the three numbers in the end-point device firmware release version.

For example in a version 1.2.3 this is the number 2.

Introduced in firmware version 5.6.0

Firmware patch version number 

Unsigned 16-bit integer (little-endian)

23

Registers: 1

0xFFFF

Returns the last of the three numbers in the end-point device firmware release version.

For example in a version 1.2.3 this is the number 3.

Introduced in firmware version 5.6.0

Internal or external modem SIM ICCID

Unsigned 16-bit integer (little-endian)

24 - 45

Registers: 22

0xFFFF

Checks first internal, then external modem. If neither are found or don’t have ICCID returns 0xFFFF on all fields.

ICCID is variable length between 18-22 numbers. First number starts running at register 24. If ICCID is less than 22 numbers, extra fields have 0xFFFF.

Introduced in firmware version 5.6.0

Reserved for future use

 

46

 

 

Send SMS message

Write only

 

47

Registers: 1

-

Write 1 to send SMS message, cleared by the device after the message has been sent. Ensure all other SMS fields are filled in before triggering send.

Introduced in firmware version 5.7.0

SMS message status

 

48

Registers: 1

0xFF

Status for SMS message sending. Status codes:

  • 0: on going, message is being sent
  • 1: success
  • 2: failure
  • 3: modem not ready
  • 255: default value, no status to report

Introduced in firmware version 5.7.0

SMS phone number

Write only

 

49 - 58

Registers: 10

-

Phone number in ASCII to which the SMS will be sent, network byte order, padded with 0x00.

2 bytes per register, 20 numbers or characters in total.

Introduced in firmware version 5.7.0

SMS message text

Write only

 

59 - 138

Registers: 80

-

SMS message string, max 80 char., in UTF-8, network byte order, padded with 0x00.

2 bytes per register, 160 numbers or characters in total.

Introduced in firmware version 5.7.0