From 345e3133e381fc941cc7e6b43e269a443d5adba3 Mon Sep 17 00:00:00 2001 From: Jonas Zeunert Date: Thu, 19 Sep 2024 21:41:45 +0200 Subject: [PATCH] final --- code/src/main.py | 21 ++++++++++++++++++++- firmware/boot.py | 9 +++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/code/src/main.py b/code/src/main.py index 159861c..237b555 100644 --- a/code/src/main.py +++ b/code/src/main.py @@ -1,9 +1,10 @@ #!/bin/python import dht -from machine import Pin, Timer, RTC +from machine import Pin, Timer, RTC, SoftI2C from micropyserver import MicroPyServer from micropyserver_utils import send_response, get_request_post_params +from i2c_lcd import I2cLcd import ntptime import os import io @@ -12,6 +13,12 @@ DHT_PIN = 26 RELAY_PIN = 4 UPDATE_INTERVAL_S = 60 MAX_LOG_SIZE = 3 * 1024 * 1024 # MegaByte +I2C_SCL = Pin(19) +I2C_SDA = Pin(18) +I2C_FREQ = 100000 +I2C_ADDR = 39 +DISP_ROWS = 2 +DISP_COLS = 16 name = "Test Sensor" @@ -26,6 +33,8 @@ dht = dht.DHT22(Pin(DHT_PIN)) relay = Pin(RELAY_PIN, Pin.OUT) update_timer = Timer(0) index_template = "" +i2c = SoftI2C(scl=I2C_SCL, sda=I2C_SDA, freq=I2C_FREQ) +lcd = I2cLcd(i2c, I2C_ADDR, DISP_ROWS, DISP_COLS) humidity_limit = 80 @@ -83,6 +92,15 @@ def update(_): update_relay() write_log() + + update_disp() + +def update_disp(): + global lcd, temp, humidity + lcd.clear() + text = f'Temp: {temp:2.1f}ßC Humidity: {humidity:2.1f}%' + lcd.putstr(text) + def update_relay(): if high_humidity(): @@ -219,6 +237,7 @@ def load_index_template(): def main(): global server init() + update(None) server.start() diff --git a/firmware/boot.py b/firmware/boot.py index 1ac0af7..9f00b2d 100644 --- a/firmware/boot.py +++ b/firmware/boot.py @@ -1,3 +1,4 @@ +from time import sleep def do_connect(): import network wlan = network.WLAN(network.STA_IF) @@ -6,14 +7,10 @@ def do_connect(): print('connecting to network...') wlan.connect('nubbe', 'MFhBB!MThAuE!') while not wlan.isconnected(): + sleep(0.1) + print("Connecting") pass print('network config:', wlan.ifconfig()) do_connect() -import gc -import webrepl - -webrepl.start() - -gc.collect()