-
Hi all, What am I trying to achieve? Transfer voltage, power, energy consumed etc measurements from a Tuya-compliant WIFI power meter into an influxdb database for further visualization and analysis. How am I going about it? On a Raspberry Pi, every 10 minutes I run a script that first checks for the latest measurement timestamp already in the influxdb, then calls getdevicelog() with appropriate start and end times. As my power meter is rather talkative, 10 minutes worth of logs is about 1000 records, so it takes ~10 "fetches" to get all the data. What is my problem? Everything works like a charm in general, but every now and then I see 5-10 minute gaps in my measurement sequences. I checked the Tuya cloud online and the missing data is there, so Tuya is not to blame here.
As you can see, on the first "fetch" a properly formed URL with all the necessary query params is passed and a perfectly formed response is received. When I look into the code for _tuyaplatform(), here's what I see: def _tuyaplatform(self, uri, action='GET', post=None, ver='v1.0', recursive=False, query=None, content_type=None):
...
# Check to see if token is expired
if "token invalid" in response.text:
if recursive is True:
log.debug("Failed 2nd attempt to renew token - Aborting")
return None
log.debug("Token Expired - Try to renew")
self._gettoken()
if not self.token:
log.debug("Failed to renew token")
return None
else:
return self._tuyaplatform(uri, action, post, ver, True) But uri variable is just pure path with no query parameters, you probably need to pass query as well to the recursive call to the function? Like this: return self._tuyaplatform(uri, action, post, ver, True, query) Would appreciate any feedback. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @ndlarge Yes, that does look like a bug. We actually want to pass the entire context to the recursion: return self._tuyaplatform(uri, action, post, ver, True, query, content_type) Thank you! I'll open an issue. Feel free to submit a PR if you would like, so you can get credit. 😁 One concern: That's a lot of API calls to Tuya Cloud. Are you hitting any rate limits or quotas? |
Beta Was this translation helpful? Give feedback.
-
Thank you @jasonacox . As for the rate limits or quotas - I have no idea frankly. The Tuya documentation on this is extremely unclear but so far (a few days) I had no indication that I was hitting any limits. Could this constantly expiring token be an indication of me hitting some limits? I don't even know how I am going to know if I hit a limit or a quota (besides stuff stopping working suddenly). |
Beta Was this translation helpful? Give feedback.
Hi @ndlarge Yes, that does look like a bug. We actually want to pass the entire context to the recursion:
Thank you!
I'll open an issue. Feel free to submit a PR if you would like, so you can get credit. 😁
One concern: That's a lot of API calls to Tuya Cloud. Are you hitting any rate limits or quotas?