mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
limit thermostat time set to 3 tries, check dst flag #2142
This commit is contained in:
@@ -1562,25 +1562,33 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t setTimeRetry = 0;
|
static uint8_t setTimeRetry = 0;
|
||||||
|
uint8_t dst = 0xFE;
|
||||||
|
bool use_dst = !telegram->read_value(dst, 9) || dst == 0xFF;
|
||||||
if ((telegram->message_data[7] & 0x0C) && has_command(&dateTime_)) { // date and time not valid
|
if ((telegram->message_data[7] & 0x0C) && has_command(&dateTime_)) { // date and time not valid
|
||||||
if (setTimeRetry < 3) {
|
if (setTimeRetry < 3) {
|
||||||
set_datetime("ntp", -1); // set from NTP
|
if (!use_dst) {
|
||||||
|
set_datetime("ntp", 0); // set from NTP without dst
|
||||||
|
} else {
|
||||||
|
set_datetime("ntp", -1); // set from NTP
|
||||||
|
}
|
||||||
setTimeRetry++;
|
setTimeRetry++;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check clock
|
// check clock
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
tm * tm_ = localtime(&now);
|
tm * tm_ = localtime(&now);
|
||||||
bool tset_ = tm_->tm_year > 110; // year 2010 and up, time is valid
|
bool tset_ = tm_->tm_year > 110; // year 2010 and up, time is valid
|
||||||
tm_->tm_year = (telegram->message_data[0] & 0x7F) + 100; // IVT
|
tm_->tm_year = (telegram->message_data[0] & 0x7F) + 100; // IVT
|
||||||
tm_->tm_mon = telegram->message_data[1] - 1;
|
tm_->tm_mon = telegram->message_data[1] - 1;
|
||||||
tm_->tm_mday = telegram->message_data[3];
|
tm_->tm_mday = telegram->message_data[3];
|
||||||
tm_->tm_hour = telegram->message_data[2];
|
tm_->tm_hour = telegram->message_data[2];
|
||||||
tm_->tm_min = telegram->message_data[4];
|
tm_->tm_min = telegram->message_data[4];
|
||||||
tm_->tm_sec = telegram->message_data[5];
|
tm_->tm_sec = telegram->message_data[5];
|
||||||
tm_->tm_isdst = telegram->message_data[7] & 0x01;
|
if (use_dst) {
|
||||||
|
tm_->tm_isdst = telegram->message_data[7] & 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
// render date to DD.MM.YYYY HH:MM and publish
|
// render date to DD.MM.YYYY HH:MM and publish
|
||||||
char newdatetime[sizeof(dateTime_)];
|
char newdatetime[sizeof(dateTime_)];
|
||||||
@@ -1595,7 +1603,11 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
|
|||||||
double difference = difftime(now, ttime);
|
double difference = difftime(now, ttime);
|
||||||
if (difference > 15 || difference < -15) {
|
if (difference > 15 || difference < -15) {
|
||||||
if (setTimeRetry < 3) {
|
if (setTimeRetry < 3) {
|
||||||
set_datetime("ntp", -1); // set from NTP
|
if (!use_dst) {
|
||||||
|
set_datetime("ntp", 0); // set from NTP without dst
|
||||||
|
} else {
|
||||||
|
set_datetime("ntp", -1); // set from NTP
|
||||||
|
}
|
||||||
LOG_INFO("thermostat time correction from ntp");
|
LOG_INFO("thermostat time correction from ntp");
|
||||||
setTimeRetry++;
|
setTimeRetry++;
|
||||||
}
|
}
|
||||||
@@ -2694,8 +2706,8 @@ bool Thermostat::set_datetime(const char * value, const int8_t id) {
|
|||||||
data[3] = tm_->tm_mday;
|
data[3] = tm_->tm_mday;
|
||||||
data[4] = tm_->tm_min;
|
data[4] = tm_->tm_min;
|
||||||
data[5] = tm_->tm_sec;
|
data[5] = tm_->tm_sec;
|
||||||
data[6] = (tm_->tm_wday + 6) % 7; // Bosch counts from Mo, time from Su
|
data[6] = (tm_->tm_wday + 6) % 7; // Bosch counts from Mo, time from Su
|
||||||
data[7] = tm_->tm_isdst + 2; // set DST and flag for ext. clock
|
data[7] = (id == 0) ? 2 : tm_->tm_isdst + 2; // set DST and flag for ext. clock
|
||||||
if (model() == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) {
|
if (model() == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) {
|
||||||
data[6]++; // Junkers use 1-7;
|
data[6]++; // Junkers use 1-7;
|
||||||
data[7] = 0;
|
data[7] = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user