Skip to content

Second and third NTP servers are not working #4964

Closed
@szerwi

Description

@szerwi

Hardware:

Board: ESP32 Dev Module
Core Installation version: 1.0.5
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10

Description:

I am using SimpleTime example. I have added second and third NTP server, but when I change first NTP server's address to wrong one, it cannot obtain time. configTzTime() and configTime() are not using second and third NTP servers.

Sketch: (leave the backquotes for code formatting)

#include <WiFi.h>
#include "time.h"

const char* ssid       = "xxx";
const char* password   = "xxx";

const char* ntpServer = "wrong.ntp.org";
const char* ntpServer2 = "pl.pool.ntp.org";
const char* ntpServer3 = "3.pl.pool.ntp.org";
const long  gmtOffset_sec = 3600;
const int   daylightOffset_sec = 3600;

void printLocalTime()
{
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;
  }
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}

void setup()
{
  Serial.begin(115200);
  
  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }
  Serial.println(" CONNECTED");
  
  configTzTime("CET-1CEST,M3.5.0,M10.5.0/3", ntpServer, ntpServer2, ntpServer3);
  //configTime(gmtOffset_sec, daylightOffset_sec, ntpServer, ntpServer2, ntpServer3); //same situation
  printLocalTime();

  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);
}

void loop()
{
  delay(1000);
  printLocalTime();
}

Debug Messages:

Connecting to xxx [D][WiFiGeneric.cpp:374] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 2 - STA_START
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:419] _eventCallback(): STA IP: 192.168.1.113, MASK: 255.255.255.0, GW: 192.168.1.1
. CONNECTED
Failed to obtain time
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 5 - STA_DISCONNECTED
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 3 - STA_STOP
Failed to obtain time
Failed to obtain time
Failed to obtain time
Failed to obtain time

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions