Skip to content

Commit

Permalink
Fix old config compatibility for timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
matjack1 committed Nov 14, 2023
1 parent 48b329c commit 973cdc3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/config.esp
Original file line number Diff line number Diff line change
Expand Up @@ -171,27 +171,30 @@ bool ICACHE_FLASH_ATTR loadConfiguration(Config &config)
config.ntpServer = strdup(ntp["server"]);
}
config.ntpInterval = ntp["interval"];
if (ntp.containsKey("tzinfo"))
{
config.tzInfo = strdup(ntp["tzinfo"]);
}

// support for old config
if (ntp.containsKey("timezone"))
{
config.tzInfo = (char *) malloc(10 * sizeof(char));
float tz = ntp["timezone"];
if(tz > 0)
{
sprintf(config.tzInfo, "UTC+%f", tz);
snprintf(config.tzInfo, 10, "UTC+%.2f", tz);
}
else if(tz < 0)
{
sprintf(config.tzInfo, "UTC-%f", tz);
snprintf(config.tzInfo, 10, "UTC-%.2f", tz);
}
else
{
sprintf(config.tzInfo, "UTC");
snprintf(config.tzInfo, 10, "UTC");
}
}
if (ntp.containsKey("tzinfo"))
{
config.tzInfo = (char *) malloc(strlen(ntp["tzinfo"]) * sizeof(char));
config.tzInfo = strdup(ntp["tzinfo"]);
}
config.activateTime[0] = hardware["rtime"];
config.lockType[0] = hardware["ltype"];
config.relayType[0] = hardware["rtype"];
Expand Down

0 comments on commit 973cdc3

Please sign in to comment.