home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.81k stars 30.51k forks source link

Modbus issue with raw data readings wrong #38588

Closed Ronoon closed 4 years ago

Ronoon commented 4 years ago

The problem

The readings in the log are not correct cause in the responding answer is first answer byte is set to the last position. This is what it should look like image

and this is the log provided by Hassio log for modbus.py 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.transaction] Current transaction state - TRANSACTION_COMPLETE 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.transaction] Running transaction 537 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.transaction] SEND: 0x1 0x4 0x0 0x0 0x0 0x1 0x31 0xca 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.framer.rtu_framer] Changing state to IDLE - Last Frame End - 1596698840.671388, Current Time stamp - 1596698870.639631 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.client.sync] New Transaction state 'SENDING' 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.transaction] Changing transaction state from 'SENDING' to 'WAITING FOR REPLY' 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.transaction] Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY' 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.transaction] RECV: 0x4 0x2 0x1 0x1 0x79 0x60 0x1 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.framer.rtu_framer] CRC invalid, discarding header!! 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.framer.rtu_framer] Resetting frame - Current Frame in buffer - 0x4 0x2 0x1 0x1 0x79 0x60 0x1 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.framer.rtu_framer] Frame check failed, ignoring!! 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.framer.rtu_framer] Resetting frame - Current Frame in buffer - 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.transaction] Getting transaction 1 2020-08-06 09:27:50 DEBUG (SyncWorker_6) [pymodbus.transaction] Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE' 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.transaction] Current transaction state - TRANSACTION_COMPLETE 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.transaction] Running transaction 538 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.transaction] SEND: 0x1 0x4 0x0 0x1 0x0 0x1 0x60 0xa 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.framer.rtu_framer] Changing state to IDLE - Last Frame End - 1596698870.652209, Current Time stamp - 1596698870.659502 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.client.sync] New Transaction state 'SENDING' 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.transaction] Changing transaction state from 'SENDING' to 'WAITING FOR REPLY' 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.transaction] Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY' 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.transaction] RECV: 0x4 0x2 0x2 0x6d 0x79 0xbd 0x1 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.framer.rtu_framer] CRC invalid, discarding header!! 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.framer.rtu_framer] Resetting frame - Current Frame in buffer - 0x4 0x2 0x2 0x6d 0x79 0xbd 0x1 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.framer.rtu_framer] Frame check failed, ignoring!! 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.framer.rtu_framer] Resetting frame - Current Frame in buffer - 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.transaction] Getting transaction 1 2020-08-06 09:27:50 DEBUG (SyncWorker_3) [pymodbus.transaction] Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'

As you can see, the first answer is okay with the right bytes e.g. 01 04 02 etc. the second answer put the first byte to the last position, so the answer is starting with 04 02 .... 01

Seems there is a mixup in the framer or whereever

Environment

image image image

Problem-relevant configuration.yaml

image

Traceback/Error logs

Additional information

Also it is changing the output to the wrong place eg. the temperature is provided with the humidity and otherwise the same. The output looks like these:

image

Also it looks like it is not stable as it should be as it is shown in the datalos at night and then the changing to the correct data again without any changes in the system.

probot-home-assistant[bot] commented 4 years ago

Hey there @adamchengtkc, @janiversen, mind taking a look at this issue as its been labeled with an integration (modbus) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

janiversen commented 4 years ago

The log comes from pymodbus, so if that does something wrong you need to open an issue in that project.

Looking at the log, your configuration/device seems to have several problems: [pymodbus.transaction] RECV: 0x4 0x2 0x1 0x1 0x79 0x60 0x1 [pymodbus.framer.rtu_framer] CRC invalid, discarding header!! [pymodbus.framer.rtu_framer] Resetting frame - Current Frame in buffer - 0x4 0x2 0x1 0x1 0x79 0x60 0x1 [pymodbus.framer.rtu_framer] Frame check failed, ignoring!!

Please close this issue, and when you file an issue with pymodbus open a new issue with a reference to that, so we can see when it is time to update pymodbus.

janiversen commented 4 years ago

I am just wondering are you sure "rtuovertcp" is the correct framer, and not tcp directly ?

"rtuovertcp" are nearly exclusively used by multiplexers that have multiple rs485 connecting to devices and tcp/ip connecting upwards.

Ronoon commented 4 years ago

To answer your latest question:

1.8.2020 R444A01 Digital display RS485 Modbus RTU temperature and humidity sensor indoor and outdoor room computer room farm AM232 .. Product Description Shipping list Built-in sensor: 1 R444A01_A digital display RS485 temperature and humidity sensor (with simple case) External sensor: 1 R444A01_B digital display RS485 temperature and humidity sensor+ external sensor Function description: Supply voltage: DC 5-40V (recommended 6.5-28V) Working current: digital tube display 18MA (12V), digital tube off 5MA (12V) MODBUS RTU protocol, 03 read command, 06 write command. Serial port baud rate: 9600 (default), N, 8, 1 By modifying the 485 address, up to 247 modules can be cascaded (more than 16 please use R485 repeater) Adopt AM2320 temperature and humidity sensor Dimensions: module 59 X 30 X 18MM, housing: 73X 37 X 23MM, external sensor: 60 X 26 X 13MM Weight 16 grams of module, 16 grams of outer casing, 16 grams of external sensor

it is a modbus RTU sensor so to read the sensor over a tcp/ip interface you have to read the data as modbus/rtu over tcp/ip same as reading them over the serial port