This commit is contained in:
Jonas Zeunert
2024-09-19 21:41:45 +02:00
parent b53eb6a2f6
commit 345e3133e3
2 changed files with 23 additions and 7 deletions

View File

@@ -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()

View File

@@ -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()