NTPClient icon indicating copy to clipboard operation
NTPClient copied to clipboard

not getting any data

Open Soumojit28 opened this issue 4 years ago • 10 comments

I am trying to run the example sketch, when I connect to my phone hotspot it provides correct time data but when I connect to my wifi router I only get 00:00:00 and it starts counting from it and if I reset I again get 00:00:00, any ideas why this happening?

Soumojit28 avatar Mar 30 '20 18:03 Soumojit28

Same here..

ireun avatar Apr 01 '20 10:04 ireun

Same here

flaviopuhl avatar Apr 01 '20 13:04 flaviopuhl

any solutions?

Soumojit28 avatar Apr 02 '20 17:04 Soumojit28

I had the same issue all with my Wemos D1 boards. The solution for me was to ensure the correct WiFi mode. All my Wemos D1 were configured with mode 3. After changing to mode 1, it was fine :).

#include <ESP8266WiFi.h>
WiFi.begin(WLAN_SSID, WLAN_PSK);

...

/* ensure WIFI_STA mode */
Serial.print("Current WiFi mode = ");
Serial.println(WiFi.getMode());
Serial.print("Set to WIFI_STA mode = ");
WiFi.mode(WIFI_STA); // WIFI_STA = 1
Serial.println(WiFi.getMode());

32u-nd avatar Apr 16 '20 08:04 32u-nd

Thanks 32u-nd. My previous code come back to work without any action, but I included your suggestion as good practice.

flaviopuhl avatar Apr 16 '20 19:04 flaviopuhl

I have the same problem with WeMos D1 Mini. Everytime it connects to WiFi router it gets 00:00:00 and it starts counting from it. Even with the "32u-nd" code (thanks), and ensuring WIFI_STA mode, I have always the same result.
Any idea? Thanks.

Antracita426 avatar Apr 23 '20 16:04 Antracita426

Hello everybody! My research on the issue has shown that any problem with network parameters can be the cause. For example, if the device does not use DHCP, you must correctly specify not only the main network parameters, but also do not forget about DNS. Otherwise, WiFi.hostByName will not be able to correctly recognize the IP address of the specified time-server. The error message will not be displayed, but the sketch will not work either.

michaelSapegin avatar Apr 24 '20 05:04 michaelSapegin

Hello Michael, Thank you very much for your quick answer. Right, I am configuring WiFi with fixed IP, but I do not define the DNS. Find following my config code:

#include <NTPClient.h> //importamos la librería del cliente NTP #include <ESP8266WiFi.h> //librería necesaria para la conexión wifi #include <WiFiUdp.h> // importamos librería UDP para comunicar con NTP

const char* ssid = "XXXXXXXXXXXXXXX"; // WIFI network SSID const char* password = "XXXXXXXXXXXXXXXX"; // WIFI network PASSWORD IPAddress ip(192,168,0,175); IPAddress gateway(192,168,0,1); IPAddress subnet(255,255,255,0);

WiFiUDP ntpUDP;

NTPClient timeClient(ntpUDP, "es.pool.ntp.org",0,6000);

void setup(){ Serial.begin(9600); WiFi.config(ip, gateway, subnet); WiFi.mode(WIFI_STA); // Config module as station only. WiFi.begin(ssid, password); // nos conectamos al wifi …

I thought that the router took care of the DNS. Otherwise, I do not know how to configure them on the code. I will have to check. Any idea? Beside this, do I have to open any port on the router to make the sketch run? Thank you again for your time.

Antracita426 avatar Apr 24 '20 09:04 Antracita426

Just add this definition: IPAddress dns(192,168,0,1); // set your right dns

and in setup() change this: WiFi.config(ip, gateway, subnet, dns);

In full form it may be WiFi.config(ip, gateway, subnet, dns1, dns2);

NTP uses special port 123, I think you don't have to open it in router

michaelSapegin avatar Apr 24 '20 09:04 michaelSapegin

Hi Michael, Great, great, great, …, Yessss! I added yours advices, and it is working pretty well, now. Thank you very much, indeed, for your help. I wonder if it will change from summer and winter time on the dates? Best regards, and … thanks once more.

Antracita426 avatar Apr 24 '20 15:04 Antracita426