Re: ESP32 Feather NTP libraries
Re: ESP32 Feather NTP libraries
Re: ESP32 Feather NTP libraries
Re: ESP32 Feather NTP libraries
Re: ESP32 Feather NTP libraries
tannewt wrote:Unfortunately the current NTP library is a bit of a lie. It just uses a NINA FW call to get the time.
However, I did make an actual NTP version here: https://github.com/tannewt/Adafruit_Cir ... ee/raw_ntp
Would you mind trying it and letting me know how it works? We can figure out how to swap them out soon.
# modules circuitpython natifs
import wifi
import socketpool
import time
# modules circuitpython externes (dossier lib)
import adafruit_ntp
# Récupère le SSID et le MDP du réseau WiFi dans le fichier secrets.py
try:
from secrets import secrets
except ImportError:
print("Fichier secrets.py non disponible")
raise
# ********************************
# *** CONNEXION AU RESEAU WIFI ***
# ********************************
print("Réseaux WiFi disponibles :")
for network in wifi.radio.start_scanning_networks():
print(f'\t{str(network.ssid, "utf-8")}\t\tRSSI: {network.rssi}\tCanal: {network.channel}')
wifi.radio.stop_scanning_networks()
print(f'Tentative de connexion au réseau {secrets["ssid"]}')
print("........")
wifi.radio.connect(secrets["ssid"], secrets["password"])
print(f'Connecté au réseau {secrets["ssid"]} !')
# ***********************************
# *** RECUPERATION DE L'HEURE NTP ***
# ***********************************
pool = socketpool.SocketPool(wifi.radio)
ntp = adafruit_ntp.NTP(pool)
while True:
print(ntp.datetime)
time.sleep(1)
Re: ESP32 Feather NTP libraries
Re: ESP32 Feather NTP libraries
import time, board, adafruit_ds3231
import ipaddress, ssl, wifi, socketpool, adafruit_requests, secrets, adafruit_ntp
from rtc import RTC
ds3231=adafruit_ds3231.DS3231(board.I2C())
from secrets import secrets
aio_username = secrets["aio_username"]; aio_key = secrets["aio_key"]; location = secrets.get("timezone", None)
TIME_URL = "https://io.adafruit.com/api/v2/%s/integrations/time/strftime?x-aio-key=%s" % (aio_username, aio_key)
TIME_URL += "&fmt=%25Y-%25m-%25d+%25H%3A%25M%3A%25S.%25L+%25j+%25u+%25z+%25Z"
print("Getting time... ", end="")
wifi.radio.connect(secrets["ssid"], secrets["password"])
pool = socketpool.SocketPool(wifi.radio)
'''
requests = adafruit_requests.Session(pool, ssl.create_default_context())
response = requests.get(TIME_URL); times=response.text; times=times.split(" ")
print(times)
the_date=times[0]; the_time=times[1]; yday=int(times[2]); wday=int(times[3]); isdst=None
year,mon,mday=[int(x) for x in the_date.split("-")]
the_time=the_time.split(".")[0]; hour,min,sec=[int(x) for x in the_time.split(":")]
ds3231.datetime=RTC().datetime=time.struct_time((year,mon,mday,hour,min,sec,wday,yday,isdst)) #set rtc to internet timetime: "
print ("Time: ",time.localtime())
'''
ntp=adafruit_ntp.NTP(pool)
print(ntp.datetime)
Re: ESP32 Feather NTP libraries
Re: ESP32 Feather NTP libraries
Re: ESP32 Feather NTP libraries
# if time.localtime(0).tm_year != 1970:
# raise OSError("Epoch must be 1970")
Re: ESP32 Feather NTP libraries
Re: ESP32 Feather NTP libraries
tannewt wrote:Nice! That looks good.
Re: ESP32 Feather NTP libraries