Skip to content
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

Convert to SocketPool #159

Merged
merged 4 commits into from
Apr 30, 2024
Merged

Conversation

justmobilize
Copy link
Collaborator

@justmobilize justmobilize commented Apr 23, 2024

For use with: adafruit/Adafruit_CircuitPython_ConnectionManager#11

Converting from the old adafruit_wiznet5k/adafruit_wiznet5k_socket.py to adafruit_wiznet5k/adafruit_wiznet5k_socketpool.py to remove set_interface and work more like a built-in SocketPool.

This also allows one to use multiple WIZNET5K boards at the same time.

General example:

import board
import busio
import digitalio
import adafruit_requests
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socketpool as socketpool

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

cs = digitalio.DigitalInOut(board.D10)
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
radio = WIZNET5K(spi_bus, cs)
pool = socketpool.SocketPool(radio)
requests = adafruit_requests.Session(pool)
print(requests.get(TEXT_URL).text)

or with the new ConnectionManager

import board
import busio
import digitalio
import adafruit_connection_manager
import adafruit_requests
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
from adafruit_wiznet5k import adafruit_wiznet5k_socketpool

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

cs = digitalio.DigitalInOut(board.D10)
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
radio = WIZNET5K(spi_bus, cs)
pool = adafruit_connection_manager.get_radio_socketpool(radio)
assert isinstance(pool, adafruit_wiznet5k_socketpool.SocketPool)
requests = adafruit_requests.Session(pool)
print(requests.get(TEXT_URL).text)

@justmobilize
Copy link
Collaborator Author

@anecdata re-done with all the merges (including the SSL one). Would you be willing to test this again for me?

@justmobilize
Copy link
Collaborator Author

I apologize for the hard review. With moving a few things at the top, it isn't a simple white space change with it going into the class. I promise I didn't change anything.

@anecdata
Copy link
Member

anecdata commented Apr 24, 2024

This looks good, working for me with...

Hardware config:
https://gist.github.com/anecdata/c708dd9e5a0e0b582f01f27d24fc3aab?permalink_comment_id=5004766#gistcomment-5004766

Code:
https://gist.github.com/anecdata/f2e10134bb23be029d42f36662043451

Verified at the router that the sessions are cycling through the three ethernet IP addresses in sync with the code.

addendum: HTTPS is also working across all three ethernets. Not sure if it matters, but SSL works using either separate ssl.create_default_context() for each ethernet, or using a single shared ssl.create_default_context().

@justmobilize justmobilize marked this pull request as ready for review April 28, 2024 04:45
Copy link
Member

@anecdata anecdata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-tested with adafruit/Adafruit_CircuitPython_ConnectionManager#11 (review). Good to go pending any others with code review.

@dhalbert
Copy link
Contributor

Same q I asked re ESP32SPI. If this is an incompatible change, then we'll need to change any Guide examples we have. If not, no problem.

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 matching changes also made in ConnectionManager

@dhalbert dhalbert merged commit 09b83c4 into adafruit:main Apr 30, 2024
1 check passed
@justmobilize justmobilize deleted the convert-to-socketpool branch April 30, 2024 16:09
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request May 1, 2024
Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 8.0.0 from 7.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#198 from justmobilize/convert-to-socketpool

Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 7.0.0 from 6.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#159 from justmobilize/convert-to-socketpool

Updating https://github.com/adafruit/Adafruit_CircuitPython_ConnectionManager to 2.0.0 from 1.2.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_ConnectionManager#11 from justmobilize/esp32spi-and-wiznet5k-socketpool

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
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

Successfully merging this pull request may close these issues.

3 participants