ikalchev / py-sds011 Goto Github PK
View Code? Open in Web Editor NEWPython 3 interface to the SDS011 air particulate density sensor.
License: MIT License
Python 3 interface to the SDS011 air particulate density sensor.
License: MIT License
I have your code running on a Raspberry Pi. And for the most part it is working, but occasionally I get an IndexError that kills the program.
The problem occurs in the _get_reply(self) function on this line of the sds011.py file:
if (sum(d for d in data) & 255 !+ raw[8]:
return None
What I see on the console is as follows:
Traceback (most recent call last):
File "./Combo_ATH_AIO_Web_Thingspeak.py", line 141, in
pmt_2_5, pmt_10 = get_data()
File "./Combo_ATH_AIO_Web_Thingspeak.py", line 97, in get_data
AQISENSOR.sleep(sleep=False)
File "/home/pi/Combo-AIO-Web-Thingspeak/sds011.py", line 113, in sleep
self._get_reply()
File "/home/pi/Combo-AOI-Web-Thingspeak/sds011.py", line 57, in _get_reply
if (sum(d for d in data) & 255 != raw[8];
IndexError: index out of range
I'm not proficient enough with Python to see what the problem is here, so hoping you (or someone else) can help me with this.
Regards,
rgmcleod52
The example shows
time.sleep(15) # Allow time for the sensor to measure properly
yet the datasheet states:
"The data is stable when the sensor works after 30 seconds"
Line 158 in 4d3380a
Wondering if a PR to remove this is a good idea. I spent some time with this and couldn't get it to work. Documented query()
worked fine.
>>> sensor.query()
(0.8, 0.9)
What physical unit do I see in this output?
Is there a way to set sensor sleep time? I set sleep = 10 in config.txt, but this value doesnt effect sensor sleep time.
My sensor always sleeps for minute and 30s, even if I don't open python app. I would like sensor to wake up every 10 minutes.
Neither function returns anything (based on code review and running).
Possibly related to #3. Opened new issue as impacts both routines.
It would be nice to have a destructor for the SDS011
class. The simplest I can think of is:
def __del__(self):
self.sleep()
If for any reason the script crashes, the sensor will be safely shut down.
I created the following test program:
#!/usr/bin/python3
import sds011
import time
sensor = sds011.SDS011( "/dev/ttyUSB2", use_query_mode=True )
sensor.sleep( sleep=False )
time.sleep( 15 )
pm25, pm10 = sensor.query()
sensor.sleep()
print( "PM2.5: %6.1f" % pm25 )
print( "PM10: %6.1f" % pm10 )
The first time after connecting the sensor it works, but after that when the sensor is in the sleep mode i get the following exception:
Traceback (most recent call last):
File "./readout.py", line 10, in
sensor = sds011.SDS011( "/dev/ttyUSB2", use_query_mode=True )
File "/home/mf/python/sensors/sds011/sds011/init.py", line 44, in init
self.set_report_mode(active=not use_query_mode)
File "/home/mf/python/sensors/sds011/sds011/init.py", line 76, in set_report_mode
self._get_reply()
File "/home/mf/python/sensors/sds011/sds011/init.py", line 55, in _get_reply
if (sum(d for d in data) & 255) != raw[8]:
IndexError: index out of range
To get it working I added a check for reply length in function _get_reply() near line 171:
if len(data) == 0:
return None
I assume there is a timeout and that's the reason that 0 bytes are received. I did not check if more changes are needed to make it work properly, it seems to work fine with this change alone.
Hello,
how can I check if sensor is in sleep mode?
I am trying
sensor.sleep(sleep=True)
print (sensor.sleep(read=True))
sensor.sleep()
print (sensor.sleep(read=True))
but this won't work as expected.
I am getting two times
None
None
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.