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 import secrets
SSID = 'telemetry' SSID = 'gast1000'
WPA_KEY = secrets.WPA_KEY WPA_KEY = secrets.WPA_KEY
MQTT_SERVER = '172.16.10.47' MQTT_SERVER = 'broker.hottis.de'
MQTT_LOGIN = 'thermo-anna' MQTT_LOGIN = 'thermo-anna'
MQTT_PASSWORD = secrets.MQTT_PASSWORD MQTT_PASSWORD = secrets.MQTT_PASSWORD

25
main.py
View File

@ -2,7 +2,7 @@ import machine
from umqttsimple import MQTTClient from umqttsimple import MQTTClient
import time import time
import ubinascii import ubinascii
from machine import Pin from machine import Pin, WDT
from onewire import OneWire from onewire import OneWire
from ds18x20 import DS18X20 from ds18x20 import DS18X20
import network import network
@ -16,9 +16,9 @@ SENSOR_PIN = 16
print("Hello") print("Hello")
resetCause = machine.reset_cause() resetCause = machine.reset_cause()
# wdt = WDT(timeout=8000) wdt = WDT(timeout=8000)
# wdt.feed() wdt.feed()
# print("Watchdog enabled") print("Watchdog enabled")
try: try:
wlan = network.WLAN(network.STA_IF) wlan = network.WLAN(network.STA_IF)
@ -28,7 +28,7 @@ try:
connectCnt = 0 connectCnt = 0
while (not wlan.isconnected() or (connectCnt > config.MAX_CONNECT_RETRY_CNT)): while (not wlan.isconnected() or (connectCnt > config.MAX_CONNECT_RETRY_CNT)):
print("Not yet connected") print("Not yet connected")
# wdt.feed() wdt.feed()
connectCnt += 1 connectCnt += 1
time.sleep(1) time.sleep(1)
@ -37,19 +37,19 @@ try:
machine.reset() machine.reset()
print(f"Connected to WLAN: {resetCause} {connectCnt} {wlan.ifconfig()}") print(f"Connected to WLAN: {resetCause} {connectCnt} {wlan.ifconfig()}")
# wdt.feed() wdt.feed()
clientId = f"rpipwtherm-{ubinascii.hexlify(machine.unique_id())}" clientId = f"rpipwtherm-{ubinascii.hexlify(machine.unique_id())}"
client = MQTTClient(clientId, config.MQTT_SERVER, keepalive=60, client = MQTTClient(clientId, config.MQTT_SERVER, keepalive=60,
ssl=True, user=config.MQTT_LOGIN, password=config.MQTT_PASSWORD) ssl=True, user=config.MQTT_LOGIN, password=config.MQTT_PASSWORD)
client.connect() client.connect()
print(f"Connected to MQTT broker {config.MQTT_SERVER} ") 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()}") # client.publish(config.STARTUP_TOPIC, f"Hello, rpipw thermometer is alive now at {wlan.ifconfig()}")
except Exception as e: except Exception as e:
print(f"Some error when starting: {e.__class__.__name__}, {e}") print(f"Some error when starting: {e.__class__.__name__}, {e}")
time.sleep(15) time.sleep(5)
machine.reset() machine.reset()
@ -68,7 +68,7 @@ try:
print(f"Sensor: {idx}, {json.dumps(msg)}") print(f"Sensor: {idx}, {json.dumps(msg)}")
client.publish(config.PAYLOAD_TOPIC, json.dumps(msg)) client.publish(config.PAYLOAD_TOPIC, json.dumps(msg))
print(f"Payload {idx} sent") print(f"Payload {idx} sent")
# wdt.feed() wdt.feed()
client.disconnect() client.disconnect()
print("Disconnected from broker") print("Disconnected from broker")
@ -79,10 +79,11 @@ try:
except Exception as e: except Exception as e:
print(f"Error in main loop: {e.__class__.__name__}, {e}") print(f"Error in main loop: {e.__class__.__name__}, {e}")
finally: finally:
print("Waiting ...") for w in range(config.MAIN_PERIOD_S):
# wdt.feed() print(f"Waiting {w}...")
wdt.feed()
time.sleep(1)
time.sleep(config.MAIN_PERIOD_S)
print("Restarting") print("Restarting")
time.sleep(1) time.sleep(1)
machine.reset() machine.reset()