tjhowse / modbus4mqtt

Modbus TCP <-> MQTT glue. YAML configuration. Robust.
Other
75 stars 33 forks source link

Scan batching misbehaves with modbus address zero/one issue. #28

Open tjhowse opened 3 years ago

tjhowse commented 3 years ago

Minimal config:

ip: 192.168.1.89
port: 502
update_rate: 5
address_offset: 0
variant: sungrow
scan_batching: 100
registers:
  - pub_topic: "inverter_model"
    address: 4999
    table: input

Fails: 2021-01-13 20:51:28 ERROR Failed to read 100 input table registers starting from 4900: Modbus Error: [Input/Output] No Response received from the remoteunit/Unable to decode response

This is due to the long-ignored issue of modbus4mqtt addresses starting from zero, but actual modbus addresses starting from 1. When the yaml specifies address 4999 we're actually reading address 5000 from modbus' perspective. This means when we try to batch reads on 100-register-aligned boundaries we send a request for address 4900 (4901) which is invalid.

We should fix the addresses in the example YAMLs and teach the modbus interface to account for the zero/one problem.