Call getLocalTime() only once to prevent a delay of 10ms if no time is available

This commit is contained in:
Thomas Basler
2025-03-29 18:15:22 +01:00
parent 192484ff28
commit 93e4ca8092
4 changed files with 44 additions and 58 deletions

View File

@@ -70,6 +70,8 @@ void HoymilesClass::loop()
iv->sendChangeChannelRequest();
}
if (Utils::getTimeAvailable()) {
// Fetch statistics
iv->sendStatsRequest();
// Fetch event log
@@ -83,16 +85,9 @@ void HoymilesClass::loop()
iv->sendSystemConfigParaRequest();
}
// Set limit if required
if (iv->SystemConfigPara()->getLastLimitCommandSuccess() == CMD_NOK) {
_messageOutput->println("Resend ActivePowerControl");
iv->resendActivePowerControlRequest();
}
// Set power status if required
if (iv->PowerCommand()->getLastPowerCommandSuccess() == CMD_NOK) {
_messageOutput->println("Resend PowerCommand");
iv->resendPowerControlRequest();
// Fetch grid profile
if (iv->Statistics()->getLastUpdate() > 0 && (iv->GridProfile()->getLastUpdate() == 0 || !iv->GridProfile()->containsValidData())) {
iv->sendGridOnProFileParaRequest();
}
// Fetch dev info (but first fetch stats)
@@ -112,10 +107,18 @@ void HoymilesClass::loop()
iv->sendDevInfoRequest();
}
}
}
// Fetch grid profile
if (iv->Statistics()->getLastUpdate() > 0 && (iv->GridProfile()->getLastUpdate() == 0 || !iv->GridProfile()->containsValidData())) {
iv->sendGridOnProFileParaRequest();
// Set limit if required
if (iv->SystemConfigPara()->getLastLimitCommandSuccess() == CMD_NOK) {
_messageOutput->println("Resend ActivePowerControl");
iv->resendActivePowerControlRequest();
}
// Set power status if required
if (iv->PowerCommand()->getLastPowerCommandSuccess() == CMD_NOK) {
_messageOutput->println("Resend PowerCommand");
iv->resendPowerControlRequest();
}
_messageOutput->printf("Queue size - NRF: %" PRId32 " CMT: %" PRId32 "\r\n", _radioNrf->getQueueSize(), _radioCmt->getQueueSize());

View File

@@ -3,6 +3,7 @@
* Copyright (C) 2023-2025 Thomas Basler and others
*/
#include "Utils.h"
#include <Arduino.h>
#include <time.h>
uint8_t Utils::getWeekDay()
@@ -11,3 +12,9 @@ uint8_t Utils::getWeekDay()
struct tm tm = *localtime(&now);
return tm.tm_mday;
}
bool Utils::getTimeAvailable()
{
struct tm timeinfo;
return getLocalTime(&timeinfo, 5);
}

View File

@@ -6,4 +6,5 @@
class Utils {
public:
static uint8_t getWeekDay();
static bool getTimeAvailable();
};

View File

@@ -24,11 +24,6 @@ bool HM_Abstract::sendStatsRequest()
return false;
}
struct tm timeinfo;
if (!getLocalTime(&timeinfo, 5)) {
return false;
}
time_t now;
time(&now);
@@ -45,11 +40,6 @@ bool HM_Abstract::sendAlarmLogRequest(const bool force)
return false;
}
struct tm timeinfo;
if (!getLocalTime(&timeinfo, 5)) {
return false;
}
if (!force) {
if (Statistics()->hasChannelFieldValue(TYPE_INV, CH0, FLD_EVT_LOG)) {
if (static_cast<uint8_t>(Statistics()->getChannelFieldValue(TYPE_INV, CH0, FLD_EVT_LOG) == _lastAlarmLogCnt)) {
@@ -77,11 +67,6 @@ bool HM_Abstract::sendDevInfoRequest()
return false;
}
struct tm timeinfo;
if (!getLocalTime(&timeinfo, 5)) {
return false;
}
time_t now;
time(&now);
@@ -102,11 +87,6 @@ bool HM_Abstract::sendSystemConfigParaRequest()
return false;
}
struct tm timeinfo;
if (!getLocalTime(&timeinfo, 5)) {
return false;
}
time_t now;
time(&now);
@@ -205,11 +185,6 @@ bool HM_Abstract::sendGridOnProFileParaRequest()
return false;
}
struct tm timeinfo;
if (!getLocalTime(&timeinfo, 5)) {
return false;
}
time_t now;
time(&now);