mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-29 15:42:20 +03:00
Устраняем ложное срабатывание крона при запуске МК
по причине преждевременной инициализации переменных до получения доверенного времени
This commit is contained in:
@@ -13,11 +13,12 @@ class Cron : public IoTItem {
|
|||||||
String _format = "";
|
String _format = "";
|
||||||
cron_expr _expr;
|
cron_expr _expr;
|
||||||
time_t _nextAlarm = 0;
|
time_t _nextAlarm = 0;
|
||||||
|
bool _isInit = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Cron(String parameters): IoTItem(parameters) {
|
Cron(String parameters): IoTItem(parameters) {
|
||||||
jsonRead(parameters, F("formatNextAlarm"), _format);
|
jsonRead(parameters, F("formatNextAlarm"), _format);
|
||||||
initCron();
|
if (_time_isTrust) initCron();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initCron() {
|
void initCron() {
|
||||||
@@ -39,6 +40,7 @@ class Cron : public IoTItem {
|
|||||||
if (forced || (_nextAlarm <= gmtTimeToLocal(unixTime))) {
|
if (forced || (_nextAlarm <= gmtTimeToLocal(unixTime))) {
|
||||||
// update alarm if next trigger is not yet in the future
|
// update alarm if next trigger is not yet in the future
|
||||||
_nextAlarm = cron_next(&_expr, gmtTimeToLocal(unixTime));
|
_nextAlarm = cron_next(&_expr, gmtTimeToLocal(unixTime));
|
||||||
|
_isInit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,6 +60,8 @@ class Cron : public IoTItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setValue(const IoTValue& Value, bool genEvent) {
|
void setValue(const IoTValue& Value, bool genEvent) {
|
||||||
|
if (!_time_isTrust) return;
|
||||||
|
|
||||||
value = Value;
|
value = Value;
|
||||||
_pause = false;
|
_pause = false;
|
||||||
initCron();
|
initCron();
|
||||||
@@ -74,6 +78,7 @@ class Cron : public IoTItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void doByInterval() {
|
void doByInterval() {
|
||||||
|
if (!_isInit && _time_isTrust) initCron();
|
||||||
if (!_pause && _time_isTrust && (gmtTimeToLocal(unixTime) >= _nextAlarm)) {
|
if (!_pause && _time_isTrust && (gmtTimeToLocal(unixTime) >= _nextAlarm)) {
|
||||||
updateNextAlarm(true);
|
updateNextAlarm(true);
|
||||||
bool _needSaveBak = _needSave;
|
bool _needSaveBak = _needSave;
|
||||||
|
|||||||
Reference in New Issue
Block a user