未验证 提交 34125cee 编写于 作者: V vortigont 提交者: GitHub

Examples update, add a note for configTime() that only one ntp server is supported by lwip (#5343)

lwip lib bundled with esp32 Arduino supports only one ntp server. Any additional servers set are just silently ignored.
This default is different from esp8266 Arduino core and very confusing. Most of the examples provided uses 3 different ntp servers for redundancy while only the first one is used actually.
Addressing issue #4964
上级 ee247360
...@@ -44,6 +44,8 @@ static void setTimeZone(long offset, int daylight) ...@@ -44,6 +44,8 @@ static void setTimeZone(long offset, int daylight)
/* /*
* configTime * configTime
* Source: https://github.com/esp8266/Arduino/blob/master/cores/esp8266/time.c * Source: https://github.com/esp8266/Arduino/blob/master/cores/esp8266/time.c
* Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored
* see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig
* */ * */
void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3) void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
{ {
...@@ -63,6 +65,8 @@ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1, ...@@ -63,6 +65,8 @@ void configTime(long gmtOffset_sec, int daylightOffset_sec, const char* server1,
/* /*
* configTzTime * configTzTime
* sntp setup using TZ environment variable * sntp setup using TZ environment variable
* Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored
* see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig
* */ * */
void configTzTime(const char* tz, const char* server1, const char* server2, const char* server3) void configTzTime(const char* tz, const char* server1, const char* server2, const char* server3)
{ {
......
...@@ -148,6 +148,10 @@ void setup(){ ...@@ -148,6 +148,10 @@ void setup(){
Serial.println("IP address: "); Serial.println("IP address: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
Serial.println("Contacting Time Server"); Serial.println("Contacting Time Server");
/*
Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored
see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig
*/
configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
struct tm tmstruct ; struct tm tmstruct ;
delay(2000); delay(2000);
......
...@@ -17,6 +17,10 @@ WiFiMulti WiFiMulti; ...@@ -17,6 +17,10 @@ WiFiMulti WiFiMulti;
// Set time via NTP, as required for x.509 validation // Set time via NTP, as required for x.509 validation
void setClock() { void setClock() {
/*
Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored
see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig
*/
configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // UTC configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // UTC
Serial.print(F("Waiting for NTP time sync: ")); Serial.print(F("Waiting for NTP time sync: "));
......
...@@ -160,6 +160,10 @@ void setup(){ ...@@ -160,6 +160,10 @@ void setup(){
Serial.println("IP address: "); Serial.println("IP address: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
Serial.println("Contacting Time Server"); Serial.println("Contacting Time Server");
/*
Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored
see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig
*/
configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
struct tm tmstruct ; struct tm tmstruct ;
delay(2000); delay(2000);
......
...@@ -164,6 +164,10 @@ void setup(){ ...@@ -164,6 +164,10 @@ void setup(){
Serial.println("IP address: "); Serial.println("IP address: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
Serial.println("Contacting Time Server"); Serial.println("Contacting Time Server");
/*
Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored
see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig
*/
configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
struct tm tmstruct ; struct tm tmstruct ;
delay(2000); delay(2000);
......
...@@ -164,6 +164,10 @@ void setup(){ ...@@ -164,6 +164,10 @@ void setup(){
Serial.println("IP address: "); Serial.println("IP address: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
Serial.println("Contacting Time Server"); Serial.println("Contacting Time Server");
/*
Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored
see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig
*/
configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
struct tm tmstruct ; struct tm tmstruct ;
delay(2000); delay(2000);
......
...@@ -148,6 +148,10 @@ void setup(){ ...@@ -148,6 +148,10 @@ void setup(){
Serial.println("IP address: "); Serial.println("IP address: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
Serial.println("Contacting Time Server"); Serial.println("Contacting Time Server");
/*
Note: Bundled Arduino lwip supports only ONE ntp server, 2nd and 3rd options are silently ignored
see CONFIG_LWIP_DHCP_MAX_NTP_SERVERS define in ./tools/sdk/esp32/sdkconfig
*/
configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); configTime(3600*timezone, daysavetime*3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org");
struct tm tmstruct ; struct tm tmstruct ;
delay(2000); delay(2000);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册