Added WTD

This commit is contained in:
Christoffer Martinsson 2022-09-18 13:32:03 +02:00
parent 941a5fb12f
commit 04580bb5a9

26
main.py
View File

@ -5,38 +5,44 @@ from machine import Pin, UART, WDT
from umqtt.simple import MQTTClient
prefix = config.MQTT_ID + "/"
print("Booting...")
led = Pin("LED", machine.Pin.OUT)
led.value(1)
time.sleep_us(200)
time.sleep(0.1)
led.value(0)
time.sleep_us(200)
time.sleep(0.1)
led.value(1)
time.sleep_us(200)
time.sleep(0.1)
led.value(0)
time.sleep_us(200)
led.value(1)
wdt = WDT(timeout=30000)
wdt = WDT()
print("Setting up WLAN")
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(config.WIFI_SSID, config.WIFI_PASS)
wdt.feed()
while not wlan.isconnected() and wlan.status() >= 0:
print("Waiting to connect:")
print("Connecting...")
led.value(1)
time.sleep_us(500)
time.sleep(0.5)
led.value(0)
time.sleep_us(500)
time.sleep(0.5)
wdt.feed()
print("Connected!")
led.value(0)
wdt.feed()
print("Setting up MQTT")
client = MQTTClient(config.MQTT_ID, config.MQTT_BROKER,user=None, password=None, keepalive=300, ssl=False, ssl_params={})
client.connect()
client.publish(prefix + 'status', "connected")
wdt.feed()
print("Setting up UART")
uart = machine.UART(0, 115200,invert=UART.INV_RX)
def readUntil(uartObject, termination, maxlen=-1, includeTermination=True):
@ -80,6 +86,8 @@ def parse_han_protocol(data):
data = ""
wdt.feed()
print("Running...")
while True:
led.value(0)
wdt.feed()