Skip to content

Raw ntp #1

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

Closed
wants to merge 3 commits into from
Closed

Raw ntp #1

wants to merge 3 commits into from

Conversation

askpatrickw
Copy link

Picking up on the work by @tannewt (who did the hard part) this PR has the following:

  • Removes the check for Epoch. It failes on esp32s2, but it also appears to not be needed as it works without it.
  • changes the calls to time.gmtime() with time.localtime()
  • It adds an ntp_simpletest.py which will works on esp32s2 boards (those with native wifi)
  • It renames the previous ntp_simpletest.py to ntp_simpletest_cpython.py

Tested:

  • Python
  • CircuitPython esp32s2 port, FeatherS2

Not Tested:

  • esp32spi board

Copy link
Owner

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up! Did you verify this works with ESP32SPI still?

@askpatrickw
Copy link
Author

@tannewt Sorry, no I did not, I called that out. I don't have any way to test that.
I don't have any of those boards. Want me to ask on discord for someone to help test it?

@askpatrickw
Copy link
Author

For posterity... the way the check for the epoch fails on esp32s2 looks like this:

time.localtime(0)
OverflowError: timestamp out of range for platform time_t

There is a reference to time_t in the IDF docs I didn't fully grasp:

https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/kconfig.html?highlight=platform%20time_t#config-sdk-toolchain-supports-time-wide-64-bits

@anecdata
Copy link

anecdata commented Dec 22, 2020

I couldn't get the esp32spi example to work:

  • no valid_time or set_time variables/methods
  • not sure that feeding an esp to ntp() will work (I don't think there's an equivalent of socketpool)
  • suggest switching to secrets for AP credentials

Just a note too... I think it's apparent, but use of UDP for NTP on esp32-s2 is a new model from released esp32spi, which exposed the low-level IDF time function to NINA (getTime) which in turn exposed it to the ESP32SPI library (esp.get_time()), since ESP32** automatically gets NTP time in the background.

If I try using an esp32spi socket instead of socketpool, I get:

  File "/lib/adafruit_ntp.py", line 74, in datetime
AttributeError: 'module' object has no attribute 'SOCK_DGRAM'

I think UDP is enabled only for esp32s2 currently. So I suspect that if we are to support both at this time, two different flows are needed in the library. I think I recall that UDP is possible in ESP32SPI, but it's kludgy due to the way NINA is implemented.

The other change in this NTP library API is elevating RTC updates from the library to the user. (How do we manage breaking changes in libraries when they are in between major circuitpython releases?)

@askpatrickw
Copy link
Author

Gotcha, so more work will be needed to do a full library for CP overall.
For now, we can use this (if needed) on esp32s2.

@netroy
Copy link

netroy commented Jan 29, 2021

hey folks, I've been trying this branch and things were working great until CircuitPython 6.1.0. But, not there seems to be some issue with reading from the socket, and the ntp call throws an EAGAIN.
I managed to bisect it down to this commit. But, I'm not very good at C, and haven't been able to pinpoint what might be breaking this library.

I'm not necessarily asking any of you for help. Just letting you know that this code is breaking on new releases of Circuitpython for me on an ESP32S2 board.

Let me know if I can provide any more information.

@anecdata
Copy link

I was also getting EAGAIN with UDP/NTP, but using settimeout I was able to get around it (then, depending on timeout value, sometimes get ETIMEDOUT)

@netroy
Copy link

netroy commented Jan 29, 2021

@anecdata I tried setting the socket timeout as well. and it did not fix the issue. I also tried replacing the hostname with a resolved ip address, that did not fix anything either.

I can try later to make another UDP request, and see if I can locate the issue.

@askpatrickw
Copy link
Author

Based on this adafruit#16

I'm closing this PR.

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

Successfully merging this pull request may close these issues.

4 participants