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

Unexpected Payload from Device error 904, but working? #472

Open
vvmichielvv opened this issue Mar 13, 2024 · 5 comments
Open

Unexpected Payload from Device error 904, but working? #472

vvmichielvv opened this issue Mar 13, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@vvmichielvv
Copy link

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

@uzlonewolf
Copy link
Collaborator

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

@vvmichielvv
Copy link
Author

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}]

@uzlonewolf
Copy link
Collaborator

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?

@vvmichielvv
Copy link
Author

vvmichielvv commented Mar 14, 2024

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).

@uzlonewolf uzlonewolf added the bug Something isn't working label Mar 15, 2024
@uzlonewolf
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants