-
Notifications
You must be signed in to change notification settings - Fork 12
Resync NTP regurlarly #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Seems ok |
Let's wait at least for the results of the tests of @McMagellan |
The rescheduling is done twice: both in |
@RichieB2B Two things. The difference in time was indeed wrong. However, the double call to |
@CurlyMoo So an extra call to timerqueue_inserts(x, y, -5) would just reset the previous timer. That's much less of an issue than I thought but still good to avoid it. |
@RichieB2B Exactly. |
Feedback: Testing time synchronization. Alpha-467a907, Egyras#527 Method:
|
@CurlyMoo why not use some basic logic, just 2 variables, one boolen for time sync'ed flag, and one last time synced (timestamp after timesync) and check by that.. if it's never synced (try every 5min) and if synced try after last sync_time timeout. |
That's what we're basicly doing here, but centralized through the timepool. |
Oh, sorry, i saw somewhere you mentioned exact dates.. so thought it tied to dates :) didn't check source. |
It does, because by definition unix time starts on the 1st of januari 1970. So, checking for a year other than 1970 is similar to that sync flag but with more accuracy of success. |
@McMagellan Can you let it run again for a while and check for the |
Feedback: Testing time synchronization. Alpha baddb94, Egyras#531 How I do it:
LED WLAN and DSL on Fritzbox1 flash for about 5 - 6 minutes until the PC browser is connected to the WLAN again. For the next attempt, I activated "Debug log to MQTT topic from start" to have the messages recorded in the influxdb immediately after reconnection. The timestamp at the beginning of the line comes from the Raspberry. |
@CurlyMoo: How can i do this? |
I did another test on synchronizing the date and time. This process was recorded in the first console window. You can see that the time has been updated. Security notice: |
Please do! |
Why do you need two timers? The code from timer -6 could look like this:
and then in systemboot just call it after a minute.
And then delete timer -5... |
Because in your case you're always doing a |
Only once, right after the systemboot.
and
|
Same thing. You are already doing a ntpReload while you haven't checked if the previous ntpReload succeeded. |
And i don't see why using two timers is an issue? They're not active at the same time so aren't a performance issue at all. |
It is just doing it the other way around:
It is less code and easier to read. Less code is easier to maintain. |
No it isn’t, because ntpReload is an async function.
|
HeishaMon/HeishaMon.ino
Outdated
/* | ||
* Wait 300 sec less than a full day | ||
*/ | ||
logprintln_P(F("Syncing with ntp servers, check again in a day")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log should change to:
Succesfully synced with ntp servers, checking again in a day
In the logs by @McMagellan it works fine everytime. @IgorYbema The only thing that confuses me is that in the HeishaMon/HeishaMon/HeishaMon.ino Line 172 in efec856
|
I repeated today the ntp test and this time it didn't work. Initial situation:
Then Starts the Debug Logfile 29bputty.log.
I then waited 40 minutes and the running log file showed that no synchronization had taken place.
Normal start of Heishamon because the WLAN environment was ntp-sync again at this time. What I also saw are several web server connections like this: The IP address is that of your own access point?? |
What I also saw is a hole in the MQTT bulk transmission shortly after the correct time synchronization. Thu Aug 29 13:15:59 2024 (11160): received TOP104 Solar_Frost_Protection: 5 TOP111 to TOP115 are missing here. Never seen bevore. |
Let's zoom out a bit. Until now we have been suspecting the NTP additions are the ones that are faulty, but i would like to focus first on correct functioning of the @McMagellan @stumbaumr can you guys monitor in the difference tests how long it takes for the wifi to connect, how long it takes for the first ntp sync message to appear in the log, and how long it takes before the time is set correctly? |
You can clearly see it in the last log So focussing on the ntp sync without a proper wifi connection is useless. |
Here is the information from the system log of the two Fritz boxes after power on at 12:35 (time stamp from the start of the Putty file). Sorry it's German. Systemlog Fritzbox1 DSL.pdf The first message in the log is around 12:37, although it is unclear to me where the Fritzbox got this time because no ntp sync could take place yet. Maybe from the DSL Training Start Message. The first WiFi device logs on to the network at 12:37:08. At 12:40:10 DSL IP V4 was connected to Fritzbox1 At 12:40:11 the message about successful time synchronization comes after two unsuccessful attempts. Heishamon only logged on to the network at 13:15:56 after the manual reboot with the IP address 192.168.178.36. |
The reason why it didn't connect to wifi is, I believe, due to that you have connected to the AP:
However, it should not report this message after that: I'll check the NTP code |
This is all correct. It started syncing just after the first wifi reconnect (after 17 mins):
"Could connect to the webserver" does that maybe mean using the AP 192.168.4.1? As said, this causes the heishamon not to retry connecting to the main wifi as it thinks the user is configuring the heishamon. |
No, there was knowingly no connection from the laptop or desktop to the AP. Or does Heishamon connect with itself? See extraction from last Logfile. First line is the timestamp- info cause the webserver entries have no timestamp, whatever.
|
Seems you do have a client connecting to it. Maybe a phone you used before and is now auto connecting? |
In the past, I actually used the Heishamon AP to connect my cell phone to the normal WiFi in the settings in the event of a factory reset. I will repeat the test and first turn off my cell phone. |
Feedback new Test: ntp sync. The test was manually stopped after 20 minutes without the time being synchronized. However, all network connections were then disconnected. There is only one webserver call in the 20 minutes: This IP address is the Fritzbox2 which runs as a MESH- repeater. |
It reconnected ok. The time sync failed. Was DSL trained already?
|
What i also find wierd is that the subsequent check is suddenly: Whilst the year is still 1970. |
@IgorYbema:The timing in the Fritzbox is always the same. There are only minimal time differences between the network master and the repeater (MESH). To me it looks like Heishamon checks whether the last network connection is available just a few seconds after starting. |
So Heishamon reconnected at 3:33 to the wifi. No not at that time. Retry at 8:33 failed to sync. Thanks. I'll try to find out why |
So probably the year == 1970 check is wrong. That is why it flips over to next day check and doesnt run a ntpReload. |
tm_year = years since 1900... Patching this stupid one |
Build Egyras#587 from https://github.com/IgorYbema/HeishaMon/actions/runs/10634643077 can be used to test |
It again proves the need of reviews. |
logprintln_P(F("Syncing with ntp servers, check again in 5 minutes")); | ||
timerqueue_insert(300, 0, -6); | ||
logprintln_P(F("Resynced with NTP servers. Next sync after 24 hours.")); | ||
timerqueue_insert(86400, 0, -5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, you're 100% sure that the time cannot become bogus again and reset to it's defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no reason outside a reboot that the time will get bogus indeed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if this fixes this unnecessary sync from the logs from @McMagellan
Fri Aug 30 19:53:24 2024 (751365): Received 203 bytes data
Fri Aug 30 19:53:24 2024 (751366): Checksum and header received ok!
Fri Aug 30 19:53:24 2024 (751368): received TOP49 Main_Hex_Outlet_Temp: 23
754921: Syncing with ntp servers, check again in 5 minutes
Feedback Egyras#587 ntp sync. Signature Alpha b24fab5 I ran 2 tests of 20 minutes each and in both cases the time was synchronized correctly after about 7 minutes. Here too, when I was looking through the log file 30bputty.log, I noticed a hole in the MQTT bulk message. |
This is probably just caused by some overloading of the log lines, busy mqtt server or network drops. Nothing to worry about |
will be added to v3.7 |
When the year is 1970 resync every 5 minutes. If the date is properly set, resync every day.