From df27d1474a79fcb8b191175015bfe72b866a4e51 Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Wed, 18 Nov 2020 23:45:20 +0100 Subject: [PATCH] Make compatible with millis() rollover --- operame.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/operame.ino b/operame.ino index 5e0f8cc..1976430 100644 --- a/operame.ino +++ b/operame.ino @@ -214,8 +214,8 @@ void check_sensor() { } void loop() { - unsigned long next = millis() + 6000; - static unsigned long next_mqtt = 0; + static unsigned long previous_mqtt = 0; + unsigned long start = millis(); if (mqtt_enabled) mqtt.loop(); @@ -227,18 +227,18 @@ void loop() { if (CO2) { display_ppm(CO2); - if (mqtt_enabled && millis() > next_mqtt) { + if (mqtt_enabled && millis() - previous_mqtt >= mqtt_interval) { + previous_mqtt = millis(); connect_mqtt(); String message = mqtt_template; message.replace("{}", String(CO2)); retain(mqtt_topic, message); - next_mqtt = millis() + mqtt_interval; } } else { display_big("wacht..."); } - while (millis() < next) { + while (millis() - start < 6000) { if (CO2) display_ppm(CO2); // repeat, for blinking if (ota_enabled) ArduinoOTA.handle(); check_buttons();