mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2025-12-11 01:10:20 +01:00
Call getLocalTime() only once to prevent a delay of 10ms if no time is available
This commit is contained in:
@@ -70,17 +70,43 @@ void HoymilesClass::loop()
|
||||
iv->sendChangeChannelRequest();
|
||||
}
|
||||
|
||||
iv->sendStatsRequest();
|
||||
if (Utils::getTimeAvailable()) {
|
||||
// Fetch statistics
|
||||
iv->sendStatsRequest();
|
||||
|
||||
// Fetch event log
|
||||
const bool force = iv->EventLog()->getLastAlarmRequestSuccess() == CMD_NOK;
|
||||
iv->sendAlarmLogRequest(force);
|
||||
// Fetch event log
|
||||
const bool force = iv->EventLog()->getLastAlarmRequestSuccess() == CMD_NOK;
|
||||
iv->sendAlarmLogRequest(force);
|
||||
|
||||
// Fetch limit
|
||||
if (((millis() - iv->SystemConfigPara()->getLastUpdateRequest() > HOY_SYSTEM_CONFIG_PARA_POLL_INTERVAL)
|
||||
&& (millis() - iv->SystemConfigPara()->getLastUpdateCommand() > HOY_SYSTEM_CONFIG_PARA_POLL_MIN_DURATION))) {
|
||||
_messageOutput->println("Request SystemConfigPara");
|
||||
iv->sendSystemConfigParaRequest();
|
||||
// Fetch limit
|
||||
if (((millis() - iv->SystemConfigPara()->getLastUpdateRequest() > HOY_SYSTEM_CONFIG_PARA_POLL_INTERVAL)
|
||||
&& (millis() - iv->SystemConfigPara()->getLastUpdateCommand() > HOY_SYSTEM_CONFIG_PARA_POLL_MIN_DURATION))) {
|
||||
_messageOutput->println("Request SystemConfigPara");
|
||||
iv->sendSystemConfigParaRequest();
|
||||
}
|
||||
|
||||
// Fetch grid profile
|
||||
if (iv->Statistics()->getLastUpdate() > 0 && (iv->GridProfile()->getLastUpdate() == 0 || !iv->GridProfile()->containsValidData())) {
|
||||
iv->sendGridOnProFileParaRequest();
|
||||
}
|
||||
|
||||
// Fetch dev info (but first fetch stats)
|
||||
if (iv->Statistics()->getLastUpdate() > 0) {
|
||||
const bool invalidDevInfo = !iv->DevInfo()->containsValidData()
|
||||
&& iv->DevInfo()->getLastUpdateAll() > 0
|
||||
&& iv->DevInfo()->getLastUpdateSimple() > 0;
|
||||
|
||||
if (invalidDevInfo) {
|
||||
_messageOutput->println("DevInfo: No Valid Data");
|
||||
}
|
||||
|
||||
if ((iv->DevInfo()->getLastUpdateAll() == 0)
|
||||
|| (iv->DevInfo()->getLastUpdateSimple() == 0)
|
||||
|| invalidDevInfo) {
|
||||
_messageOutput->println("Request device info");
|
||||
iv->sendDevInfoRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set limit if required
|
||||
@@ -95,29 +121,6 @@ void HoymilesClass::loop()
|
||||
iv->resendPowerControlRequest();
|
||||
}
|
||||
|
||||
// Fetch dev info (but first fetch stats)
|
||||
if (iv->Statistics()->getLastUpdate() > 0) {
|
||||
const bool invalidDevInfo = !iv->DevInfo()->containsValidData()
|
||||
&& iv->DevInfo()->getLastUpdateAll() > 0
|
||||
&& iv->DevInfo()->getLastUpdateSimple() > 0;
|
||||
|
||||
if (invalidDevInfo) {
|
||||
_messageOutput->println("DevInfo: No Valid Data");
|
||||
}
|
||||
|
||||
if ((iv->DevInfo()->getLastUpdateAll() == 0)
|
||||
|| (iv->DevInfo()->getLastUpdateSimple() == 0)
|
||||
|| invalidDevInfo) {
|
||||
_messageOutput->println("Request device info");
|
||||
iv->sendDevInfoRequest();
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch grid profile
|
||||
if (iv->Statistics()->getLastUpdate() > 0 && (iv->GridProfile()->getLastUpdate() == 0 || !iv->GridProfile()->containsValidData())) {
|
||||
iv->sendGridOnProFileParaRequest();
|
||||
}
|
||||
|
||||
_messageOutput->printf("Queue size - NRF: %" PRId32 " CMT: %" PRId32 "\r\n", _radioNrf->getQueueSize(), _radioCmt->getQueueSize());
|
||||
_lastPoll = millis();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -6,4 +6,5 @@
|
||||
class Utils {
|
||||
public:
|
||||
static uint8_t getWeekDay();
|
||||
};
|
||||
static bool getTimeAvailable();
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user