Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ModbusBridge request/response logic #22075

Merged

Conversation

dwrobel
Copy link
Contributor

@dwrobel dwrobel commented Sep 2, 2024

  • Fix cases where the subsequent Modbus packet   can be send to the serial port (triggered either by   'ModbusSend' command or request from TCP bridge)   before an answer was received to the previous packet.

  This can happen in a setup where simultaneously:   - two (or more) modbus TCP clients are sending requests
through the modbus-proxy [1] to Tasmota,
  - ModbusSend commands are executed (e.g. using Berry).

  Log excerpt (from build with TASMOTAMODBUSDEBUG enabled):   14:51:18.940 MBS: Serial Send: 04 03 01 00 00 09 84 65   14:51:19.054 MBS: Serial Send: 04 03 10 0A 00 05 A1 5E   14:51:19.136 MBS: Serial Received: 04 03 0A 00 00 00 D0 00 00 01 AB 00 00 89 62

  Fix adds 'waitingForAnswerFromSerial' flag which is set after   we send data to the serial port and prevents sending another   requests before we receive an answer or timeout happened.

Fix stores temporarily a 'ModbusSend' command data and tries
to execute it after Modbus response has been received or
timeout has happened.

  • Add 'ModbusSerialTimeout' command which sets timeout in [ms] for how long we will be waiting for an answer from the client device.   Default value is 1000 [ms] and it is not restored after reboot.

  • Sends error 11 (0xB) (as TCP response) when no answer was received   from the serial port within the timeout set by 'ModbusSerialTimeout'
    command.

  • Add Modbus 'TransactionId' to the logging.

[1] https://github.com/tiagocoutinho/modbus-proxy

Description:

Related issue (if applicable): fixes #

Checklist:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.7
  • The code change is tested and works with Tasmota core ESP32 V.3.0.4
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

@dwrobel dwrobel force-pushed the Fix-ModbusBridge-request-response-logic branch from a51ffca to 407d341 Compare September 2, 2024 16:15
- Fix cases where the subsequent Modbus packet
  can be send to the serial port (triggered either by
  'ModbusSend' command or request from TCP bridge)
  before an answer was received to the previous packet.

  This can happen in a setup where simultaneously:
  - two (or more) modbus TCP clients are sending requests
    through the modbus-proxy [1] to Tasmota,
  - ModbusSend commands are executed (e.g. using Berry).

  Log excerpt (from build with TASMOTAMODBUSDEBUG enabled):
  14:51:18.940 MBS: Serial Send: 04 03 01 00 00 09 84 65
  14:51:19.054 MBS: Serial Send: 04 03 10 0A 00 05 A1 5E
  14:51:19.136 MBS: Serial Received: 04 03 0A 00 00 00 D0 00 00 01 AB 00 00 89 62

  Fix adds 'waitingForAnswerFromSerial' flag which is set after
  we send data to the serial port and prevents sending another
  requests before we receive an answer or timeout happened.

  Fix stores temporarily a 'ModbusSend' command data and tries
  to execute it after Modbus response has been received or
  timeout has happened.

- Add 'ModbusSerialTimeout' command which sets timeout in [ms]
  for how long we will be waiting for an answer from the client device.
  Default value is 1000 [ms] and it is not restored after reboot.

- Sends error 11 (0xB) (as TCP response) when no answer was received
  from the serial port within the timeout set by 'ModbusSerialTimeout'
  command.

- Add Modbus 'TransactionId' to the logging.

[1] https://github.com/tiagocoutinho/modbus-proxy

Signed-off-by: Damian Wrobel <[email protected]>
@dwrobel dwrobel force-pushed the Fix-ModbusBridge-request-response-logic branch from 407d341 to b09edbd Compare September 2, 2024 16:32
@arendst arendst merged commit 6650dee into arendst:development Sep 9, 2024
59 checks passed
hawa-lc4 pushed a commit to hawa-lc4/Tasmota-dev that referenced this pull request Sep 16, 2024
- Fix cases where the subsequent Modbus packet
  can be send to the serial port (triggered either by
  'ModbusSend' command or request from TCP bridge)
  before an answer was received to the previous packet.

  This can happen in a setup where simultaneously:
  - two (or more) modbus TCP clients are sending requests
    through the modbus-proxy [1] to Tasmota,
  - ModbusSend commands are executed (e.g. using Berry).

  Log excerpt (from build with TASMOTAMODBUSDEBUG enabled):
  14:51:18.940 MBS: Serial Send: 04 03 01 00 00 09 84 65
  14:51:19.054 MBS: Serial Send: 04 03 10 0A 00 05 A1 5E
  14:51:19.136 MBS: Serial Received: 04 03 0A 00 00 00 D0 00 00 01 AB 00 00 89 62

  Fix adds 'waitingForAnswerFromSerial' flag which is set after
  we send data to the serial port and prevents sending another
  requests before we receive an answer or timeout happened.

  Fix stores temporarily a 'ModbusSend' command data and tries
  to execute it after Modbus response has been received or
  timeout has happened.

- Add 'ModbusSerialTimeout' command which sets timeout in [ms]
  for how long we will be waiting for an answer from the client device.
  Default value is 1000 [ms] and it is not restored after reboot.

- Sends error 11 (0xB) (as TCP response) when no answer was received
  from the serial port within the timeout set by 'ModbusSerialTimeout'
  command.

- Add Modbus 'TransactionId' to the logging.

[1] https://github.com/tiagocoutinho/modbus-proxy

Signed-off-by: Damian Wrobel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants