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

PM2.5 Faster Readout #111

Closed
sibero80 opened this issue Nov 3, 2017 · 4 comments
Closed

PM2.5 Faster Readout #111

sibero80 opened this issue Nov 3, 2017 · 4 comments

Comments

@sibero80
Copy link

sibero80 commented Nov 3, 2017

Hello everyone, greetings from Colombia!
I'm trying to figure out the best way to create a listener service that can have a short polling interval from the PM2.5 sensor data.

Executing the command miio --control 192.168.0.22 --method get_prop --params '["aqi","power","battery","usb_state"]' provides de desired information, but it takes too long to process (I'm assuming there is some initialization done each time the miio command is executed).

Any suggestins on how to implement a more quick/efficient sensor readout using this library?

thank you!

@syssi
Copy link
Collaborator

syssi commented Nov 3, 2017

Why do you need more speed? Does the sensor (PM2.5) update so frequently? :-)

@sibero80
Copy link
Author

sibero80 commented Nov 3, 2017

That is a great question! I'm trying to implement a makeshift computer vision for cars and PM2.5 correlation. So refresh rate improvements would be great at any level!
I'm asking this because I see that the screen of the device is refreshing at a faster rate than the bash script is pulling.

If discovering a python mechanism what would elliminate any overhead in the readout of the sensor ouput, at least by a 20% - 30%, it would mean a huge improvement for the computer vision project.

I think my question can also be interpreted as this:
Where can I see code examples on how to get device information using python, where all dependencies are only loaded once, and elliminate most of the overhead for continous readout.

Thank you all!

@rytilahti
Copy link
Owner

rytilahti commented Nov 7, 2017

I think it makes sense to create your own script for your use-case (which was interesting to hear, btw!), but unfortunaly(?) there is no currently way to say whether the handshake is done as a part of communication. The basic workflow would however look like this, which would assuming there are no other limitations on the device would go like this:

  1. Initial discovery handshake (which is done currently every time something is sent out)
  2. Keep polling the device until the time limit hits (the device will stop answering to requests if there has been no handshake for a while, but can't recall the details, e.g. https://github.com/aholstenson/miio/ does handshake only every X minutes)
  3. Do a handshake only when necessary.

Adding a cache instead of sending a handshake for every request is something we could merge assuming it won't break anything. Making it send the handshake for each requests was just an easy way out at that point.

edit: from the looks if it, you are not using this library actually? If so, I think this issue could be closed (although avoiding unnecessary handshakes would still be nice to have!) -- otherwise the instructions I wrote above will stand; you do not want to execute the command from the shell for each invocation but run it in a loop.

@sibero80
Copy link
Author

sibero80 commented Nov 7, 2017

Thank you rytilahti! Your points make a lot of sense. I was hoping to find out an out-of the box, but it seems I'll have to get my hands dirty as I'm not yet well enough versed in Python, but the challenge is thrilling. Closing the issue!

@sibero80 sibero80 closed this as completed Nov 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants