Skip to content

Commit

Permalink
Merge pull request #146 from justmobilize/update-legacy-set-socket-ex…
Browse files Browse the repository at this point in the history
…amples

Update legacy set_socket examples
  • Loading branch information
dhalbert authored Mar 1, 2024
2 parents 3bd953e + bdd64a1 commit 080ad9b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
10 changes: 6 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ wifitest.adafruit.com.
import board
import busio
import digitalio
import adafruit_requests as requests
import adafruit_connection_manager
import adafruit_requests
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
import adafruit_wiznet5k.adafruit_wiznet5k_socket as pool
print("Wiznet5k WebClient Test")
Expand All @@ -79,8 +80,9 @@ wifitest.adafruit.com.
# Initialize ethernet interface with DHCP
eth = WIZNET5K(spi_bus, cs)
# Initialize a requests object with a socket and ethernet interface
requests.set_socket(socket, eth)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, eth)
requests = adafruit_requests.Session(pool, ssl_context)
print("Chip Version:", eth.chip)
print("MAC Address:", [hex(i) for i in eth.mac_address])
Expand Down
9 changes: 6 additions & 3 deletions examples/wiznet5k_aio_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_connection_manager
import adafruit_requests
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
import adafruit_wiznet5k.adafruit_wiznet5k_socket as pool

# Get Adafruit.io details from a secrets.py file
try:
Expand All @@ -21,7 +22,9 @@

# Initialize ethernet interface with DHCP
eth = WIZNET5K(spi_bus, cs)
requests.set_socket(socket, eth)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, eth)
requests = adafruit_requests.Session(pool, ssl_context)

counter = 0

Expand Down
10 changes: 6 additions & 4 deletions examples/wiznet5k_cheerlights.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
import busio
from digitalio import DigitalInOut

import adafruit_requests as requests
import adafruit_connection_manager
import adafruit_requests

import neopixel
import adafruit_fancyled.adafruit_fancyled as fancy
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
import adafruit_wiznet5k.adafruit_wiznet5k_socket as pool

cs = DigitalInOut(board.D10)
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Initialize ethernet interface with DHCP
eth = WIZNET5K(spi_bus, cs)

# Initialize a requests object with a socket and ethernet interface
requests.set_socket(socket, eth)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, eth)
requests = adafruit_requests.Session(pool, ssl_context)

DATA_SOURCE = "http://api.thingspeak.com/channels/1417/feeds.json?results=1"
DATA_LOCATION = ["feeds", 0, "field2"]
Expand Down
10 changes: 6 additions & 4 deletions examples/wiznet5k_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import board
import busio
import digitalio
import adafruit_requests as requests
import adafruit_connection_manager
import adafruit_requests
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
import adafruit_wiznet5k.adafruit_wiznet5k_socket as pool

print("Wiznet5k WebClient Test")

Expand All @@ -22,8 +23,9 @@
# Initialize ethernet interface with DHCP
eth = WIZNET5K(spi_bus, cs)

# Initialize a requests object with a socket and ethernet interface
requests.set_socket(socket, eth)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, eth)
requests = adafruit_requests.Session(pool, ssl_context)

print("Chip Version:", eth.chip)
print("MAC Address:", [hex(i) for i in eth.mac_address])
Expand Down
10 changes: 6 additions & 4 deletions examples/wiznet5k_simpletest_manual_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import board
import busio
import digitalio
import adafruit_requests as requests
import adafruit_connection_manager
import adafruit_requests
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
import adafruit_wiznet5k.adafruit_wiznet5k_socket as pool

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

Expand All @@ -27,8 +28,9 @@
# Set network configuration
eth.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER)

# Initialize a requests object with a socket and ethernet interface
requests.set_socket(socket, eth)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, eth)
requests = adafruit_requests.Session(pool, ssl_context)

print("Chip Version:", eth.chip)
print("MAC Address:", [hex(i) for i in eth.mac_address])
Expand Down
10 changes: 6 additions & 4 deletions examples/wiznet5k_wsgiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import digitalio
import neopixel

import adafruit_requests as requests
import adafruit_connection_manager
import adafruit_requests
from adafruit_wsgi.wsgi_app import WSGIApp
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
import adafruit_wiznet5k.adafruit_wiznet5k_socket as pool
import adafruit_wiznet5k.adafruit_wiznet5k_wsgiserver as server


Expand Down Expand Up @@ -76,8 +77,9 @@ def get_static_file(filename):
# Initialize Ethernet interface with DHCP
eth = WIZNET5K(spi_bus, cs, mac=mac)

# Initialize a requests object with a socket and ethernet interface
requests.set_socket(socket, eth)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, eth)
requests = adafruit_requests.Session(pool, ssl_context)


# Here we create our application, registering the
Expand Down

0 comments on commit 080ad9b

Please sign in to comment.