RaspberryPi NTP server messed by node red?

Here is the description of my system:
I have an ESP32 which connect to a Raspberry Pi configured as an access point.
On my raspberry pi i have a NTP server : I installed ntpd and i modify the ntpd.conf to add the lines:

server 127.127.1.0 prefer 
fudge 127.127.1.0 stratum 12

on my Esp32, I use the library NTPClient.h (GitHub - WhymustIhaveaname/NTPClient: Connect to a NTP server which is a forked that provide milliseconds). The NTP updates are "overkill" for debuging: every 5 seconds, and then display the time every 10ms.

I am keeping developing my system which would require MQTT. Therefore I am using Node-Red.
For now, my simple code does not have any MQTT connection, just sending/receiving NTP paquets.

The issue:
I run the code for few minutes, and I get the real time.
After few minute, i launch node-red, and once everything is properly loaded, the NTP update is completely messed up.

23:43:29.310
23:43:29.320
23:43:29.330
23:43:29.340
23:43:29.350
23:43:29.360
23:43:29.370
23:43:29.380
23:43:29.390
23:43:29.400
23:43:29.410
23:43:29.420
23:43:29.430
23:43:29.440
23:43:29.450
23:43:29.460
sent ntp packet
got ntp packet.
tik, tok, (tok-tik)/2: 347774, 347794, 10.00
receive_int, transmit_int: 0, 0
receive_dec, transmit_dec: 0, 0.000000, 0, 0.000000
current Epoc: 2085978496 0.010000
06:28:16.016
06:28:16.026
06:28:16.036
06:28:16.046
06:28:16.056
06:28:16.066
06:28:16.076
06:28:16.086
06:28:16.096
06:28:16.106
06:28:16.116
06:28:16.126
06:28:16.136
06:28:16.146

I did the test few times, and each time the updated times is exactly 06:28:16, it increases to 06:28:26, then reset to 06:28:16

The main issue: on the boot
If node red is launched the first NTP request provide always the same time: 04:39:39 which is later updated to 06:28:16

Are you aware of a potential interaction between node-red and the ntp server?

Thank you
Sylvain

The first thing that gets my attention is the IP address.

127.x.x.x is for local use only and no other machine can use them.

Try an IP address which is part of the range used by the WAP.

Thanks, sorry I was wrong with node-red causing issues. I am not sure if this is the right forum then.
I changed the IP address to 192.168.5.2 (my AP is on 192.168.5.1, and release Ip adress from 192.168.5.100 to 192.168.5.200) . Is it the correct choice, or should I set it tp 192.168.5.1?

SB

OK, I just typed:

sudo service ntp restart

and it solved the issue (till when?). Any specialist on this?

After few tests decreasing the request time down to 100ms, I confirm the issues are caused by the too small time allowed for the NTP update.

ntp queries are normally done in a timescale of seconds not ms. Doing queries that fast risks flooding the server.

Also if you really need extra accuracy, you need to configure multiple ntp servers and have them also sync externally of course. A minimum of 3 or 4 seems to be the recommendation.

You can make it the same IP address as the AP.

IP numbers are not ..... limited to what you can have on them.
So your access point can also be the NTP server.

But you can't have two respberry pies with the same IP.

As to which IP address, well, you could also use DHCP, but I would suggest having a fixed one.

Thank you so much,
I used the sparkfun tutorial to setup my AP. I am quite a newbie with all these things but finally converging towards some solution.

@TotallyInformation: do you think I could modify my ntpd.conf as follow:

server 192.168.5.1 prefer
server 192.168.5.2 prefer 
server 192.168.5.3 prefer 
server 192.168.5.4 prefer 
fudge 192.168.5.1 stratum 12
fudge 192.168.5.2 stratum 12
fudge 192.168.5.3 stratum 12
fudge 192.168.5.4 stratum 12

my NTPClient function on my esp32 will remain the same:
NTPClient timeClient(ntpUDP, "192.168.5.1 ", 0, 1800000);//one request every 30min

Sorry, I'm no expert on NTP I'm afraid. You would need to do some searching to find the best setup. You need to set up a hierarchy of internal and external NTP servers with the external servers referencing one of the "pool" servers so that they get load balanced. You also need to make sure that you aren't hitting external NTP servers too often or you will probably get banned (it is, after all, a free service).

Frankly, I use the default settings for my OS (Debian/Rasbian) to set my servers timesync. For my ESP devices, I use an NTP library (or whatever is built into ESPEasy or Tasmota if I'm using those firmwares) and also set them to use external NTP. As I'm in the UK, I use the UK pool server. This is sufficient for me and I've never had to worry about time but I'm certainly not trying to look for ms time sync. As long as my times are accurate to the second, that is plenty for me.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.