-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweatherstationbme680.py
More file actions
109 lines (95 loc) · 3.56 KB
/
weatherstationbme680.py
File metadata and controls
109 lines (95 loc) · 3.56 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from __future__ import division
from webthing import (Property, Thing, Value)
import logging
import tornado.ioloop
import sensorBME680
class WeatherstationBME680(Thing):
def __init__(self):
Thing.__init__(self,
'Indoor Weatherstation',
['MultiLevelSensor', 'TemperatureSensor'],
'A web connected weatherstation')
self.level = Value(0.0)
self.add_property(
Property(
self,
'level',
self.level,
metadata={
'@type': 'LevelProperty',
'title': 'Air Quality',
'type': 'number',
'description': 'The current air quality',
'minimum': 0,
'maximum': 100,
'unit': 'percent',
'readOnly': True,
}))
self.humidity = Value(0.0)
self.add_property(
Property(
self,
'humidity',
self.humidity,
metadata={
'title': 'Humidity',
'type': 'number',
'description': 'Humidity in %',
'minimum': 0,
'maximum': 100,
'unit': 'percent',
'readOnly': True,
}))
self.temperature = Value(0.0)
self.add_property(
Property(
self,
'temperature',
self.temperature,
metadata={
'@type': 'TemperatureProperty',
'title': 'Temperature',
'type': 'number',
'description': 'The current temperature',
'minimum': -20,
'maximum': 80,
'unit': 'degree celsius',
'readOnly': True,
}))
self.pressure = Value(0.0)
self.add_property(
Property(
self,
'pressure',
self.pressure,
metadata={
'title': 'Air Pressure',
'type': 'number',
'description': 'The current air pressure',
'minimum': 600,
'maximum': 1200,
'unit': 'hPa',
'readOnly': True,
}))
logging.debug('starting the sensor update looping task')
self.timer = tornado.ioloop.PeriodicCallback(
self.update_levels,
3000
)
self.timer.start()
def update_levels(self):
if sensorBME680.sensor.get_sensor_data():
new_level = sensorBME680.update_air_quality()
logging.debug('setting new air quality: %s', new_level)
self.level.notify_of_external_update(new_level)
new_humidity = sensorBME680.update_humidity()
logging.debug('setting new humidity: %s', new_humidity)
self.humidity.notify_of_external_update(new_humidity)
new_temperature = sensorBME680.update_temperature()
logging.debug('setting new temperature: %s', new_temperature)
self.temperature.notify_of_external_update(new_temperature)
new_pressure = sensorBME680.update_pressure()
logging.debug('setting new air pressure: %s', new_pressure)
self.pressure.notify_of_external_update(new_pressure)
def cancel_update_level_task(self):
self.timer.stop()