...
...
Variant battery powered
...
...
Data Sheet with dimensions (PDF)
Further customization Options
The product variants shown above are the standard variants.
...
Modbus defines four different object types form which values can be read: Coils, Discrete Inputs, Input Registers, and Holding Registers. Of those four, Coils and Holding Registers can also be written to. Coils and Discrete Inputs hold single bit values while Input Registers and Holding Registers hold 16 bit values. For values that cannot fit into 16 bit, it is customary to use multiple consecutive registers to hold the value. Modbus does not define what the bytes in the registers represent; it is up to the creator of the Modbus Slave Device to specify how to interpret the stored bits. A 16 bit register could be used to hold a single byte value, for example, or four consecutive registers could hold a double precision floating point number. Storing texts as ASCII characters is also possible. For integer numbers in particular it there is no defined byte order, nor signage definition. Because of those ambiguities it is not possible for the Lobaro LoRaWAN Bridge to understand the data read from/written to Slave Devices. All communications therefore simply forward raw Modbus Commands and Responses with their payload, as it communicated on the Bus. Any check sums (CRC16 for RTU, LRC for ASCII) are excluded from LoRaWAN communications or the Bridge's configuration, as there are other check sums in work their already.
For a deeper introduction into Modbus please refer to https://en.wikipedia.org/wiki/Modbus.
Quick Start Guide
Please refer to the rest of this documentation for a save and proper use of the Modbus Bridge.
This Quick Start Guide can only show you basic operations. It illustrates reading a single value from one Slave Device.
- Connect the Modbus Bridge to your Modbus Slave Device using the RS485 connection using a twisted pair cable:
A
toA
,B
toB
, andGND
toGND
(GND
is not strictly necessary but enhances the connection. Not all slave devices supply aGND
connector). - Connect the Modbus Bridge to a computer using the Lobaro Configuration Adapter and the Lobaro Maintenance Tool.
- Synchronise the LoRaWAN configuration parameters between the Bridge and your Network Server.
- Make sure the Bridge is in reach of a Gateway attached to your Network Server.
- Set the Modbus Parameters according to your Slave Device (ASCII/RTU, Baud, Data Length, Stop Bits, Parity).
- Set
MbCmd
to the Modbus Command to read the register you need (see below). - Save the configuration and switch to the Log tab. You should see the device requesting the data and uploading it via LoRaWAN.
MbCmd
must contain the Modbus Command the Bridge will execute. The command is entered in Hex and without any checksums and is 6 bytes long (12 hexdigits). The default value is 010300000003
, it consists of 4 parts: 01
, 03
, 0000
, 0003
01Address of the Slave Device. 1 byte: often 01 new devices03What kind of Modbus Register to read. 1 byte. 03 stand for Holding Register.0000Number/address of the first register to read. 2 bytes. Many devices have some value to read out at 0000.0003Number of consecutive registers to read from the first register. 2 bytes. This would read the registers #0, #1, and #2 in one command.
The format used for MbCmd
is conforming to the Modbus Standard. See Configurations/Modbus Commands for a description and Examples for some more advance examples. The Modbus Bridge has a Dialog Mode that lets you try out Modbus Commands interactively which helps getting used to the syntax and helps you in trying out your slave devices.
Work Cycle
The Modbus LoRaWAN Bridge has a simple work cycle. It spends most of the time in a deep sleep state, to conserve energy. For every reading it wakes up for a few seconds, requests values from the connected slave devices, uploads the data via LoRaWAN, and then goes to sleep again. The following flowchart illustrates the work cycle:
Cron expression
Init
Test Reading
LoRaWAN Join
Data Collection
Data Transfer
Sleep
InitWhen the device starts (because it has just been connected to a power source, or after a reboot) it begins in the Init state. A quick self-check is executed; if that succeeds, the green on-board LED blinks once, slowly. After that the configuration is evaluated and checked for invalid values. If any problems are detected during Init, the device's LED will light up for three times, and the device will then reboot. If everything is okay, the device will continue with the Test Reading.Test ReadingAfter verifying configuration, the Bridge executes all Modbus Commands stored once without uploading the results but logging them only to the console. This makes it easy to verify all Modbus Slaves are reachable and their registers can be read. Connect your computer to the Bridge using the Lobaro Config Adapter and check the output using the Lobaro Maintenance Tool. The device will continue with LoRaWAN Join to connect to the Network (whether the test reading was successful or not does not change this).LoRaWAN JoinThe Bridge tries to connect to the LoRaWAN Network. The Details depend on the device's configuration (OTAA vs. ABP, optional Time synchronisation). Unless ABP is used, the Bridge will remain in this state until joining succeeds. It will repeat to send Join requests with decreasing frequency. After successfully attaching it enters Data Collection for the first time and starts the normal operation cycle.Data CollectionThe Bridge sends all Modbus Commands from the Configuration on the Bus and collects the answers (or lack thereof).Data TransferThe collected Modbus Responses are uploaded via LoRaWAN. This can take multiple upload messages depending on the amount of data collected. Once a day a status message is also uploaded, giving some information about the state of the Bridge itself. If many messages are uploaded this can take a long time. At least one message is uploaded during this state. When all data is uploaded, the device goes to Sleep.SleepBetween activations the device enters a very power efficient sleep mode. It stays dormant until the time specified by the Cron expression, when it changes back to Data Collection.
Configuration
The (initial) configuration is normally done using our free Lobaro Maintenance Tool and the USB PC configuation adapter.
Beside this the configuration can also be changed or read remotely in the field using LoRaWAN downlink messages, see Downlinks description.
LoRaWAN
The connection to the LoRaWAN network is defined by multiple configuration parameters. This need to be set according to your LoRaWAN network and the way your device is supposed to be attached to it, or the device will not be able to send any data.
For a detailed introduction into how this values need to be configured, please refer to the chapter LoRaWAN configuration in our LoRaWAN background article.
...
Name
...
Description
...
Type
...
Values
...
Modbus/UART
There are several values that define the configuration via Modbus. These values depend on the Slave devices that you want to read out. Please refer to your Modbus Devices's manual to find out the correct configuration.
name | description | values |
---|---|---|
MbProt | Modbus-Protocol to use | RTU . ASCII |
MbBaud | UART Baud rate | 9600 , 19200 , 38400 , ... |
MbDataLen | UART data length | 7 , 8 , 9 |
MbStopBits | UART stop bits | 0.5 , 1 , 1.5 , 2 (written exactly like this) |
MbPar | UART parity | NONE , EVEN , ODD |
MbCron | Cron expression† defining when to read. | 0 0/15 * * * * for every 15 minutes |
MbCmd | List of Modbus Commands (see below). | 010300010003 |
PlFmt | Uplink Format | 1 , 2 , or 3 , see Payload Formats |
EnDL | Enable Downlinks | true = enable sending Modbus Commands via Downlink |
DialogMode | Enable Dialog Mode | true = set the Bridge to Dialog Mode |
LbtDuration | Listen-before-talk Duration | 0 = disables, 1 -3600 = seconds of lbt duration |
LbtSilence | Listen-before-talk Silence | 0 = disabled, 1 -3600 seconds of silence needed |
† See also our Introduction to Cron expressions.
Modbus Commands
Whenever the cron expression given in the configuration value MbCron
activates, the Modbus Bridge wakes up from hibernation (or listening mode, for Class C), a set of configured Modbus Commands (set in the configuration parameter MbCmd
) is executed over the RS-485 bus. Any responses received from the addressed Slave Device will be uploaded via LoRaWAN.
...
...
...
...
...
...
Data messages
Data messages contain responses to Modbus Commands received by the Bridge. The Bridge supports multiple Payload formats for different use cases. The format is selected by the configuration parameter PlFmt
:
1
: Verbose payload format (port 3)2
: Compact payload format with time (port 6)3
: Compact payload format without time (port 7)
VERBOSE PAYLOAD FORMAT
The verbose payload format (PlFmt
=1
) is the standard setting of the Bridge. It is designed to be very versatile (it uploads the complete Response sent by the Slave Devices, so reading registers as well as writing registers are both supported). It contains all information you need to know the register and the slave device your data is coming from. You do not need to know the exact configuration of your devices in your backend to be able to parse the data. This is convenient when you have man Modbus Bridges with different configuration in the field. This payload format is also good in communicating error conditions in case the executed Modbus Commands fail. The trade off is overhead in the transmission. If you need to get a lot of data uploaded often, this could be a problem for you with the limited LoRaWAN bandwidth. If this is a problem for your use case, you should take a look at the compact data formats.
Data messages using the verbose payload format are uploaded on port 3. Every message starts with a 5 byte timestamp (UNIX timestamp as big endian int40
, see timestamps in our LoRaWAN devices) for more information). The timestamp is followed by one or more responses of varying length.
Each of the responses starts with a single byte (uint8
) indicating the length of its payload (len
) followed by that many bytes of payload. The payload consists of the raw Modbus response as sent by the Slave Device followed by 3 additional bytes: the first register/coil as uint16
(big endian) and the number of registers/coils as uint8
taken from the executed command. The following tables visualise the message structure. See the Examples Section for some sample data messages explained down to the individual bytes. We also provide a Reference Decoder in JavaScript that can read the format.
The timestamp in the message is the wakeup time when the device was activated by the cron expression in MbCron
(using the devices internal clock). The Modbus Response in the message in addition with the start register/coil and the register/coil count makes it possible to know which registers/coils where exactly read/written, what kind they were, and the address of the device. For Modbus Commands that do not have a register/coil count (like function 5, forcing a single coil), or for those that do not contain a start register/coil (e.g. funtion 7, reading exception status), the contents of the additional fields start register
and/or count
are undefined. The payload format used only a single byte for the count value, so if you are reading/writing more than 255 coils, the higher byte will be cut off.
The Bridge puts as many responses as in one message as possible (without changing the order of responses and respecting the maximal message size of the current Spreading Factor). If the responses do not fit into a single message it will upload as many messages as needed. When a single response is too long to fit in a message, the response will be split up over multiple messages and will need to be reassembled in the backend. See Split Messages for instructions on how to do that and how to prevent splitting.
Structure of a message on port 3:
Bytes | 0 . 1 . 2 . 3 . 4 | 5 ... | ... | ... | ... |
+-------------------+------------+------------+-----+------------+
Part | timestamp | response 1 | response 2 | ... | response n |
Structure of a response part on port 3:
Bytes | 0 | 1 .. len-3 | len-2 . len-1 | len |
+-----+-----------------+----------------+-------+
Field | len | Modbus response | start register | count |
COMPACT PAYLOAD FORMAT
The compact payload format transmits only the payload bytes of the received responses. This format requires less bytes to upload the information than the verbose payload format, allowing more data to be read out per hour, but it requires a customised backend that knows the exact configuration of the Bridge. This format only makes sense for reading registers/coils. Error conditions can not be communicated very well using this format.
For PlFmt
=2
the data messages are uploaded on port 6. The messages start with a 5 byte timestamp (same as in verbose payload format). The timestamp is followed by only the payload bytes of the Modbus Responses triggerd by the configuration parameter MbCmd
. The bytes are just appended to the message after another, in the order of the Commands in MbCmd
. You will need to know the exact value of MbCmd
of each of your Bridges to make sense of the data. When using this payload format the Remote Configuration is very helpful: it can be used to read the value of configuration parameters over LoRaWAN without physical access to the device (it can also change those values). If a Modbus command fails to execute (for example if the Slave device has a power outage or if the bus is disconnected), the data bytes of that command are all set to 0xff
. This could also be a valid value (depending on the nature of your data), but there is no other channel to communicate failure. 0xff
is easy to spot and 0xffff
is relative unlikely to be a real value for Modbus registers.
When using the Bridge with PlFmt
=3
data messages are uploaded on port 7. The payload format is identical to the payload format for PlFmt
=3
only without the timestamp (to save another 5 bytes in case you do not care about the time of your readings).
Split messages
LoRaWAN has a very limited message size. For high spreading factors this goes as low as 51 bytes. If a Modbus Response is too long to fit into a single message, the Modbus Bridge will split it up into multiple messages that are sent in sequence. Patching messages back together requires a more complex backend that can save a state. A simple parse on The Things Network will not be able to do that. If your backend cannot handle this process, you can work around it by configuring your MbCmd
in a way that no single response will be longer than 45 bytes (by reading out a maximum of 24 consecutive registers in a single command). If you have a configuration that results in longer Responses you should make sure your backend can handle split Responses as described here.
If a Response is too long to fit into a single message, the Bridge puts as many bytes as possible into the message. You can tell by the length of the message and the length of the Modbus Response indicated in the message, that this is only the first part of a message. This first part will be upload normally on port 3 (or port 4, if triggered by a downlink). Following the first part, the Bridge will upload the remaining data in messages sent on port 5. For very long Responses and high Spreading Factors, the Response could be split into up to 6 messages. You can use the frame counter and the indicated length to verify if you receive all parts.
Warning
Remaining data is not send on port 5 as documented above, but on port 3.
Modbus Responses that are split up will never be packed together with other Responses. The Examples section contains an illustration of a split up Response.
Downlink
Please be aware that Downlinks in LoRaWAN can only be received when the device sends an Uplink, or when the device operates in Class C mode. See Uplinks and Downlinks in our LoRaWAN page for more information.
Modbus Commands
Downlinks on port 4 contain one or more Modbus Commands that the Bridge should forward to the RS-485 bus. Every Command must be prefixed by a single byte defining the Command's length as uint8
. The Modbus Commands must be sent as raw bytes and without any check digits.
The Responses to the Commands are sent as Uplink messages on port 4. The payload format on port 4 is the same as on port 3 (see Data messages), only that the timestamp indicates the time the downlink was received by the Bridge.
Any byte sequence can transmitted this way and will be forwarded to the bus. If the Bridge does not receive a Response by the addressed Slave Device, it creates an error Response with the exception code 11
"Gateway Target Device Failed to Respond". This only makes sense if the Downlink did contain a Modbus Command, but it will be performed for any sequence of bytes you send. Commands must have a length of at least 3 bytes.
Please be advised that not all Modbus Slave devices send Responses in all cases. If you receive the exception code 11
it is possible that the Slave device was reached but was not addressed correctly. It might even be possible, that a Command was executed successfully, but that the device does not send confirmations. When in doubt, refer to the documentation of your connected devices or try communicating with it directly from your computer or using the Dialog Mode, to reduce possible error sources.
Refer to Examples to see some Downlinks and their answers.
Remote Configuration
The Modbus Bridge supports configuration via LoRaWAN Downlinks. It receives commands on port 128. See Remote Configuration in our LoRaWAN page for instructions on how to use it.
Examples
This chapter illustrates with some examples, how working with the Modbus Bridge looks like. The bytes that are sent via LoRaWAN are presented here as hex strings, while on the air they are sent as raw bytes. Modbus Commands and Responses are broken down to their parts in the explanations, but explaining the format used by Modbus in detail is beyond the scope of this manual. You can find a short explanation on Modbus on Wikipedia: https://en.wikipedia.org/wiki/Modbus.
Uplinks triggered by configuration
The following shows some examples of configuration for the automated reading and what the generated Uplinks for that could look like.
Example A1: Read Holding Registers 0, 1, and 2 of device with address 1
MbCmd = '010300000003'
# Example resulting Uplink after successful readout
Up, Port 3: '005d1698fd0c0103061234567890ab000003'
'005d1698fd' -> timestamp = 1561762045 -> 2019-06-28T22:47:25 UTC
'0c' -> first Response is 12 bytes long
'0103061234567890ab000003' 12 bytes modbus response:
'01' -> slave device with address 1
'03' -> function 3 = read Holding Register, success
'06' -> 6 bytes of data in Response following
'1234567890ab' -> 6 bytes of data
'0000' -> start reading at register 0
'03' -> read 3 consecutive registers
# Example resulting Uplink after failing readout
Up, Port 3: '005d1698fd0601830b000003'
'005d1698fd' -> timestamp = 1561762045 -> 2019-06-28T22:47:25 UTC
'06' -> first Response is 6 bytes long
'01830b000003' 3 bytes modbus response:
'01' -> slave device with address 1
'83' -> function 3 with error indicator 80 = read Holding Register, failed
'0b' -> error code 11: "Gateway Target Device Failed to Respond"
'0000' -> start reading at register 0
'03' -> read 3 consecutive registers
Example A2: Read coils 1000-1019 of device 32
MbCmd = '200103e80014'
# Example resulting Uplink
Up, Port 3: '005d1698fd 09 200103f1041a03e814'
'005d1698fd' -> timestamp = 1561762045 -> 2019-06-28T22:47:25 UTC
'09' -> first Response is 9 bytes long
'200103f1041a03e814' 9 bytes of response:
'20' -> slave device with address 32
'01' -> read coils, success
'03' -> 3 bytes of data
'f1041a' -> 20 bits of data packed into 3 bytes
'03e8' -> start reading at coil 1000
'14' -> read 20 consecutive coils
Example A3: Read two devices
MbCmd = '0a0300010005,3001ea600020'
# Example resulting Uplink
Up, Port 3: '005d1698fd100a030a111122223333444455550001050a30010412345678ea6020'
'005d1698fd' -> timestamp = 1561762045 -> 2019-06-28T22:47:25 UTC
'10' -> first Response is 16 bytes long
'0a030a11112222333344445555000105' 16 bytes of Response
'0a' -> slave device with address 10
'03' -> read Holding Registers, success
'0a' -> 10 bytes of data following
'11112222333344445555' 10 bytes of data
'0001' -> start reading at register 1
'05' -> read 5 registers
'0a' -> second Response is 10 bytes long
'30010412345678ea6020' 10 bytes of Response
'30' -> slave device with address 48
'01' -> read Coils, success
'04' -> 4 bytes of data following
'12345678' -> 32 bits of data packed in 4 bytes
'ea60' -> start at coil 60000
'20' -> read 32 coils
Example A4: Split up messages
MbCmd = '010300010020'
# Command reads 32 consecutive registers resulting in 64 bytes payload
# Example resulting Uplinks for a Spreading Factor of 12 with 51 bytes of payload per message
Up 1, Port 3: '005d1698fd46010340000100020003000400050006000700080009000a000b000c000d000e000f001000110012001300140015'
'005d1698fd' -> timestamp = 1561762045 -> 2019-06-28T22:47:25 UTC
'46' -> first Response is 70 bytes long
since the remainder of the message does not contain 70 bytes, you know there must be an additional part comming
Up 2, Port 5: '0016001700180019001a001b001c001d001e001f00200120'
This contains the rest of the message. Appended to the privious message, it adds up to the correct number of bytes.
TODO: examples for compact payload format
All this examples use the verbose payload format. We need to add examples using the compact format.
Uplinks triggered by Downlink Commands
Example B1: Read single Input Register by Downlink
Down, Port 4: '06180401000001'
'06' -> first Command is 6 bytes long
'180401000001' 6 bytes of Modbus Command
'18' -> slave device with address 24
'04' -> function 4, read Input Register
'0100' -> start at register 256
'0001' -> read 1 register
# Example resulting Uplink
Up, Port4: '004b3dd67508180402abcd010001'
'004b3dd675' -> timestamp = 1262343797 -> 2010-01-01T11:03:17 UTC
'08' -> first Response is 8 bytes long
'180404abcd010001' 8 bytes of Response
'18' -> slave device with address 24
'04' -> read Input Register, success
'02' -> 2 bytes of data following
'abcd' -> 2 bytes of data
'0100' -> start at register 256
'01' -> read 1 register
Example B2: Writing holding registers on multiple devices
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...