Commit e41384bc authored by Daniel Kolibár's avatar Daniel Kolibár
Browse files

faking stuff in esp32 with random values

parent ae8374fc
......@@ -6,6 +6,7 @@ import network
import ubinascii
from umqtt.robust import MQTTClient
import json
import random
dht_sensor = dht.DHT11(Pin(14))
pir = Pin(13, Pin.IN)
......@@ -50,8 +51,11 @@ async def readTemperatrue():
await uasyncio.sleep(1)
dht_sensor.measure()
temp = dht_sensor.temperature()
hum = dht_sensor.humidity()
print('Temperature: %3.1f C; ' %temp, 'Humidity: %3.1f %%' %hum)
x = {'houseId': HOUSE_ID, 'temperature': temp}
hum = dht_sensor.humidity()
y = {'houseId': HOUSE_ID, 'humidity': hum}
mqtt_client.publish('birdie/humidity', json.dumps(y))
print('Temperature: %3.1f C; ' %temp, 'Humidity: %3.1f %%' %hum)
except OSError as e:
print('Failed to read from DHT11 sensor: %s' %e)
......@@ -70,11 +74,32 @@ async def detectMotion():
else:
print('No motion detected!')
async def detectWindSpeed():
while True:
await uasyncio.sleep(1)
x = {'houseId': HOUSE_ID, 'windspeed': random.randint(0, 74)}
mqtt_client.publish('birdie/windspeed', json.dumps(x))
async def detectSmoke():
while True:
await uasyncio.sleep(1)
x = {'houseId': HOUSE_ID, 'smoke': random.randint(0, 1)}
mqtt_client.publish('birdie/smoke', json.dumps(x))
async def detectPressure():
while True:
await uasyncio.sleep(1)
x = {'houseId': HOUSE_ID, 'pressure': random.randint(250, 750)}
mqtt_client.publish('birdie/pressure', json.dumps(x))
connectToNetwork("wifi-lab", "12345wifilabhouse54321")
connectToMQTT()
event_loop = uasyncio.get_event_loop()
event_loop.create_task(readTemperatrue())
event_loop.create_task(detectMotion())
event_loop.create_task(detectWindSpeed())
event_loop.create_task(detectSmoke())
event_loop.create_task(detectPressure())
event_loop.run_forever()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment