From faca6d7f7c1e8bde8f1ee57cba0506ef96692885 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 12 Oct 2022 18:36:33 +0200 Subject: [PATCH] watchdog re-enabled --- config.py | 4 ++-- main.py | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/config.py b/config.py index a56a403..08442b2 100644 --- a/config.py +++ b/config.py @@ -1,9 +1,9 @@ import secrets -SSID = 'telemetry' +SSID = 'gast1000' WPA_KEY = secrets.WPA_KEY -MQTT_SERVER = '172.16.10.47' +MQTT_SERVER = 'broker.hottis.de' MQTT_LOGIN = 'thermo-anna' MQTT_PASSWORD = secrets.MQTT_PASSWORD diff --git a/main.py b/main.py index 36d7551..553e360 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import machine from umqttsimple import MQTTClient import time import ubinascii -from machine import Pin +from machine import Pin, WDT from onewire import OneWire from ds18x20 import DS18X20 import network @@ -16,9 +16,9 @@ SENSOR_PIN = 16 print("Hello") resetCause = machine.reset_cause() -# wdt = WDT(timeout=8000) -# wdt.feed() -# print("Watchdog enabled") +wdt = WDT(timeout=8000) +wdt.feed() +print("Watchdog enabled") try: wlan = network.WLAN(network.STA_IF) @@ -28,7 +28,7 @@ try: connectCnt = 0 while (not wlan.isconnected() or (connectCnt > config.MAX_CONNECT_RETRY_CNT)): print("Not yet connected") - # wdt.feed() + wdt.feed() connectCnt += 1 time.sleep(1) @@ -37,19 +37,19 @@ try: machine.reset() print(f"Connected to WLAN: {resetCause} {connectCnt} {wlan.ifconfig()}") - # wdt.feed() + wdt.feed() clientId = f"rpipwtherm-{ubinascii.hexlify(machine.unique_id())}" client = MQTTClient(clientId, config.MQTT_SERVER, keepalive=60, ssl=True, user=config.MQTT_LOGIN, password=config.MQTT_PASSWORD) client.connect() print(f"Connected to MQTT broker {config.MQTT_SERVER} ") - # wdt.feed() + wdt.feed() # client.publish(config.STARTUP_TOPIC, f"Hello, rpipw thermometer is alive now at {wlan.ifconfig()}") except Exception as e: print(f"Some error when starting: {e.__class__.__name__}, {e}") - time.sleep(15) + time.sleep(5) machine.reset() @@ -68,7 +68,7 @@ try: print(f"Sensor: {idx}, {json.dumps(msg)}") client.publish(config.PAYLOAD_TOPIC, json.dumps(msg)) print(f"Payload {idx} sent") - # wdt.feed() + wdt.feed() client.disconnect() print("Disconnected from broker") @@ -79,10 +79,11 @@ try: except Exception as e: print(f"Error in main loop: {e.__class__.__name__}, {e}") finally: - print("Waiting ...") - # wdt.feed() + for w in range(config.MAIN_PERIOD_S): + print(f"Waiting {w}...") + wdt.feed() + time.sleep(1) - time.sleep(config.MAIN_PERIOD_S) print("Restarting") time.sleep(1) machine.reset()