arduino-libraries / NTPClient

Connect to a NTP server
542 stars 372 forks source link

Not correct time between laptop's time and NTPClient's time! #100

Closed lhp1507 closed 4 years ago

lhp1507 commented 4 years ago

Hi everyone, I have an issue: I use exactly the Advance example from NTPClient library and upload it to my nodeMCU kit. But the time is not correct (photo attached). This Do you know the problem? Please let me know. Thank you! All the best.

Here is my code:

#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char *ssid     = "Hoang Hung 2";
const char *password = "09061997";

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "0.asia.pool.ntp.org", 7*3600, 60000);

void setup(){
  Serial.begin(115200);

  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  timeClient.begin();
}

void loop() {
  timeClient.update();

  Serial.println(timeClient.getFormattedTime());

  delay(1000);
}

image

IsakAlmgren commented 4 years ago

The code looks okay. So that means that either the ntp server has incorrect time or your laptop does. I'd bet it's your laptop time that is off, go google something like "Troubleshooting for Windows Time Service" and see if that helps. Otherwise, try switching to a different ntp pool.

lhp1507 commented 4 years ago

Oh, Thank you 3000 for your help <3 I think it's caused exactly you said. Respectfully, Phu.