adafruit / Adafruit_CircuitPython_Requests

Requests-like interface for web interfacing
MIT License
51 stars 36 forks source link

Requests hangs periodically #86

Closed askpatrickw closed 2 years ago

askpatrickw commented 2 years ago

I'm running a magtag in a 5 minute deep sleep loop.

On wake it connects to the WIFI and sets the system time by getting time from the Adafruit IO API.

This works for a while (~an hour) and then it hangs. Less often I have seen #62.

Environment: Adafruit CircuitPython 7.0.0 on 2021-09-20; Adafruit MagTag with ESP32S2 Board ID:adafruit_magtag_2.9_grayscale

This is the function I call to set the time.

def set_system_time(force_time=False):
    if time.localtime().tm_year < 2020 or force_time==True:
        print("Setting System Time in UTC")
        pool = socketpool.SocketPool(wifi.radio)
        requests = adafruit_requests.Session(pool, ssl.create_default_context())
        print("Calling adafruit IO for time")
        response = requests.get("https://io.adafruit.com/api/v2/time/seconds")
        print(response)
        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")
    else:
        print("Year seems good, skipping set time.")

Opening this for tracking I'll keep looking into it.

anecdata commented 2 years ago

Is this function the only place in the code where these lines are executed?

        pool = socketpool.SocketPool(wifi.radio)
        requests = adafruit_requests.Session(pool, ssl.create_default_context())

Do you have a device with a debug port where a DEBUG=1 build may show more information about the hang?

askpatrickw commented 2 years ago

No.

I have a networkinit.py I reuse that does the wifi and time which has these lines. I import networkinit and it runs.

But it is the first instance of them which is called after the device wakes from sleep.

It always hangs here waiting for the time and never later in my code.py where I am calling an API for some data.

Debug Build and a Kaluga to capture output. I could set that up.

askpatrickw commented 2 years ago

I'm going to make sure I can reproduce this without the Text display stuff I was doing on the MagTag. I'm sure its not related but just to be sure. If so, I'll try it on the Kaluga with the debug output.

Might take a day or so...

askpatrickw commented 2 years ago

This is a dupe of #62