-
Notifications
You must be signed in to change notification settings - Fork 0
/
enviro-board.py
81 lines (75 loc) · 2.36 KB
/
enviro-board.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import time
from coral.enviro.board import EnviroBoard
from dotenv import load_dotenv
from influxdb import InfluxDBClient
def main():
enviro = EnviroBoard()
load_dotenv()
client = InfluxDBClient(
os.getenv("HOST"),
os.getenv("PORT"),
)
client.switch_database(os.getenv("DBNAME"))
location = "window"
interval = 1
try:
while True:
iso = time.ctime()
json_body = [
{
"measurement": "temperature",
"tags": {
"sensor": "coral-enviro-temperature",
"location": location,
"unit": "celsius",
},
"time": iso,
"fields": {
"value": enviro.temperature
}
},
{
"measurement": "humidity",
"tags": {
"sensor": "coral-enviro-humidity",
"location": location,
"unit": "percentage",
},
"time": iso,
"fields": {
"value": enviro.humidity
}
},
{
"measurement": "ambient_light",
"tags": {
"sensor": "coral-enviro-ambient-light",
"location": location,
"unit": "lux"
},
"time": iso,
"fields": {
"value": enviro.ambient_light
}
},
{
"measurement": "pressure",
"tags": {
"sensor": "coral-enviro-pressure",
"location": location,
"unit": "kPa"
},
"time": iso,
"fields": {
"value": enviro.pressure
}
}
]
client.write_points(json_body)
time.sleep(interval)
except KeyboardInterrupt:
print('interrupted!')
client.close()
if __name__ == '__main__':
main()