The firmware implements a simple MODBUS RTU master mode. You can read holding and input registers and write to holding registers. The example below reads two values from one device from different memory addresses.
Note: If your MODBUS device uses the RS485 or RS232 interface, you need the corresponding converter from UART (TTL) to RS232 or UART (TTL) to RS485. UART uses P02 and P03 pins (3.3V). Therefore you should use the P02 pin in the configuration.
The MODBUS sensor mode supports several common data types with the “Little-Endian” and “Big-endian” byte order (wiki).
- UART – UART communication parameters. The list contains all possible supported combinations of a baud rate, a number of data bits, parity, stop bits.
- Device address (decimal) – it is the MODBUS address of a connected MODBUS device.
- Function – you can select the MODBUS function number for input and holding registers.
- Memory offset (decimal) – it is a zero-based memory offset in your MODBUS device. If your address looks like 40001, it may mean the holding register with the memory offset 0. Or 30002 – the input register with offset 1.
- Data type – it is a data type of a value in MODBUS memory. Some data types occupy two MODBUS registers. The firmware converts all received values to a single-precision float number (32 bit).
- The number of values – this number defines how much data the firmware reads from MODBUS memory. The firmware automatically calculates the necessary number of registers uses this number and the data type. If you configured the reading of multiple values, the firmware outputs all data to one endpoint (channel) but adds a value index to a description.
Writing MODBUS data
The firmware accepts the “write” command from a coordinator on a configured output and can write a single value back to a MODBUS device.
The firmware automatically converts a source value to a target data type and uses the “Write single register” (0x06) or “Write multiple registers” (0x10) MODBUS commands.
write - writes a value to a MODBUS device. Topic: zigbee2mqtt/[friedly_name]/set Payload: {"[channel]": [value]} Channel: l1, l2, l3 β¦ l16 Value: any valid float value.
Esa
Hi!
MODBUS is half-duplex protocol and RS485/422 transceiver ICs have (a) RE/DE -pin(s) to switch from sending to receiving. How do I configure that to the firmware?
Thank you!
Owner
For RS485 you need an external converter. It will convert a hardware layer to UART.
Christian
Hi!
Nice piece of software you got here.
Any advise for the Modbus function – i.e. software to handle the data read from a Modbus RTU device?
Something in the deCONZ ballpark, or anything else?
Thanks in advance!
Owner
The firmware supports two major function codes (3 and 4) to read input and holding registers.
Christian
Yes, as the documentation states π
However, on the server side, after zigbee, do you have any recommendation for software, as it doesn’t seem like most of the softwares out there, can handle other than switches, and the occassional temp-sensor.
Owner
I can only recommend zigbee2mqtt + homeassistant where you can add a custom converter for any DIY device.
Paul
Would it be possible to support a Modbus client mode? I’ve implemented a simple energy meter dummy for my heat pump to inject solar production data into the heating control unit. There exist also OSS modus slave implementation that would only require UART comm adjustments: https://github.com/emelianov/modbus-esp8266
My longterm goal would be to gradually replace all WiFi based ESP2866 IoT devices.
Owner
Sorry, but I’m uncertain if this feature widely used :).
kds
Hi,
Thanks for all your great job which I have sponsored a couple of times, very much deserved.
RS232 and RS485 are mentioned to require TTL converter and mandatory use of P02.
What about RS422?
I have a mix of RS485 and RS422 devices, so I am wondering if I can connect RS422 to another port in a way or another. I canβt see how it would be different and not require TTL convert as well, but just asking
Owner
Hi, RS422 requires a UART TTL converter too. The firmware supports only one UART interface. Yes, the UART pin is hardcoded to P02 for CC253x.
kds
Thanks.
Is the writing function still available? (I’m confused with today’s new firmware features list = “Simple MODBUS master implementation…”)
Reading went smoothly on 03-registers but no way to write (0x06) anything.
Tell me writing functionality is still there… please π
Owner
Sorry, but the firmware can only read MODBUS data.
kds
I figured-out that the port P02 can still be used directly as UART despeite MODBUS config in firmware because “action” command can be used to pass simple modbus commands.
Though not perfect, very instrumental to have simple UART available together with modbus read. If you could leave it as is that would allow probably quite some modbus projects with ptvo that supposes writing commands.
Would you need little help on your firmware to implement write function (for free)? Not sure if I am competent but, it’s an offer.
Owner
Sorry, but the ‘write’ command is rarely used, and I do not plan to implement it.