From 75e6c2a955ccc999d81e70277f776b3e2a297b22 Mon Sep 17 00:00:00 2001 From: varna9000 Date: Sun, 27 Nov 2022 17:00:56 +0200 Subject: [PATCH] added dust sensor sleep --- main.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 8590751..798b3ae 100644 --- a/main.py +++ b/main.py @@ -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) @@ -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() @@ -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