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: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