tinytuya icon indicating copy to clipboard operation
tinytuya copied to clipboard

Unexpected Payload from Device error 904, but working?

Open vvmichielvv opened this issue 1 year ago • 5 comments

All,

Getting further into refining everything at home, I bump into the 'Unexpected Payload from Device' error. Strange thing is that I can communicate with it (fe. switching the device on), but when listening for an update (to monitor any changes on the device itself) it errors like this. I also noticed that it is with devices I bought pretty recent. Some that error are v3.3, newest are v3.4.

In all cases, the keys have special characters in them, but again, work fine when trying to switch something. So it seems the key is correct.

Any ideas?

Regards, Michiel

vvmichielvv avatar Mar 13 '24 18:03 vvmichielvv

Can you enable debug logging (tinytuya.set_debug(True)) and post the log when it does this?

uzlonewolf avatar Mar 13 '24 18:03 uzlonewolf

Hi!

I get the following debug:

DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 0/5
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1193, in _send_receive
    rmsg = self._receive()
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1081, in _receive
    data = self._recv_all( min_len )
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1061, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 1/5
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1193, in _send_receive
    rmsg = self._receive()
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1081, in _receive
    data = self._recv_all( min_len )
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1061, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 2/5
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1193, in _send_receive
    rmsg = self._receive()
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1081, in _receive
    data = self._recv_all( min_len )
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1061, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 3/5
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1193, in _send_receive
    rmsg = self._receive()
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1081, in _receive
    data = self._recv_all( min_len )
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1061, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 4/5
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1193, in _send_receive
    rmsg = self._receive()
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1081, in _receive
    data = self._recv_all( min_len )
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1061, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:_recv_all(): no data? b''
DEBUG:_recv_all(): no data? b''
DEBUG:Error decoding received data - read retry 5/5
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1193, in _send_receive
    rmsg = self._receive()
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1081, in _receive
    data = self._recv_all( min_len )
  File "/usr/local/lib/python3.8/dist-packages/tinytuya/core.py", line 1061, in _recv_all
    raise DecodeError('No data received - connection closed?')
tinytuya.core.DecodeError: No data received - connection closed?
DEBUG:ERROR Unexpected Payload from Device - 904 - payload: null
[TUYA]-[2024-03-13 19:38:34]-[Tuya_Lagekast: {'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None}]
INFO:[TUYA]-[2024-03-13 19:38:34]-[Tuya_Lagekast: {'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None}]

vvmichielvv avatar Mar 13 '24 18:03 vvmichielvv

It looks like you are sending a command but not getting a response. What command are you sending, and how are you listening for updates?

uzlonewolf avatar Mar 13 '24 21:03 uzlonewolf

Simplifying my code:

self.tuya_device = tinytuya.OutletDevice(_devId, _ip, _key)
self.tuya_device.set_version(_version)
self.tuya_device.set_socketPersistent(True)
self.tuya_device.set_socketTimeout(60) 

payload = self.tuya_device.generate_payload(tinytuya.DP_QUERY)
self.tuya_device.send(payload)

while(True):
	data = self.tuya_device.receive()
	
	if str(data) != "" and str(data) != "None":
		# do something with the data
	else :  
		payload = self.tuya_device.generate_payload(tinytuya.HEART_BEAT)
		self.tuya_device.send(payload)

The above initializes the Outletdevice, send a DP_QUERY one time, and then sends HEART_BEAT in a loop, checking each time if there is something to receive (i.e. someone has physically changed a dimmer with a wall control).

vvmichielvv avatar Mar 14 '24 16:03 vvmichielvv

Okay, I see what's going on. I agree, a receive-only call that does not send anything should not raise an error if nothing is received. I'll try to get this fixed soon.

uzlonewolf avatar Mar 15 '24 02:03 uzlonewolf