Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

adafruit_requests stops working after Timed out waiting for
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

adafruit_requests stops working after Timed out waiting for

by evanthomas on Mon Jun 29, 2020 3:54 am

I've been struggling with this for months but I think I've spotted the pattern.

I have an application that polls a couple of endpoints, with adafruit_requests, every few seconds and makes a nice display. No network is 100% reliable end every now and then a request fails. When this happens adafruit_requests fails with: "Timed out waiting for SPI char". Firstly, this is not an appropriate exception. More importantly, once this happens the adafruit_requests becomes permanently borked with all subsequent calls failing with the same error. The only way to recover is to reboot.

To me, these are defects but perhaps I not using the library correctly. I have attached a code below that reproduces the issue.

I am using firmware 5.3.0 and 4.something. I have tested with 2 pyportals, 2 access points and several USB cables.

TIA,
Evan.

Code: Select all | TOGGLE FULL SIZE
import time
import board
import busio
from digitalio import DigitalInOut
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_requests as requests
from secrets import secrets

# Non existent endpoint
BAD_DATA_SOURCE = "http://1.2.3.4/hello"
# Good data source
GOOD_DATA_SOURCE = "https://httpbin.org/get"

# Start WiFi
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_gpio0 = DigitalInOut(board.ESP_GPIO0)
esp32_reset = DigitalInOut(board.ESP_RESET)
esp32_cs = DigitalInOut(board.ESP_CS)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, esp32_gpio0)

requests.set_socket(socket, esp)

print("MAC: " + ':'.join('{:02x}'.format(x) for x in reversed(esp.MAC_address)))
print("Connecting to AP...")
while not esp.is_connected:
  try:
    esp.connect_AP(secrets['ssid'], secrets['password'])
  except RuntimeError as e:
    print("could not connect to AP, retrying: ",e)
    continue
print("Connected to", str(esp.ssid, 'utf-8'), "\tRSSI:", esp.rssi)
print("My IP address is", esp.pretty_ip(esp.ip_address))


try:
  r = requests.get(BAD_DATA_SOURCE)
except RuntimeError as e:
  # Timed out waiting for SPI char
  print(e)

# This GET always fails
r = requests.get(GOOD_DATA_SOURCE)
print(r.text)


evanthomas
 
Posts: 16
Joined: Sun Jan 26, 2020 11:11 pm

Re: adafruit_requests stops working after Timed out waiting

by evanthomas on Mon Jun 29, 2020 9:51 pm

I've updated to the latest stable libraries and the behaviour is the same.

evanthomas
 
Posts: 16
Joined: Sun Jan 26, 2020 11:11 pm

Re: adafruit_requests stops working after Timed out waiting

by tannewt on Tue Jun 30, 2020 12:38 pm

Have you updated the ESP's firmware?

tannewt
 
Posts: 1716
Joined: Thu Oct 06, 2016 8:48 pm

Re: adafruit_requests stops working after Timed out waiting

by evanthomas on Wed Jul 01, 2020 2:57 am

Thanks for the suggestion, I should have done it earlier. I upgraded 1.2.2 -> 1.6,1, but it's exactly the same :(

Should I raise an issue?

evanthomas
 
Posts: 16
Joined: Sun Jan 26, 2020 11:11 pm

Re: adafruit_requests stops working after Timed out waiting

by tannewt on Wed Jul 01, 2020 1:04 pm

Sure, one on the ESP32SPI library would be good. I'm currently reworking requests a bit too.

No promises though because networking issues can be tough to replicate.

tannewt
 
Posts: 1716
Joined: Thu Oct 06, 2016 8:48 pm

Re: adafruit_requests stops working after Timed out waiting

by evanthomas on Wed Jul 01, 2020 6:51 pm

Ok, I'll raise an issue and. yes, it looks likes it's failing somewhere in the SPI library. It's 100% reproducible in 2 networks on 2 devices. I have other ESP32s with C++ applications that are rock solid in those networks. The device is marketed as being a python programmable IoT device so presumably it will get fixed. :)

Thanks,
Evan.

evanthomas
 
Posts: 16
Joined: Sun Jan 26, 2020 11:11 pm

Please be positive and constructive with your questions and comments.