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 TUYA state machine (in TUYA v1) #20110

Merged
merged 5 commits into from
Dec 8, 2023

Conversation

barbudor
Copy link
Contributor

@barbudor barbudor commented Nov 26, 2023

Description:

Related issue (if applicable): fixes #20086

The TuyaSerialInput reception was resetting the state machine with any incoming 0x55 byte even in the data.
This PR rework the state machine with a simpler and more robust one.

The original issue reporter has validated the PR but it would be great to get more testers
I only tested against simulator

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.4.9
  • The code change is tested and works with Tasmota core ESP32 V.2.0.14
  • I accept the CLA.

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

@barbudor barbudor marked this pull request as ready for review November 29, 2023 21:18
@barbudor
Copy link
Contributor Author

@blakadder The original reporter of the issue has validated the change but it would be great if you could also do some tests on real hardware as I only tested against simulator
Thanks

or anyone having Tuya devices...

@benjaminnestler
Copy link
Contributor

Hi @barbudor
I've checked your fix with my Tuya devices (ESP32 and ESP8266 based). The fix looks quite good!

I tried the current development branch, with an additional LOG in the TuyaSerialInput if 0x55 is received and the state machine is reseted. I set a datapoint value to 0x55. After restarting the tuya device this data point (with 0x55) value couldn't be decoded.

You can see it in the following LOG. Between the datapoint 148 and 149, the device sends another datapoint which couldn't be decoded, because this is the datapoint for which I changed the value to 0x55

2023-12-08 10:38:50.985 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-TYA: 0x55 received!!!!! Reset TuyaSerialInput State machine
2023-12-08 10:38:50.986 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-MQT: tasmota/things/8f6aadd6-72c3-46a8-8bdd-3ff9b985c8fe/tele/RESULT = {"TuyaReceived":{"Data":"55AA030700059404000100A7","Cmnd":7,"CmndData":"9404000100","DpType4Id148":0,"148":{"DpId":148,"DpIdType":4,"DpIdData":"00"}}}
2023-12-08 10:38:50.987 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-TYA: fnId=0 is set for dpId=148
2023-12-08 10:38:50.990 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-TYA: 0x55 received!!!!! Reset TuyaSerialInput State machine
2023-12-08 10:38:50.991 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-TYA: 0x55 received!!!!! Reset TuyaSerialInput State machine
2023-12-08 10:38:51.991 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-TYA: 0x55 received!!!!! Reset TuyaSerialInput State machine
2023-12-08 10:38:51.992 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-MQT: tasmota/things/8f6aadd6-72c3-46a8-8bdd-3ff9b985c8fe/tele/RESULT = {"TuyaReceived":{"Data":"55AA030700059504000100A8","Cmnd":7,"CmndData":"9504000100","DpType4Id149":0,"149":{"DpId":149,"DpIdType":4,"DpIdData":"00"}}}
2023-12-08 10:38:51.994 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-TYA: fnId=0 is set for dpId=149

Test again with the build of your branch. The LOG output looks good! The datapoint with id 37 will be decoded now (you can see the 0x55 in one of the first payload data!

2023-12-08 10:42:42.015 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-DMP: 55 AA 03 07 00 05 94 04 00 01 00 A7
2023-12-08 10:42:42.015 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-MQT: tasmota/things/8f6aadd6-72c3-46a8-8bdd-3ff9b985c8fe/tele/RESULT = {"TuyaReceived":{"Data":"55AA030700059404000100A7","Cmnd":7,"CmndData":"9404000100","DpType4Id148":0,"148":{"DpId":148,"DpIdType":4,"DpIdData":"00"}}}
2023-12-08 10:42:42.018 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-TYA: fnId=0 is set for dpId=148
2023-12-08 10:42:42.071 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-DMP: 55 AA 03 07 00 AC 25 00 00 A8 06 00 00 55 08 00 00 BE 0B 1E 00 BE 0D 1E 00 BE 0F 00 00 D2 16 00 00 BE 06 00 00 D2 08 00 00 BE 0B 1E 00 BE 0D 1E 00 BE 0F 00 00 D2 16 00 00 BE 06 00 00 D2 08 00 00 BE 0B 1E 00 BE 0D 1E 00 BE 0F 00 00 D2 16 00 00 BE 06 00 00 D2 08 00 00 BE 0B 1E 00 BE 0D 1E 00 BE 0F 00 00 D2 16 00 00 BE 06 00 00 D2 08 00 00 BE 0B 1E 00 BE 0D 1E 00 BE 0F 00 00 D2 16 00 00 BE 06 00 00 BE 08 00 00 D2 0B 1E 00 D2 0D 1E 00 D2 0F 00 00 D2 16 00 00 BE 06 00 00 BE 08 00 00 D2 0B 1E 00 D2 0D 1E 00 D2 0F 00 00 D2 16 00 00 BE 4A
2023-12-08 10:42:42.074 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-MQT: tasmota/things/8f6aadd6-72c3-46a8-8bdd-3ff9b985c8fe/tele/RESULT = {"TuyaReceived":{"Data":"55AA030700AC250000A806000055080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000BE080000D20B1E00D20D1E00D20F0000D2160000BE060000BE080000D20B1E00D20D1E00D20F0000D2160000BE4A","Cmnd":7,"CmndData":"250000A806000055080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000BE080000D20B1E00D20D1E00D20F0000D2160000BE060000BE080000D20B1E00D20D1E00D20F0000D2160000BE","DpType0Id37":"0x06000055080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000BE080000D20B1E00D20D1E00D20F0000D2160000BE060000BE080000D20B1E00D20D1E00D20F0000D2160000BE","37":{"DpId":37,"DpIdType":0,"DpIdData":"06000055080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E00BE0F0000D2160000BE060000D2080000BE0B1E00BE0D1E
2023-12-08 10:42:42.075 - 192.168.178.36: 00BE0F0000D2160000BE060000BE080000D20B1E00D20D1E00D20F0000D2160000BE060000BE080000D20B1E00D20D1E00D20F0000D2160000BE"}}}
2023-12-08 10:42:42.075 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-TYA: fnId=0 is set for dpId=37
2023-12-08 10:42:43.096 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-DMP: 55 AA 03 07 00 05 95 04 00 01 00 A8
2023-12-08 10:42:43.098 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-MQT: tasmota/things/8f6aadd6-72c3-46a8-8bdd-3ff9b985c8fe/tele/RESULT = {"TuyaReceived":{"Data":"55AA030700059504000100A8","Cmnd":7,"CmndData":"9504000100","DpType4Id149":0,"149":{"DpId":149,"DpIdType":4,"DpIdData":"00"}}}
2023-12-08 10:42:43.100 - 192.168.178.36: ASW-Dir-Mat-0796 ESP-TYA: fnId=0 is set for dpId=149

@barbudor
Copy link
Contributor Author

barbudor commented Dec 8, 2023

Thanks a lot @benjaminnestler for testing and reviewing

@arendst Unless we find another tester, that sounds good

Thanks

@arendst arendst merged commit 73268e4 into arendst:development Dec 8, 2023
64 checks passed
@arendst
Copy link
Owner

arendst commented Dec 8, 2023

Thx both.

@barbudor barbudor deleted the fix-tyua-state-machine branch December 16, 2023 22:19
hawa-lc4 pushed a commit to hawa-lc4/Tasmota-dev that referenced this pull request Jan 20, 2024
* rework state machine

* some comments

* wip

* looks good now

* little updates
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.

3 participants