-
Notifications
You must be signed in to change notification settings - Fork 0
/
dustmonitor.py
40 lines (30 loc) · 938 Bytes
/
dustmonitor.py
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
import time
import grovepi
import atexit
import logging
import json
import sys
import datetime
from sensorvalue import SensorValue
def main():
location = 'Jons Office'
readdustsensor(location)
def writetofile(data):
with open('dustdata.csv', 'ab') as f:
f.write(data.writecsv() + '\n')
def readdustsensor(location):
atexit.register(grovepi.dust_sensor_dis)
print("Reading from the dust sensor")
grovepi.dust_sensor_en()
while True:
try:
[new_val,lowpulseoccupancy] = grovepi.dustSensorRead()
if new_val:
print(lowpulseoccupancy)
sensordata = SensorValue(lowpulseoccupancy, 'none', 'Dust', location)
writetofile(sensordata)
time.sleep(5)
except IOError:
print ("Error")
if __name__ == '__main__':
main()