-
Notifications
You must be signed in to change notification settings - Fork 21
NTP support for PortalBase #115
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
• Provides NTP-based system clock synchronization. • Works with both ESP32SPI WiFi coprocessor and native wifi.radio backends. • Pulls defaults from settings.toml (NTP_SERVER, NTP_TZ, NTP_DST, NTP_RETRIES, NTP_TIMEOUT). • Includes retry loop with short delays (~0.5s) for reliability with ESP/SPI transport. • Returns a time.struct_time after syncing. • If rtc is available, sets rtc.RTC().datetime. examples/portalbase_time.py • New example: minimal demonstration of portal.network.time_sync(). • Shows how to: 1. Instantiate PyPortal. 2. Call portal.network.time_sync(). 3. Print the synced time (either as struct_time or formatted timestamp).
add wait_for_ready() to network.py module. This allows for the ESP co-processor to makes itself presentable. Had been using hard coded delays. |
Checking to confirm ESP is ready. Removed hard coded timed waits. Refactored code into baby helpers to make ruff happy.
add support for: * MatrixPortal-M4 * Fruit Jam * MagTag
@FoamyGuy - I know you are working on other projects so no rush to review. Just a quick update. I've tested this NTP PR on:
Both running CircuitPython 10-beta3. It ran fine for me. Since adafruit_portalbase is a frozen library I had to rename the lib for testing purposes on the PyPortal. I was not able to test on a MatrixPortal-M4 as the frozen portalbase is pulled in by matrixportal and looks like it needs a custom CircuitPython build or some clever trick to load a custom portalbase. If this NTP is accepted I can go back to adafruit_fruitjam and rip up the NTP and update the examples to avoid redundant code. |
@mikeysklar Thank you! I will try this out soon. In order to circumvent frozen libraries you can place the development version in the root of the CIRCUITPY drive. It will import the one from the root of CIRCUITPY if it exists instead of the frozen version. |
Ah, GTK. I'll setup a MatrixPortal-M4 with rootdir adafruit_portalbase/ to complete testing on my side and report back. @b-blake confirmed this PR is working on his Fruit Jam. |
The local library override worked great. However, I got stuck with the MatrixPortal-M4 testing. I cannot get around the SSL error it is throwing.
MatrixPortal-M4 code.py:
|
@mikeysklar it looks like for some reason this logic is not determining that it's running on the Matrix Portal M4 https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal/blob/f6678a77fd52c3538a0b2a2f91dcf05f9a016e05/adafruit_matrixportal/network.py#L35-L38 That is odd. Maybe the sysname could have changed? I'll try it out on my device as well. |
Indeed it appears that the value returned by Your example code from the previous comment works successfully for me on Matrix Portal M4 with 9.2.8 installed. |
@FoamyGuy - Awesome! I was pulling my hair out over this yesterday. I was certain it was something I was doing wrong. I'll do one more check on with MagTag and NTP setting and make some cosmetic changes. Don't approve the PR just yet. |
Tested with examples/portalbase_time.py on three boards all running CircuitPython-10.0.0-beta3.
All run clean and sync NTP / RTC with ~4 lines of nearly identical code. If you are okay with it I think this is ready to merge. |
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.
Thank you!
I tweaked this to make the fruit jam section of code the same as the others
jam = FruitJam(status_neopixel=None)
net = jam.network
I tested that version on Fruit Jam with 10.0.0-beta.3
and it seemed to be working fine.
I think there should be no need to init a new NetworkBase instance because one already gets created internally when FruitJam()
init occurs.
Forgot to mention, I also tested after deleting |
Updating https://github.com/adafruit/Adafruit_CircuitPython_PortalBase to 3.4.0 from 3.3.0: > Merge pull request adafruit/Adafruit_CircuitPython_PortalBase#115 from mikeysklar/portalbase-ntp
@FoamyGuy looks good. Thank you for your assistance on this one. I just formatted a FruitJam and loaded up with the new PortalBase 3.4.0 release from the library bundle. It ran smoothly.
|
Started as Fruit Jam NTP support, but it makes more sense to share NTP support through PortalBase.
adafruit_portalbase/network.py
• Provides NTP-based system clock synchronization.
• Works with both ESP32SPI WiFi coprocessor and native wifi.radio backends.
• Pulls defaults from settings.toml (NTP_SERVER, NTP_TZ, NTP_DST, NTP_RETRIES, NTP_TIMEOUT).
• Includes retry loop with short delays (~0.5s) for reliability with ESP/SPI transport.
• If rtc is available, sets rtc.RTC().datetime.
examples/portalbase_time.py
• New example: minimal demonstration of portal.network.time_sync().
Tested on PyPortal (portalbase is a frozen module). Testing was done with alt lib/ name.
I need to confirm testing on MatrixPortal-M4 and Fruit Jam before merging.