From a775dc71d70617cd1c5ad006861f892a51eb9351 Mon Sep 17 00:00:00 2001 From: Jeroen88 Date: Mon, 24 Oct 2022 17:45:47 +0200 Subject: [PATCH] Change time_t into uint32_t for correct unsigned roll over of intervals --- examples/Advanced_Thermostat/Advanced_Thermostat.ino | 4 ++-- examples/Basic_Thermostat_Commands/Basic_Thermostat_Commands.ino | 4 ++-- src/EasyOpenTherm.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/Advanced_Thermostat/Advanced_Thermostat.ino b/examples/Advanced_Thermostat/Advanced_Thermostat.ino index aa43b9c..fa1b36f 100644 --- a/examples/Advanced_Thermostat/Advanced_Thermostat.ino +++ b/examples/Advanced_Thermostat/Advanced_Thermostat.ino @@ -116,12 +116,12 @@ void loop() { static OpenTherm thermostat(OT_RX_PIN, OT_TX_PIN); // static variables used by the PID controller - static time_t previousTimestamp = millis(); // Previous timestamp + static uint32_t previousTimestamp = millis(); // Previous timestamp static float previousTemperature = bme.readTemperature(); // Previous temperature static float ierr = 0; // Integral error - time_t timestamp = millis(); + uint32_t timestamp = millis(); if(timestamp - previousTimestamp >= 1000) { float roomTemperature = bme.readTemperature(); // Read the sensor to get the current room temperature Serial.printf("Room temperature is %.02f *C, room temperature setpoint is %.02f *C\n", roomTemperature, ROOM_TEMPERATURE_SETPOINT); diff --git a/examples/Basic_Thermostat_Commands/Basic_Thermostat_Commands.ino b/examples/Basic_Thermostat_Commands/Basic_Thermostat_Commands.ino index e4d287f..e88c645 100644 --- a/examples/Basic_Thermostat_Commands/Basic_Thermostat_Commands.ino +++ b/examples/Basic_Thermostat_Commands/Basic_Thermostat_Commands.ino @@ -58,9 +58,9 @@ void loop() { // Create an OpenTherm thermostat (boiler is secondary) with OT_RX_PIN to receive data from boiler and OT_TX_PIN to send data to boiler // Only one OpenTherm object may be created! static OpenTherm thermostat(OT_RX_PIN, OT_TX_PIN); - static time_t previousTimestamp = millis(); // Previous timestamp + static uint32_t previousTimestamp = millis(); // Previous timestamp - time_t timestamp = millis(); + uint32_t timestamp = millis(); if(timestamp - previousTimestamp >= 1000) { // primaryFlags is used to tell the secondary device (boiler) what available services (Central heating, cooling, domestic hot water) it wants to make use of, if present diff --git a/src/EasyOpenTherm.cpp b/src/EasyOpenTherm.cpp index 83f03f9..b1af084 100644 --- a/src/EasyOpenTherm.cpp +++ b/src/EasyOpenTherm.cpp @@ -186,7 +186,7 @@ OpenTherm::ERROR_CODES OpenTherm::error() { bool OpenTherm::_execute(OTDataLinkLayer & data) { _lastError = ERROR_CODES::OK; - time_t startMillis = millis(); + uint32_t startMillis = millis(); for(;;) { if(millis() - startMillis >= _timeoutMs) { _lastError = ERROR_CODES::SEND_TIMEOUT; -- libgit2 0.21.4