Added SHT30 sensor node example app
parent
19178e0700
commit
1e893405c5
|
@ -0,0 +1,25 @@
|
|||
|
||||
__version__ = 21
|
||||
__app__ = 'sensor_node'
|
||||
|
||||
|
||||
DEPENDENCIES = [
|
||||
('lib/sht30.py', 'https://raw.githubusercontent.com/rsc1975/micropython-sht30/3b2ec7c46c9d63e37432009002ec1149da341ac7/sht30.py')
|
||||
]
|
||||
|
||||
|
||||
async def run(mqtt, name):
|
||||
|
||||
interval_sub = mqtt.subscribe('home/config/sensor_node/measurement_interval', cls=int)
|
||||
location_sub = mqtt.subscribe('config/location', local=True)
|
||||
from sht30 import SHT30
|
||||
sensor = SHT30()
|
||||
temperature, humidity = sensor.measure()
|
||||
location = await location_sub.wait_for_value()
|
||||
sensor_topic = 'home/sensors/{}/{}'
|
||||
mqtt.publish(sensor_topic.format(location, 'temperature'),
|
||||
b'{:.2f}'.format(temperature), qos=1, retain=True)
|
||||
mqtt.publish(sensor_topic.format(location, 'humidity'),
|
||||
b'{}'.format(humidity), qos=1, retain=True)
|
||||
|
||||
return await interval_sub.wait_for_value()
|
Loading…
Reference in New Issue