watchdog re-enabled

This commit is contained in:
2022-10-12 18:36:33 +02:00
parent 6cb101108b
commit faca6d7f7c
2 changed files with 15 additions and 14 deletions

View File

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

25
main.py
View File

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