Added SHT30 sensor node example app

master
Lukas Schuller 2019-02-25 06:58:05 +01:00 committed by Lukas Schuller
parent 19178e0700
commit 1e893405c5
1 changed files with 25 additions and 0 deletions

View File

@ -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()