Comments (7)
I don't have a Tuya sensor to help you troubleshoot. What device did you get?
The tinytuya or tuyapower scan functions should decrypt the UDP payload:
python -m tinytuya
Do you see the sensor in that list? If so, grab the Device ID and IP address. You can get the LOCAL KEY via the method described here: https://github.com/jasonacox/tinytuya#get-the-tuya-device-local-key
In case it helps, the data points (DPS) mapping for the sensor should be here: https://github.com/jasonacox/tinytuya#version-33---sensor-type
I suspect sensors may not respond to polling, but if it does, you could try something like:
import tinytuya
deviceID = "xxxxxxxx"
ipAddress = "xxxxxxxx"
localKey = "xxxxxxxx"
d = tinytuya.OutletDevice(deviceID, ipAddress, local_key)
d.set_version(3.3)
data = d.status()
print('Response from Sensor: %r' % data)
If that doesn't work, we would need to decrypt the UDP payload. It would be something similar to how we decode the response payload (see https://github.com/jasonacox/tinytuya/blob/master/tinytuya/__init__.py)
log.debug('status received data=%r', data)
result = data[20:-8] # hard coded offsets
if self.dev_type != 'default':
result = result[15:]
log.debug('result=%r', result)
if result.startswith(b'{'):
# this is the regular expected code path
if not isinstance(result, str):
result = result.decode()
result = json.loads(result)
elif result.startswith(PROTOCOL_VERSION_BYTES_31):
# got an encrypted payload
# expect resulting json to look similar to:: {"devId":"ID","dps":{"1":true,"2":0},"t":EPOCH_SECS,"s":3_DIGIT_NUM}
result = result[len(PROTOCOL_VERSION_BYTES_31):] # remove version header
result = result[16:] # Remove 16-bytes appears to be MD5 hexdigest of payload
cipher = AESCipher(self.local_key)
result = cipher.decrypt(result)
log.debug('decrypted result=%r', result)
if not isinstance(result, str):
result = result.decode()
result = json.loads(result)
elif self.version == 3.3:
cipher = AESCipher(self.local_key)
result = cipher.decrypt(result, False)
log.debug('decrypted result=%r', result)
if not isinstance(result, str):
result = result.decode()
result = json.loads(result)
else:
log.error('Unexpected status() payload=%r', result)
return result
from tuyapower.
from tuyapower.
from tuyapower.
Hi @grigvlad - Keep in mind that Tuya devices are designed to communicate with the TuyaCloud. Once you add the device to the SmartLife App, it creates a LocalKey that is used to encrypt the data payloads. Without that key you can't read the payloads directly from the App. However, you may be able to use the TuyaCloud to get that information. It requires that you use your credential to get a token to request the data directly. I suggest you check out the developer information on Tuya's website: https://developer.tuya.com/en/docs/iot .
from tuyapower.
from tuyapower.
Thanks Vladi, I would very much like to hear how your research goes.
Looking at the payload you are getting back, I do see the Tuya prefix and suffix:
"prefix": "000055aa00000000000000",
# Next byte is command "hexByte" + length of remaining payload + command + suffix
# (unclear if multiple bytes used for length, zero padding implies could be more
# than one byte)
"suffix": "000000000000aa55"
I don't know the labview equivalent, but a python approach could be:
# data contains the payload
# KEY is the Tuya local key you have
result = data[20:-8] # trim off the first 20 bytes (header) and last 8 (crc?)
cipher = AESCipher(KEY)
result = cipher.decrypt(result, False)
print('decrypted result=%r', result)
from tuyapower.
from tuyapower.
Related Issues (20)
- Response Data: ERROR: Timeout polling device HOT 9
- Missing Power Data HOT 11
- Error running on Mac HOT 8
- ERROR: Incomplete response HOT 1
- Smart Energy Meter HOT 1
- Get info without scanning the network HOT 1
- automate it
- Ledvance smart wifi plug missing power data and pairing issue
- Arlec PC191HA, PC287HA give 0 readings (power, current, but voltage OK) HOT 2
- Can I control switches directly in Python?
- Question: How to access historic power data? HOT 10
- Question: is this tuya python module read only from tuya compatible devices ? HOT 1
- smart energy meter not returning data HOT 4
- Tuya smart plug keeps reseting on multiple queries HOT 6
- `tuya.deviceInfo` hanging if device not available?
- Tuya API change / Missing Power Data HOT 3
- Missing Power Data - again HOT 4
- Gosund SP1 plug doesn't refresh power data without app running HOT 2
- Connexion issue to retrieve power
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tuyapower.