Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cores/esp32/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion cores/esp32/esp32-hal-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down