-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor-reader.py
More file actions
executable file
·53 lines (44 loc) · 1.55 KB
/
sensor-reader.py
File metadata and controls
executable file
·53 lines (44 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Sensor reader for BME280 Temp sensor and SDS011 PM sensor
"""
from SDS011.sds011 import SDS011, report_mode, work_state
from Adafruit_BME280 import *
# Sensor codes:
SENSOR_PM10 = 0
SENSOR_PM25 = 1
SENSOR_TEMPERATURE = 2
SENSOR_HUMIDITY = 3
SENSOR_PRESSION = 4
def main():
try:
sensor_tmp = BME280(
t_mode=BME280_OSAMPLE_8,
p_mode=BME280_OSAMPLE_8,
h_mode=BME280_OSAMPLE_8,
standby=BME280_STANDBY_250,
filter=BME280_FILTER_off, address=0x77)
degrees = sensor_tmp.read_temperature()
pascals = sensor_tmp.read_pressure()
humidity = sensor_tmp.read_humidity()
print("log: {} {}".format(SENSOR_TEMPERATURE, degrees))
print("log: {} {}".format(SENSOR_PRESSION, pascals))
print("log: {} {}".format(SENSOR_HUMIDITY, humidity))
except BaseException as e:
print("err: {}".format(e.message))
try:
sensor_pm = SDS011("/dev/ttyS1")
# sensor_pm = SDS011("/dev/ttyS1")
sensor_pm.report_mode = report_mode["Passive"]
time.sleep(5) # Investigate and test this sleep time
pm10, pm25 = sensor_pm.request()
time.sleep(5)
if pm25 is not None and pm10 is not None:
print("log: {} {}".format(SENSOR_PM10, pm10))
print("log: {} {}".format(SENSOR_PM25, pm25))
sensor_pm.work_state = work_state["Sleeping"]
except BaseException as e:
print("err: {}".format(e.message))
if __name__ == "__main__":
main()