Skip to content

Commit

Permalink
added dust sensor sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
varna9000 committed Nov 27, 2022
1 parent 38c10ae commit 75e6c2a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from config import *
import json
import math
import network

i2c = machine.I2C(0, sda=machine.Pin(21), scl=machine.Pin(22))
bme = bme280.BME280(i2c=i2c)
Expand All @@ -32,15 +33,32 @@ def on_receive(lora, outgoing):
payload = lora.read_payload()
print(payload)


def do_connect():
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.config(hostname="Micropython-Weather")

if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect(wifi_config['ssid'], wifi_config['password'])
while not sta_if.isconnected():
pass
print('network config:', sta_if.ifconfig())


lora.on_receive(on_receive)
lora.receive()


do_connect()

while True:

dust_sensor.wake()

time.sleep(5)

#Returns NOK if no measurement found in reasonable time
status = dust_sensor.read()

Expand All @@ -56,6 +74,8 @@ def on_receive(lora, outgoing):
else:
pm25=float(dust_sensor.pm25)
pm10=float(dust_sensor.pm10)

dust_sensor.sleep()

temperature,pressure,humidity = bme.values

Expand Down

0 comments on commit 75e6c2a

Please sign in to comment.