Closed 3735943886 closed 10 months ago
Several tests were done, including a forced reboot of the AP. Following the reboot, the Device.receive()
function returned an error Check device key or version
. Tinytuya does not seem to automatically recover its connection, indicating that reconnection codes may need to be added when an error message is received from Device.receive()
.
Commands were sent from outside of the loop using an already created tinytuya.Device
object to a waiting device in a loop via Device.receive()
. The Device.receive()
function inside the loop was able to receive the dps signal without any issues. However, the efficacy of this approach remains uncertain.
Any comments or guidances are welcome. Thank you.
Hi @3735943886 !
TinyTuya does automatically reconnect. Devices can sometimes take a while to re-connect to the WiFi, so if you get that error you can just wait a bit and retry the send/receive. Occasionally some devices will "forget" their local key and need to be power cycled before you can connect to them again.
Yes, it's perfectly fine to use one Device object with 2 threads like that. Just make sure to set nowait=True
in the sending calls to keep the sending thread from trying to receive as well.
Hi @3735943886 !
- TinyTuya does automatically reconnect. Devices can sometimes take a while to re-connect to the WiFi, so if you get that error you can just wait a bit and retry the send/receive. Occasionally some devices will "forget" their local key and need to be power cycled before you can connect to them again.
- Yes, it's perfectly fine to use one Device object with 2 threads like that. Just make sure to set
nowait=True
in the sending calls to keep the sending thread from trying to receive as well.
Thank you for your kind answer.
I'll control tuya devices with tinytuya. The code will be structured into Monitor and Control sections. There are two points of interest:
Device.receive()
, and an external sensor triggers the on/off control of this switch, how should this be handled? Should another connection be made to control this switch? Or can the already createdtinytuya.Device
object for monitoring be used to send control from outside of the loop while waiting forDevice.receive()
?Thank you.