mathieu-mp / aio-intex-spa

Python client for Intex Spa wifi interface
https://pypi.org/project/aio-intex-spa/
MIT License
17 stars 2 forks source link

Checksum algorithm fails on 0xFF legitimate checksum #27

Closed montgomeryb closed 1 year ago

montgomeryb commented 1 year ago

I have a cron job running that records the temperature and heats overnight. I am consistently getting exceptions thrown for a period because the checksum doesn't match.

I took the output from the exception below and ran it through the checksum as int function and it came back as zero, as you can see the spa returned it as 0xFF. If this is a legitimate issue, I am surprised it hasn't come up before although I am using Farenheit. Calling the function and ignoring the assertion for the assertion for the checksum the status below is reported. The spa I have is an SC-WF10. I tried replicating the issue today with the same settings but was unable to get the code to fail. I have posted the failing bytes returned and the passing bytes returned below:

FFFF110F0107006400000085808085670000FF FFFF110F01070064000000008080806700008A {'power': True, 'filter': True, 'heater': True, 'jets': False, 'bubbles': False, 'sanitizer': False, 'unit': '°F', 'current_temp': 100, 'preset_temp': 103, 'error_code': False}

The bolded section is different, between the preset temperature and current temperature. I tried finding the intex protocol but I'm guessing it is by trial and error.  I'm not sure what is correcting the issue - it may be a scheduled event from the app that causes the temperature to update and a different checksum? The only thing I found about 0 and FF checksums was in relation to UDP https://github.com/pstavirs/ostinato/issues/160 I'm not sure how to work around this as I understand that every command issues a status to begin with? I have tried executing an async_update_info to see if that changes anything. 

Initializing IntexSpa instance...
IntexSpa instance initialized
'status' intent: Handling new intent...
'status' intent: a spa query is needed
'status' intent: new spa query...
Not connected to the spa, trying to connect...
Opening TCP connection with the spa at SPA_DEVICE:8990 with asyncio...
TCP connection established with the spa
Sending bytes to the spa: b'{"data": "8888060FEE0F01DA", "sid": "16877683219221", "type": 1}'
Receiving bytes from the spa: b'{"sid":"16877683219221","data":"FFFF110F0107006400000086808086680000FC","result":"ok","type":2}\n'
'status' intent: new status is rendered
'status' intent: Handling new intent...
'status' intent: a spa query is needed
'status' intent: new spa query...
Sending bytes to the spa: b'{"data": "8888060FEE0F01DA", "sid": "16877683220962", "type": 1}'
Receiving bytes from the spa: b'{"sid":"16877683220962","data":"FFFF110F0107006400000086808086680000FC","result":"ok","type":2}\n'
'status' intent: new status is rendered
'preset_temp' intent: Handling new intent...
'preset_temp' intent: triggering a preliminary 'update' intent...
'status' intent: Handling new intent...
'status' intent: a spa query is needed
'status' intent: new spa query...
Sending bytes to the spa: b'{"data": "8888060FEE0F01DA", "sid": "16877683221893", "type": 1}'
Receiving bytes from the spa: b'{"sid":"16877683221893","data":"FFFF110F0107006400000086808086680000FC","result":"ok","type":2}\n'
'status' intent: new status is rendered
'preset_temp' intent: a spa query is needed
'preset_temp' intent: new spa query...
Sending bytes to the spa: b'{"data": "8888050F0C6767", "sid": "16877683222765", "type": 1}'
Receiving bytes from the spa: b'{"sid":"16877683222765","data":"FFFF110F0107006400000085808085670000FF","result":"ok","type":2}\n'
Malformed spa response during spa querying
'preset_temp' intent: new spa query...
Sending bytes to the spa: b'{"data": "8888050F0C6767", "sid": "16877683247193", "type": 1}'
Receiving bytes from the spa: b'{"sid":"16877683247193","data":"FFFF110F0107006400000085808085670000FF","result":"ok","type":2}\n'
Malformed spa response during spa querying
'preset_temp' intent: new spa query...
Sending bytes to the spa: b'{"data": "8888050F0C6767", "sid": "16877683270894", "type": 1}'
Receiving bytes from the spa: b'{"sid":"16877683270894","data":"FFFF110F0107006400000085808085670000FF","result":"ok","type":2}\n'
Malformed spa response during spa querying
Spa is unreachable
mathieu-mp commented 1 year ago

Great analysis! I'll update the checksum functions.

You were out of luck with that 0xFF checksum: it is a simple addition of the data bits that has 1 in 256 chance on ending up on 0x00.

mathieu-mp commented 1 year ago

Hi @montgomeryb

This shall be fixed with 0.8.4 Release

Please reopen the issue if it is not solved