adafruit / Adafruit_CircuitPython_AzureIoT

Access to Microsoft Azure IoT device, messaging, and job services from CircuitPython!
MIT License
19 stars 15 forks source link

Native Networking Examples missing ssl and adafruit_requests in code from README. #49

Closed bgilreath closed 2 years ago

bgilreath commented 2 years ago

https://github.com/adafruit/Adafruit_CircuitPython_AzureIoT/blob/main/examples/azureiot_native_networking/azureiot_hub_simpletest.py Replaced line #66 with this:

pool = socketpool.SocketPool(wifi.radio) requests = adafruit_requests.Session(pool, ssl.create_default_context()) response = requests.get("https://io.adafruit.com/api/v2/time/seconds") if response: if response.status_code == 200: r = rtc.RTC() r.datetime = time.localtime(int(response.text)) print(f"System Time: {r.datetime}") else: print("Setting time failed")

ladyada commented 2 years ago

welp we shouldnt relly be usig io.adafruit for timekeeping anymore now that we have ntp - what is the exact issue you're solving here :)

bgilreath commented 2 years ago

Sounds good to me!

The issue I'm solving is the native networking example referenced above fails as is on my ESP32-S2 BME Feather with 7.3. Following the advice in the README for this library under the Native Networking heading is where the code snippet is from showing the io.adafruit.com example - and I agree with you about not using it!

Here is the code that eventually got around the issue: pool = socketpool.SocketPool(wifi.radio) ntp = adafruit_ntp.NTP(pool, tz_offset=0) if rtc.RTC().datetime == ntp.datetime: print("Time is correct.....................") else: rtc.RTC().datetime = ntp.datetime print("TIME ADJUSTED: {0}".format(ntp.datetime))

tannewt commented 2 years ago

That's my bad! I changed the example code files but not the README.

tannewt commented 2 years ago

Please check my changes in #51