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
The response time to get the current power usage varies a lot #1932
Comments
Hi, There could be two reasons for this:
Let me know if that helps! |
Thanks for the quick reply! The problem I had seemed to be the first one, writing a simple python script to call the API solved the problem and now it works fine, thanks! |
Sorry, I just tested it again and this weird issue came up again. I wrote this python script: from miio import DeviceFactory
import time
dev = DeviceFactory.create("1.1.1.1", "aaaa")
while True:
start = time.time() * 1000
print(dev.get_property_by(11,2))
print("Time used: " + str(int(time.time() * 1000 - start)) + " ms") It's output is:
Time for each request is 200-300ms, that is normal. But when I added a sleep between each request, something seems to go wrong. from miio import DeviceFactory
import time
dev = DeviceFactory.create("1.1.1.1", "aaaa")
while True:
start = time.time() * 1000
print(dev.get_property_by(11,2))
print("Time used: " + str(int(time.time() * 1000 - start)) + " ms")
time.sleep(1) # <= Only change here Now there're weird spikes in response time (some requests take >1000ms, some <100ms):
|
Could you add a timestamp to the print output to see if those delays appear on regular periods? Just wondering if it could have something to do with the handshake handling (i.e., device expecting one in some intervals), but could it also be be, that the device happens to be in some sort of power save mode and/or that the wifi connection is congested? |
My device is very close to the router and there are no other devices on the LAN interfering with it, so I don't think it should be the network quality that is causing the delay. (I've also repeated the experiment several times and the response time of the device is always very stable if I changed the code to print the timestamp: from miio import GenericMiot
import time
import logging
logging.basicConfig(level=logging.DEBUG)
dev = GenericMiot("1.1.1.1", "xxxx", debug=True)
while True:
start = time.time() * 1000
print("Start request: " + str(int(start)))
print(dev.get_property_by(11,2))
print("Time used: " + str(int(time.time() * 1000 - start)) + " ms")
time.sleep(1) Output:
It does seem like the delays are somewhat cyclical? |
Describe the bug
The response time for the device to get the current power usage is sometimes long and sometimes short
Version information (please complete the following information):
Device information:
If the issue is specific to a device [Use
miiocli device --ip <ip address> --token <token> info
]:To Reproduce
Steps to reproduce the behavior:
miiocli genericmiot --ip 1.1.1.1 --token abcdef get_property_by 11 2
Expected behavior
It should be possible to obtain power consumption data quickly. (e.g. below 200ms for all requests)
The text was updated successfully, but these errors were encountered: