NTP not working on ESP32

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Bert'Ridder
Normal user
Posts: 11
Joined: 08 Jan 2018, 13:15

NTP not working on ESP32

#1 Post by Bert'Ridder » 30 Dec 2022, 18:31

Hi,

As the ESP32 Wemos D1 R32 is getting cheaper and more available, I have now 2 ESP32's running with ESP-Easy.

One issue there is still there is that the Systemtime is always starting to go into 1970, althoug the NTP is set to nl.pool.ntp.org. This is the same as I use on all my ESP-Mega 8266's.

But somehow the Systemtime is not set to the current time.

System Info
Unit Number: 201
Git Build: mega-20221224_35f2ff8
Local Time: 1970-01-03 02:43:18
Time Source: No time set
Uptime: 2 days 2 hours 43 minutes
In the Systemlog:

Code: Select all

182725127: NTP : NTP host nl.pool.ntp.org (0.0.0.0) queried
182726130: NTP : No reply

I have tried several Build's:
ESP_Easy_mega_20221224_collection_E_ESP32_4M316k
ESP_Easy_mega_20221105_collection_A_ESP32_4M316k
ESP_Easy_mega_20220616_test_E_ESP32s2_4M316k


Also, and I suspect the same cause, the Timing for the systemvarables about the Sunset etc is also not working, although the GPS-coordinates are set.
Sunrise/Sunset
%sunset% 0:00 0%3a00
%sunset-1h% 5:28 5%3a28
%sunrise% 0:00 0%3a00
%sunrise+10m% 6:38 6%3a38
%s_sunset% 0 0
%s_sunrise% 0 0
%m_sunset% 0 0
%m_sunrise% 0 0
Is this a known issue on the ESP32's? Or is there an special parameter to be set ?
Who can help me?

User avatar
Ath
Normal user
Posts: 3494
Joined: 10 Jun 2018, 12:06
Location: NL

Re: NTP not working on ESP32

#2 Post by Ath » 30 Dec 2022, 19:04

Bert'Ridder wrote: 30 Dec 2022, 18:31 As the ESP32 Wemos D1 R32 is getting cheaper and more available, I have now 2 ESP32's running with ESP-Easy.

One issue there is still there is that the Systemtime is always starting to go into 1970, althoug the NTP is set to nl.pool.ntp.org. This is the same as I use on all my ESP-Mega 8266's.
Ever since I started using ESPEasy, back in 2018, I've never set the NTP hostname (after finding guidance in this forum that it should best be left empty), only just set the checkbox "Use NTP", and it always worked right out of the box. Same for ESP32, once I started using those.
So, I'd first start with clearing the "NTP Hostname" field, and then reboot the unit to let NTP sync up the date/time.

Most important requirement, obviously, is that the units have access to internet, and are allowed to connect over UDP using port 1023, but as it is working for your ESP8266's that is an unlikely cause.
Are the other network settings, on the Config page, similar to the ESP8266 units? Especially when using a fixed IP setup (IP, Gateway, Subnet mask and DNS set) the Subnet mask must match with that setting on the Gateway and DNS, or else they won't be able to communicate properly. Using DHCP (leaving those 4 fields empty) will make life easier when using external services.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8739
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: NTP not working on ESP32

#3 Post by TD-er » 30 Dec 2022, 22:01

Looks like you either can't reach the gateway, and/or the DNS server.
Are you using DHCP or static IP?

The fact it shows 0.0.0.0 in the logs are a good indication the ESP cannot resolve the hostname of the NTP server.

Bert'Ridder
Normal user
Posts: 11
Joined: 08 Jan 2018, 13:15

Re: NTP not working on ESP32

#4 Post by Bert'Ridder » 31 Dec 2022, 15:48

Thank you both.

You were both right.

I have the ESP's on a Static IP, because then they remain on the same IP-Adres when a reset is done (I have somtimes a reset on the ruter and then the IP-dressses gets mixed up.).
On the ESP32 to go on Static IP-Adresses I have to fiill in the whole set of fields. On the ESP-Mega (8266) it is okay to only fill in the statis IP-Adres and leve the Gateway and DNS empty. That mixed up the DNS to the NTP-server.

I found out that when I change on one ESP32 (#201) this settings to DHCP, on the other ESP32 (#202), the time is synchronized by the ESPEasy p2p connection.
System Info
Unit Number: 202
Git Build: mega-20221224_35f2ff8
Local Time: 2022-12-31 15:34:18
Time Source: ESPEasy p2p (201)
Uptime: 0 days 3 hours 13 minutes
So for now, I know the cause and can work around it by setting up, on ESP32 with DHCP (that differs to the Mega on the 266).

A static IP-Adres can work, but then I have to set the Wfi DNS to the IP-Adres of my provider ( global- IP-adres)

Thanks for the help.

User avatar
Ath
Normal user
Posts: 3494
Joined: 10 Jun 2018, 12:06
Location: NL

Re: NTP not working on ESP32

#5 Post by Ath » 31 Dec 2022, 16:44

Bert'Ridder wrote: 31 Dec 2022, 15:48 On the ESP32 to go on Static IP-Adresses I have to fiill in the whole set of fields. On the ESP-Mega (8266) it is okay to only fill in the statis IP-Adres and leve the Gateway and DNS empty. That mixed up the DNS to the NTP-server.
On ESP8266 it is also required to set all 4 fields (IP, Gateway, Netmask, DNS) when configuring a static IP, that it has worked in your setup is sheer luck (or bad karma, can't decide :lol:).

NB: I have all my ESP's (ESP8266 and ESP32 and ESP32s2) using fixed IP configuration, for the same reason, to avoid having to search for the new IPs after a router restart. Without setting all 4 fields it never would work reliably with a fixed IP address.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8739
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: NTP not working on ESP32

#6 Post by TD-er » 01 Jan 2023, 02:06

Most routers support to assign a fixed IP address to some MAC addresses.
However I know some providers (<kuch> KPN </>) sometimes tend to clear all settings in your router for no reason at all other than just letting those users know who's boss.
Others (<kuch> Ziggo </>) will send out some clear command whenever a user dares to call the hell-desk.

So I know why you would want to use static IP.

However, for access beyond your own network, you need to have a gateway.
And simply setting the IP of the router as DNS is not enough if you need to access some NTP server outside your own network.
N.B. some routers also have a NTP service running, so for those you can set the IP of the router as NTP server. That's the only way to use NTP without setting a gateway and/or DNS IP address.

Post Reply

Who is online

Users browsing this forum: No registered users and 96 guests