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.

MODBUS

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.

Comments
Harvey Specter
Posted at 07:45 June 19, 2024
Esa
Reply
Author

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!

    Harvey Specter
    Posted at 10:05 June 19, 2024
    Owner
    Reply
    Author

    For RS485 you need an external converter. It will convert a hardware layer to UART.

Harvey Specter
Posted at 19:51 June 23, 2022
Christian
Reply
Author

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!

    Harvey Specter
    Posted at 04:02 June 25, 2022
    Owner
    Reply
    Author

    The firmware supports two major function codes (3 and 4) to read input and holding registers.

      Harvey Specter
      Posted at 11:27 June 25, 2022
      Christian
      Reply
      Author

      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.

        Harvey Specter
        Posted at 11:47 June 25, 2022
        Owner
        Reply
        Author

        I can only recommend zigbee2mqtt + homeassistant where you can add a custom converter for any DIY device.

Harvey Specter
Posted at 07:18 May 20, 2022
Paul
Reply
Author

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.

    Harvey Specter
    Posted at 09:25 May 20, 2022
    Owner
    Reply
    Author

    Sorry, but I’m uncertain if this feature widely used :).

Harvey Specter
Posted at 05:31 January 8, 2022
kds
Reply
Author

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

    Harvey Specter
    Posted at 03:45 January 10, 2022
    Owner
    Reply
    Author

    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.

      Harvey Specter
      Posted at 14:29 January 14, 2022
      kds
      Reply
      Author

      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 πŸ™

        Harvey Specter
        Posted at 06:21 January 16, 2022
        Owner
        Reply
        Author

        Sorry, but the firmware can only read MODBUS data.

          Harvey Specter
          Posted at 09:51 January 16, 2022
          kds
          Author

          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.

          Harvey Specter
          Posted at 08:23 January 19, 2022
          Owner
          Author

          Sorry, but the ‘write’ command is rarely used, and I do not plan to implement it.

Leave a Reply to Owner
Cancel Reply