Skip to content

Wiznet5k incompatible with recent Requests releases #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anecdata opened this issue Mar 26, 2021 · 1 comment
Closed

Wiznet5k incompatible with recent Requests releases #33

anecdata opened this issue Mar 26, 2021 · 1 comment

Comments

@anecdata
Copy link
Member

anecdata commented Mar 26, 2021

New issue opened here based on a comment in #32. This issue may be better moved to Requests.

Current versions of Wiznet5k do not work with recent versions of Requests.

CircuitPython 5.3.1 through CircuitPython 6.2.0-beta.4 work with the 20200714 library bundle that was current as of CirPy 5.3.1 (Requests 1.4.3), but not with recent Requests versions, so it appears to be a library issue.

Old stuff:

Adafruit CircuitPython 5.3.1 on 2020-07-13; Adafruit Feather M4 Express with samd51j19
>>> # CS on board.A5
>>> # library bundle 20200714
>>> import wiznet5k_simpletest.py
Wiznet5k WebClient Test
Chip Version: w5500
MAC Address: ['0xde', '0xad', '0xbe', '0xef', '0xfe', '0xed']
My IP address is: 192.168.6.223
IP lookup adafruit.com: 104.20.39.240
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
----------------------------------------
This is a test of Adafruit WiFi!
If you can read this, its working :)

----------------------------------------

Fetching json from http://api.coindesk.com/v1/bpi/currentprice/USD.json
----------------------------------------
{'time': {'updated': 'Mar 23, 2021 20:32:00 UTC', 'updatedISO': '2021-03-23T20:32:00+00:00', 'updateduk': 'Mar 23, 2021 at 20:32 GMT'}, 'disclaimer': 'This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org', 'bpi': {'USD': {'code': 'USD', 'description': 'United States Dollar', 'rate_float': 54869.0, 'rate': '54,868.9933'}}}
----------------------------------------
Done!

Newer stuff, after a long wait:

Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit Feather M4 Express with samd51j19
>>> # CS on board.A5
>>> # library bundle 20210320
>>> import wiznet5k_simpletest.py
Wiznet5k WebClient Test
Chip Version: w5500
MAC Address: ['0xde', '0xad', '0xbe', '0xef', '0xfe', '0xed']
My IP address is: 192.168.6.223
IP lookup adafruit.com: 104.20.39.240
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "wiznet5k_simpletest.py", line 38, in <module>
  File "adafruit_requests.py", line 681, in get
  File "adafruit_requests.py", line 586, in request
OutOfRetries: Repeated socket failures

Same behavior CircuitPython 6.0.0 through CircuitPython 6.2.0-beta.4, with recent versions of Requests.

Likely a Requests issue or how newer requests interacts with the Wiznet5k socket: The only libraries needed for the simpletest code are: Requests and Wiznet5k (plus native or library adafruit_bus_device). 6.2.0-beta.4 works with 20210324 wiznet5k + 20200714 requests

From a little print-debugging... Requests appears to be failing because recv from the wiznet socket repeatedly times out before detecting the magic "H" in HTTP/1.1 200 OK.

@anecdata
Copy link
Member Author

Adafruit CircuitPython 7.2.0-alpha.1-224-gac7a80753 on 2022-01-26; Adafruit Feather RP2040 with rp2040
adafruit-circuitpython-bundle-7.x-mpy-20220128
Test code:

import board
from digitalio import DigitalInOut, Direction
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as wiznet5k_socket
import adafruit_requests
# local
from secrets import secrets

TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"

spi = board.SPI()

#
# WIZNET5K - W5500 FeatherWing
#
MAC_ADDR_5500 = (0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED)
# customized CS pin b/c ESP32 needs GPIO0 available for reboots:
eth_5500_cs = DigitalInOut(board.D25)
eth_5500 = WIZNET5K(spi, eth_5500_cs, mac=MAC_ADDR_5500)
print("W5500 IP Address:", eth_5500.pretty_ip(eth_5500.ip_address))

# Initialize a requests object with an ethernet socket and interface
adafruit_requests.set_socket(wiznet5k_socket, eth_5500)
print("Fetching text via W5500 from", TEXT_URL)
with adafruit_requests.get(TEXT_URL) as r:
    print(r.text)

print("Done!")

Result:

code.py output:
W5500 IP Address: 192.168.6.250
Fetching text via W5500 from http://wifitest.adafruit.com/testwifi/index.html
This is a test of Adafruit WiFi!
If you can read this, its working :)
Done!

Code done running.

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant