bmentink
04/14/2025, 12:35 AMbackoff := 1000
while true: // Normal mqtt task.
start := Time.monotonic-us
e := catch: // Catch the broker going away.
run-mqtt
if e:
attempt-duration := Time.monotonic-us - start
if attempt-duration < 1_000_000: // < 1 second
// Immediate failure. Increase backoff.
backoff = min (2 * backoff) 60_000 // Max backoff time 10 sec
else:
// Slow failure. Reset backoff.
backoff = 1000
//print "caught exception $e"
sleep --ms=2000 //backoff