NTPClient
NTPClient copied to clipboard
not getting any data
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?
Same here..
Same here
any solutions?
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());
Thanks 32u-nd. My previous code come back to work without any action, but I included your suggestion as good practice.
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.
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.
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.
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
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.