adafruit/nina-fw

1.7.5 fails to get from github API while 1.7.4 works

slootsky opened this issue · 2 comments

I wanted to add to the esp32 test code to check the latest version of the Nina FW, so I added http://api.github.com/repos/adafruit/nina-fw/releases/latest and did a get to find the latest fw version. On 1.7.5 this fails with the following error, but it works with 1.7.4. Further down, I've included my test code.

I'm testing on a matrix portal, and I'm using adafruit_esp32spi==6.1.0

Traceback (most recent call last):
  File "adafruit_requests.py", line 534, in _get_socket
  File "adafruit_requests.py", line 764, in connect
  File "adafruit_esp32spi/adafruit_esp32spi_socket.py", line 75, in connect
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 806, in socket_connect
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 702, in socket_open
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 332, in _send_command_get_response
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 288, in _wait_response_cmd
  File "adafruit_esp32spi/adafruit_esp32spi.py", line 197, in _wait_for_ready
TimeoutError: ESP32 not responding

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "code.py", line 1, in <module>
  File "gitGet.py", line 159, in <module>
  File "adafruit_requests.py", line 823, in get
  File "adafruit_requests.py", line 717, in request
  File "adafruit_requests.py", line 668, in request
  File "adafruit_requests.py", line 515, in _get_socket
RuntimeError: Sending request failed

Code done running.

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# adafruit_requests usage with an esp32spi_socket
import board
import busio

try:
    import ssl
except ImportError as e:
    print(e)
    print("continuing")

try:
    import wifi
except ImportError as e:
    print(e)
    print("continuing")

try:
    import socketpool
except ImportError as e:
    print(e)
    print("continuing")

from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
# source control.
# pylint: disable=no-name-in-module,wrong-import-order
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

print("ESP32 SPI complete webclient test")

TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
JSON_GET_URL = "https://httpbin.org/get"
JSON_POST_URL = "https://httpbin.org/post"
NINA_FW_LATEST = "http://api.github.com/repos/adafruit/nina-fw/releases/latest"

# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

# If you have an externally connected ESP32:
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)

# If you have an AirLift Featherwing or ItsyBitsy Airlift:
# esp32_cs = DigitalInOut(board.D13)
# esp32_ready = DigitalInOut(board.D11)
# esp32_reset = DigitalInOut(board.D12)

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

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
    print("ESP32 found and in idle mode")
print("Firmware vers.", esp.firmware_version.decode('utf-8'))
print("MAC addr:", [hex(i) for i in esp.MAC_address])

if 'ssid' not in secrets:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    exit
elif 'password' not in secrets:
    print("WiFi ssid and password are kept in secrets.py, please add them there!")
    exit


print(f"Connecting to AP... {secrets['ssid']}")
while not esp.is_connected:
    try:
        esp.connect_AP(secrets["ssid"], secrets["password"])
    except (RuntimeError, ConnectionError) 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))
print(
    "IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
)
print(
    "IP lookup api.github.com: %s" % esp.pretty_ip(esp.get_host_by_name("api.github.com"))
)

print("Ping google.com: %d ms" % esp.ping("google.com"))

# Initialize a requests object with a socket and esp32spi interface
socket.set_interface(esp)
requests.set_socket(socket, esp)


print("Fetching text from %s" % TEXT_URL)
response = requests.get(TEXT_URL)
print("-" * 40)

print("Text Response: ", response.text)
print("-" * 40)
response.close()

print("Fetching JSON data from %s" % JSON_GET_URL)
response = requests.get(JSON_GET_URL)
print("-" * 40)

try:
    print("JSON Response: ", response.json())
    print("-" * 40)
except ValueError as e:
    print(e)
    # continue
response.close()

data = "31F"
print("POSTing data to {0}: {1}".format(JSON_POST_URL, data))
response = requests.post(JSON_POST_URL, data=data)
print("-" * 40)

try:
    json_resp = response.json()
except ValueError as e:
    print(e)
    # continue
else:
    # Parse out the 'data' key from json_resp dict.
    print("Data received from server:", json_resp["data"])
    print("-" * 40)
response.close()

json_data = {"Date": "July 25, 2019"}
print("POSTing data to {0}: {1}".format(JSON_POST_URL, json_data))
response = requests.post(JSON_POST_URL, json=json_data)
print("-" * 40)

try:
    json_resp = response.json()
except ValueError as e:
    print(e)
    # continue
else:
    # Parse out the 'json' key from json_resp dict.
    print("JSON Data received from server:", json_resp["json"])
    print("-" * 40)
response.close()


print("Fetching JSON data from %s" % NINA_FW_LATEST)
response = requests.get(NINA_FW_LATEST)
print("="*40)
try:
    print("JSON Response: ", response.json())
    print("-" * 40)
except ValueError as e:
    print(e)
    # continue
response.close()

print(f"Nina FW Latest Tag: {response.json()['tag_name']}")
print("Running Firmware vers.", esp.firmware_version.decode('utf-8'))

Nina FW v 1.7.7 from #55 resolves my issue.

Closing, thanks!