Page 2 of 3

Re: ESP8266 - NTP server request issue

PostPosted: Fri Oct 11, 2019 8:03 pm
by davydnorris
I don't use Arduino much, but this is the library I have always used for NTP when I do

maybe try a different library?

Here's a sample sketch based on this lib - credit to the original coder

Code: Select all#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

// Replace with your network credentials
const char* ssid     = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

// Define NTP Client to get time
NTPClient timeClient(ntpUDP);

// Variables to save date and time
String formattedDate;
String dayStamp;
String timeStamp;

void setup() {
  // Initialize Serial Monitor
  Serial.print("Connecting to ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  // Print local IP address and start web server
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");

// Initialize a NTPClient to get time
  // Set offset time in seconds to adjust for your timezone, for example:
  // GMT +1 = 3600
  // GMT +8 = 28800
  // GMT -1 = -3600
  // GMT 0 = 0
void loop() {
  while(!timeClient.update()) {
  // The formattedDate comes with the following format:
  // 2018-05-28T16:00:13Z
  // We need to extract date and time
  formattedDate = timeClient.getFormattedDate();

  // Extract date
  int splitT = formattedDate.indexOf("T");
  dayStamp = formattedDate.substring(0, splitT);
  Serial.print("DATE: ");
  // Extract time
  timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1);
  Serial.print("HOUR: ");

Re: ESP8266 - NTP server request issue

PostPosted: Sat Oct 12, 2019 3:09 am
by schufti
why is everybody messing around with 3rd party ntp libs when arduino esp core brings an integrated solution?

Re: ESP8266 - NTP server request issue

PostPosted: Sat Oct 12, 2019 6:03 am
by Bebeno
Hi all.
davydnorris - I downloaded library from link and tried your code but there was still issue during compilation.
I removed all libraries from Arduino IDE and according - schufti - advice I used again example code from ESP8266 >> NTPclient and it finaly started work. It is strange. I used all this examples before but without positive result for me. But now :-)

Guys thanks a lot for help. Now I can continu on my project.

Re: ESP8266 - NTP server request issue

PostPosted: Sun Oct 20, 2019 4:48 pm
by davydnorris
I think the library I pointed to is the one in Arduino core - as I said, I really don't use Arduino much

Glad you got it all working!