final
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
|
||||||
import dht
|
import dht
|
||||||
from machine import Pin, Timer, RTC
|
from machine import Pin, Timer, RTC, SoftI2C
|
||||||
from micropyserver import MicroPyServer
|
from micropyserver import MicroPyServer
|
||||||
from micropyserver_utils import send_response, get_request_post_params
|
from micropyserver_utils import send_response, get_request_post_params
|
||||||
|
from i2c_lcd import I2cLcd
|
||||||
import ntptime
|
import ntptime
|
||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
@@ -12,6 +13,12 @@ DHT_PIN = 26
|
|||||||
RELAY_PIN = 4
|
RELAY_PIN = 4
|
||||||
UPDATE_INTERVAL_S = 60
|
UPDATE_INTERVAL_S = 60
|
||||||
MAX_LOG_SIZE = 3 * 1024 * 1024 # MegaByte
|
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"
|
name = "Test Sensor"
|
||||||
|
|
||||||
@@ -26,6 +33,8 @@ dht = dht.DHT22(Pin(DHT_PIN))
|
|||||||
relay = Pin(RELAY_PIN, Pin.OUT)
|
relay = Pin(RELAY_PIN, Pin.OUT)
|
||||||
update_timer = Timer(0)
|
update_timer = Timer(0)
|
||||||
index_template = ""
|
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
|
humidity_limit = 80
|
||||||
|
|
||||||
@@ -83,6 +92,15 @@ def update(_):
|
|||||||
update_relay()
|
update_relay()
|
||||||
|
|
||||||
write_log()
|
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():
|
def update_relay():
|
||||||
if high_humidity():
|
if high_humidity():
|
||||||
@@ -219,6 +237,7 @@ def load_index_template():
|
|||||||
def main():
|
def main():
|
||||||
global server
|
global server
|
||||||
init()
|
init()
|
||||||
|
update(None)
|
||||||
server.start()
|
server.start()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from time import sleep
|
||||||
def do_connect():
|
def do_connect():
|
||||||
import network
|
import network
|
||||||
wlan = network.WLAN(network.STA_IF)
|
wlan = network.WLAN(network.STA_IF)
|
||||||
@@ -6,14 +7,10 @@ def do_connect():
|
|||||||
print('connecting to network...')
|
print('connecting to network...')
|
||||||
wlan.connect('nubbe', 'MFhBB!MThAuE!')
|
wlan.connect('nubbe', 'MFhBB!MThAuE!')
|
||||||
while not wlan.isconnected():
|
while not wlan.isconnected():
|
||||||
|
sleep(0.1)
|
||||||
|
print("Connecting")
|
||||||
pass
|
pass
|
||||||
print('network config:', wlan.ifconfig())
|
print('network config:', wlan.ifconfig())
|
||||||
|
|
||||||
do_connect()
|
do_connect()
|
||||||
import gc
|
|
||||||
import webrepl
|
|
||||||
|
|
||||||
webrepl.start()
|
|
||||||
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user