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

srandy kopec

parent 121f6173
......@@ -16,28 +16,29 @@ def connectToNetwork(ssid, password):
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('connecting to network %s' %ssid)
print('connecting to wlan network: %s' %ssid)
wlan.connect(ssid, password)
while not wlan.isconnected():
pass
print('network config:', wlan.ifconfig())
print('connected! network config:', wlan.ifconfig())
def on_message(topic, message):
print(message)
def connectToMQTT():
print(wlan.isconnected())
global mqtt_client
def connectToMQTT():
global mqtt_client
SSL_PARAMS = {'server_hostname': '50ffbd7e701c480ca097875a1621692c.s1.eu.hivemq.cloud'}
mqtt_client = MQTTClient(
client_id = 'bla',
client_id = 'birdie_house_' + ubinascii.hexlify(network.WLAN().config('mac'),'_').decode(),
server = '50ffbd7e701c480ca097875a1621692c.s1.eu.hivemq.cloud',
port = 8883,
keepalive = 60,
ssl=True
keepalive = 30,
ssl=True,
user='birdie',
password='tjhpnHMQb2021',
ssl_params=SSL_PARAMS
)
mqtt_client.connect()
mqtt_client.set_callback(on_message)
mqtt_client.subscribe("birdie/tx")
mqtt_client.connect()
async def readTemperatrue():
while True:
......@@ -46,8 +47,7 @@ async def readTemperatrue():
dht_sensor.measure()
temp = dht_sensor.temperature()
hum = dht_sensor.humidity()
print('Temperature: %3.1f C' %temp)
print('Humidity: %3.1f %%' %hum)
print('Temperature: %3.1f C; ' %temp, 'Humidity: %3.1f %%' %hum)
except OSError as e:
print('Failed to read from DHT11 sensor: %s' %e)
......@@ -56,7 +56,7 @@ async def detectMotion():
while True:
await uasyncio.sleep(1)
if pir.value():
mqtt_client.publish('birdie/rx', 'TAKE_PHOTO')
mqtt_client.publish('birdie/rxtx/raspberry', 'TAKE_PHOTO')
await uasyncio.sleep_ms(40)
while pir.value():
pass
......
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