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

Add support for WIZNET5K ssl #9

Merged
merged 7 commits into from
Apr 25, 2024
Merged

Conversation

justmobilize
Copy link
Collaborator

@justmobilize justmobilize commented Apr 20, 2024

Updated to support SSL everywhere. To test you need:

cp: main adafruit/circuitpython#8954 (merged)
wiznet: main adafruit/Adafruit_CircuitPython_Wiznet5k#157 (merged)

If this looks good to people (and once the versions are determined), I would like to add tests before it's merged.

@justmobilize
Copy link
Collaborator Author

@anecdata if you have time, would you be willing to try this?

@anecdata
Copy link
Member

anecdata commented Apr 24, 2024

I'm having trouble getting the right pieces together for this. Here's what's installed:
Adafruit CircuitPython 9.1.0-beta.0-27-g4ede914d45 on 2024-04-17; FeatherS3 with ESP32S3 (PR #8954)
adafruit_requests v3.2.5 (latest)
adafruit_connection_manager (this PR #9)
adafruit_wiznet5k v5.2.0 (includes #157, but not #151)

code...
import traceback
import ssl
import board
import digitalio
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_requests
import adafruit_connection_manager

TEXT_URL = "https://httpbin.org/get"

spi_bus = board.SPI()
cs = digitalio.DigitalInOut(board.A4)
mac = f'de:ad:be:ef:fe:{(252):02x}'  # I need this to avoid DHCP collisions
radio = WIZNET5K(spi_bus, cs, mac=mac, debug=False)
pool = adafruit_connection_manager.get_radio_socketpool(radio)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio)
requests = adafruit_requests.Session(pool, ssl_context)

while True:
    print(f"Fetching from {TEXT_URL} ... ", end="")
    with requests.get(TEXT_URL) as resp:
        print(f'{resp.status_code}')
    time.sleep(5)

result:

Fetching from https://httpbin.org/get ... Traceback (most recent call last):
  File "code.py", line 23, in <module>
  File "adafruit_requests.py", line 591, in get
  File "adafruit_requests.py", line 525, in request
  File "adafruit_connection_manager.py", line 256, in get_socket
  File "adafruit_wiznet5k/adafruit_wiznet5k_socket.py", line 195, in getaddrinfo
  File "adafruit_wiznet5k/adafruit_wiznet5k_socket.py", line 210, in gethostbyname
AttributeError: 'NoneType' object has no attribute 'get_host_by_name'

I haven't used CM too much yet, maybe there's something wrong in the code.

@justmobilize
Copy link
Collaborator Author

@anecdata I found the issue (working on too many things at the same time). I'll update this PR tonight

@anecdata
Copy link
Member

Yes, I fully understand, there are so many inter-related changes going on, it's hard to keep track of what goes with what.

@justmobilize
Copy link
Collaborator Author

Especially when it's one's own fault. I keep doing things here like I do professionally and thinking things will get merged and released quickly...

@justmobilize
Copy link
Collaborator Author

@anecdata this should work now... Sorry about that

@anecdata
Copy link
Member

That did it... "200 OK" every 5 seconds :-)

@justmobilize justmobilize marked this pull request as ready for review April 25, 2024 16:58
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.

Not tested. Just one style thing.

adafruit_connection_manager.py Outdated Show resolved Hide resolved
justmobilize and others added 2 commits April 25, 2024 12:02
Co-authored-by: Dan Halbert <halbert@halwitz.org>
@justmobilize
Copy link
Collaborator Author

@dhalbert updated

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.

Thanks!

@dhalbert dhalbert merged commit 513cb12 into adafruit:main Apr 25, 2024
1 check passed
@justmobilize justmobilize deleted the wiznet5k-ssl branch April 25, 2024 20:34
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Apr 26, 2024
Updating https://github.com/adafruit/Adafruit_CircuitPython_ConnectionManager to 1.1.0 from 1.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_ConnectionManager#8 from justmobilize/different-pool-different-connection-manager
  > Merge pull request adafruit/Adafruit_CircuitPython_ConnectionManager#9 from justmobilize/wiznet5k-ssl
  > Merge pull request adafruit/Adafruit_CircuitPython_ConnectionManager#12 from justmobilize/test-updates
  > Merge pull request adafruit/Adafruit_CircuitPython_ConnectionManager#5 from FoamyGuy/fix_circup_instruction

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