Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Discard old packets #3

Closed
wants to merge 2 commits into from

Conversation

bmcdonnell
Copy link
Contributor

This resolves an issue I experienced where some old packets were causing updates to old times.

For instance, suppose an NTP packet from the server is delayed, so NTPClient::update() retries before the first arrives. Then the first arrives, time is updated, and the second packet arrives, and remains unparsed. Before this patch, when calling update() the next time, it would parse the old out-of-date packet.

The original NTPClient tries to do this, with its parsePacket() / flush() loop in its forceUpdate() function (which is also used by its update() function). It doesn't work though, since WiFiUDP::parsePacket() doesn't advance to the next packet without WiFiUDP::read(), and WiFiUDP::flush() isn't implemented.

@khoih-prog
Copy link
Owner

Thanks for this PR. It seems to be a very good improvements, but I have to spend some time to test and see if everything is working OK with the new PR.

Best Regards,

@khoih-prog
Copy link
Owner

Hi,

I just have time to test this PR now, and sorry that it's nor working. Can you spend time to verify and check / fix

Testing with Nano_33_IoT

Before update with this PR => OK

Starting NINA_NTPClient_Basic on SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library
Connecting to: HueNet1

NINA_NTPClient_Basic started @ IP address: 192.168.2.114
Using NTP Server pool.ntp.org
******NOT UPDATED******
UTC : 00:00:04
UTC : 00:00:04 Thu 01 Jan 1970
LOC : 02:28:20
LOC : 02:28:20 Sun 07 Feb 2106
UTC EPOCH : 4
LOC EPOCH : 4294952900
UTC : 0:0:4 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:04 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:20 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:20 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 05:08:10
UTC : 05:08:10 Fri 04 Jun 2021
LOC : 01:08:10
LOC : 01:08:10 Fri 04 Jun 2021
UTC EPOCH : 1622783290
LOC EPOCH : 1622768890
UTC : 5:8:10 Fri 4/6/2021 or 4 Jun 2021
UTC : 05:08:10 Fri 4/6/2021 or 4 Jun 2021
LOC : 1:8:10 Fri 4/6/2021 or 4 Jun 2021
LOC : 01:08:10 Fri 4/6/2021 or 4 Jun 2021

After update with this PR => never UPDATED

Starting NINA_NTPClient_Basic on SAMD_NANO_33_IOT with WiFiNINA using WiFiNINA_Generic Library
Connecting to: HueNet1

NINA_NTPClient_Basic started @ IP address: 192.168.2.114
Using NTP Server pool.ntp.org
******NOT UPDATED******
UTC : 00:00:06
UTC : 00:00:06 Thu 01 Jan 1970
LOC : 02:28:22
LOC : 02:28:22 Sun 07 Feb 2106
UTC EPOCH : 6
LOC EPOCH : 4294952902
UTC : 0:0:6 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:06 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:22 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:22 Sun 7/2/2106 or 7 Feb 2106
******NOT UPDATED******
UTC : 00:00:16
UTC : 00:00:16 Thu 01 Jan 1970
LOC : 02:28:32
LOC : 02:28:32 Sun 07 Feb 2106
UTC EPOCH : 16
LOC EPOCH : 4294952912
UTC : 0:0:16 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:16 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:32 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:32 Sun 7/2/2106 or 7 Feb 2106
******NOT UPDATED******
UTC : 00:00:26
UTC : 00:00:26 Thu 01 Jan 1970
LOC : 02:28:42
LOC : 02:28:42 Sun 07 Feb 2106
UTC EPOCH : 26
LOC EPOCH : 4294952922
UTC : 0:0:26 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:26 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:42 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:42 Sun 7/2/2106 or 7 Feb 2106


Testing with Nano_RP2040_Connect

Before update with this PR => OK

Starting NINA_NTPClient_Basic on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library
Connecting to: HueNet1

NINA_NTPClient_Basic started @ IP address: 192.168.2.153
Using NTP Server pool.ntp.org
******NOT UPDATED******
UTC : 00:00:05
UTC : 00:00:05 Thu 01 Jan 1970
LOC : 02:28:21
LOC : 02:28:21 Sun 07 Feb 2106
UTC EPOCH : 5
LOC EPOCH : 4294952901
UTC : 0:0:5 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:05 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:21 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:21 Sun 7/2/2106 or 7 Feb 2106
********UPDATED********
UTC : 04:44:54
UTC : 04:44:54 Fri 04 Jun 2021
LOC : 00:44:54
LOC : 00:44:54 Fri 04 Jun 2021
UTC EPOCH : 1622781894
LOC EPOCH : 1622767494
UTC : 4:44:54 Fri 4/6/2021 or 4 Jun 2021
UTC : 04:44:54 Fri 4/6/2021 or 4 Jun 2021
LOC : 0:44:54 Fri 4/6/2021 or 4 Jun 2021
LOC : 00:44:54 Fri 4/6/2021 or 4 Jun 2021
********UPDATED********
UTC : 04:45:04
UTC : 04:45:04 Fri 04 Jun 2021
LOC : 00:45:04
LOC : 00:45:04 Fri 04 Jun 2021
UTC EPOCH : 1622781904
LOC EPOCH : 1622767504
UTC : 4:45:4 Fri 4/6/2021 or 4 Jun 2021
UTC : 04:45:04 Fri 4/6/2021 or 4 Jun 2021
LOC : 0:45:4 Fri 4/6/2021 or 4 Jun 2021
LOC : 00:45:04 Fri 4/6/2021 or 4 Jun 2021

After update with this PR => never UPDATED


Starting NINA_NTPClient_Basic on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library
Connecting to: HueNet1

NINA_NTPClient_Basic started @ IP address: 192.168.2.153
Using NTP Server pool.ntp.org
******NOT UPDATED******
UTC : 00:00:04
UTC : 00:00:04 Thu 01 Jan 1970
LOC : 02:28:20
LOC : 02:28:20 Sun 07 Feb 2106
UTC EPOCH : 4
LOC EPOCH : 4294952900
UTC : 0:0:4 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:04 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:20 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:20 Sun 7/2/2106 or 7 Feb 2106
******NOT UPDATED******
UTC : 00:00:14
UTC : 00:00:14 Thu 01 Jan 1970
LOC : 02:28:30
LOC : 02:28:30 Sun 07 Feb 2106
UTC EPOCH : 14
LOC EPOCH : 4294952910
UTC : 0:0:14 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:14 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:30 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:30 Sun 7/2/2106 or 7 Feb 2106

...

******NOT UPDATED******
UTC : 00:00:23
UTC : 00:00:23 Thu 01 Jan 1970
LOC : 02:28:39
LOC : 02:28:39 Sun 07 Feb 2106
UTC EPOCH : 23
LOC EPOCH : 4294952919
UTC : 0:0:23 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:23 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:39 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:39 Sun 7/2/2106 or 7 Feb 2106


Copy link
Owner

@khoih-prog khoih-prog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is not working. Please check the Test results in comment.
After fixing the issue, you have to delete the old repo, then refork / rebase.

@bmcdonnell
Copy link
Contributor Author

It was working for me in my real world use with an Adafruit Metro M4 Express AirLift (WiFi) - Lite, together with #4, at least.

How did you perform your tests? How can I run the same?

@khoih-prog
Copy link
Owner

Just use the NINA_NTPClient_Basic on a board using WiFiNINS, suchj as Nano-33-IoT, Nano-RP2040-Connect.

I haven't checked if it's working with other boards using Ethernet yet because the previous tests failed.

@bmcdonnell bmcdonnell force-pushed the discard-old-packets branch from a6c22fe to f954284 Compare June 4, 2021 16:18
@bmcdonnell
Copy link
Contributor Author

I rebased this branch, but did not perform any new testing.

I don't currently have any boards in hand on which I can test this. (I shipped the board I was using for a now tentatively completed project.) Can you see if the issue persists with the rebased code? That would be how I was testing it before, with both this and #4 merged.

@khoih-prog
Copy link
Owner

khoih-prog commented Jun 4, 2021

Still not working using your latest rebased code. I'll spend some time later to find out and fix the issue, just put it in the bucket list.

Starting NINA_NTPClient_Basic on MBED NANO_RP2040_CONNECT with WiFiNINA using WiFiNINA_Generic Library
Connecting to: HueNet1

NINA_NTPClient_Basic started @ IP address: 192.168.2.153
Using NTP Server pool.ntp.org
******NOT UPDATED******
UTC : 00:00:05
UTC : 00:00:05 Thu 01 Jan 1970
LOC : 02:28:21
LOC : 02:28:21 Sun 07 Feb 2106
UTC EPOCH : 5
LOC EPOCH : 4294952901
UTC : 0:0:5 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:05 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:21 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:21 Sun 7/2/2106 or 7 Feb 2106
******NOT UPDATED******
UTC : 00:00:14
UTC : 00:00:14 Thu 01 Jan 1970
LOC : 02:28:30
LOC : 02:28:30 Sun 07 Feb 2106
UTC EPOCH : 14
LOC EPOCH : 4294952910
UTC : 0:0:14 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:14 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:30 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:30 Sun 7/2/2106 or 7 Feb 2106
******NOT UPDATED******
UTC : 00:00:24
UTC : 00:00:24 Thu 01 Jan 1970
LOC : 02:28:40
LOC : 02:28:40 Sun 07 Feb 2106
UTC EPOCH : 24
LOC EPOCH : 4294952920
UTC : 0:0:24 Thu 1/1/1970 or 1 Jan 1970
UTC : 00:00:24 Thu 1/1/1970 or 1 Jan 1970
LOC : 2:28:40 Sun 7/2/2106 or 7 Feb 2106
LOC : 02:28:40 Sun 7/2/2106 or 7 Feb 2106

@khoih-prog khoih-prog closed this Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants