add configTzTime() to setup sntp using TZ environment variable (#608)

This commit is contained in:
Mark D 2017-09-05 04:15:55 -04:00 committed by Me No Dev
parent 0f83dbcfd6
commit 234c855c9b
2 changed files with 20 additions and 1 deletions

View File

@ -168,6 +168,8 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 10
extern "C" bool getLocalTime(struct tm * info, uint32_t ms = 5000);
extern "C" void configTime(long gmtOffset_sec, int daylightOffset_sec,
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);
extern "C" void configTzTime(const char* tz,
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);
// WMath prototypes
long random(long);

View File

@ -45,7 +45,6 @@ static void setTimeZone(long offset, int daylight)
* */
void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
{
if(sntp_enabled()){
sntp_stop();
}
@ -57,6 +56,24 @@ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1,
setTimeZone(gmtOffset_sec, daylightOffset_sec);
}
/*
* configTzTime
* sntp setup using TZ environment variable
* */
void configTzTime(const char* tz, const char* server1, const char* server2, const char* server3)
{
if(sntp_enabled()){
sntp_stop();
}
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, (char*)server1);
sntp_setservername(1, (char*)server2);
sntp_setservername(2, (char*)server3);
sntp_init();
setenv("TZ", tz, 1);
tzset();
}
bool getLocalTime(struct tm * info, uint32_t ms)
{
uint32_t count = ms / 10;