Skip to content

ntptime: Does not handle KoD (Kiss of Death) resonse. #604

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

Open
peterhinch opened this issue Feb 1, 2023 · 2 comments
Open

ntptime: Does not handle KoD (Kiss of Death) resonse. #604

peterhinch opened this issue Feb 1, 2023 · 2 comments

Comments

@peterhinch
Copy link
Contributor

A call to .time() can return a large negative number which results in a rather confusing exception in .settime(). This can occur if an application issues NTP requests too frequently: see this post. I suspect there may also be other circumstances in which an NTP query returns zero.

Another problem reported in discussions is that .time() frequently times out. Clearly the timeout must be short, but this implies that on many networks timeouts will be common.

There are a number of simple fixes. One is for .time() to return an error value in either of these cases which is tested by .settime(). The latter could return a bool indicating success or failure.

@massimosala
Copy link

Hi Peter

I dislike the ntptime module, I think it is like "how to confuse a cat" !

Probably a lot of users get KoD because they don't realize that ntptime.time() isn't time.time() ...

I wrote my version, with more strict checking about the servers reponse.

Feel free to read and use it.
Ah, you have to remove the compatibility module and the gc_collect()
The compatibility is just to use this module also on windows / linux, defining const

Eventually I can donate it to mp ecosystem.

ntptime2.py.txt

@massimosala
Copy link

I see now I use a variable MICRO in settime()

Just replace the code with:

	try :
		from machine import RTC
		RTC().datetime((tm[0], tm[1], tm[2], tm[6] + 1, tm[3], tm[4], tm[5], 0))
	except :
		print("Unsupported platform, no RTC")

and the printf() with print()

Ciao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants