Skip to content

Commit

Permalink
Merge pull request #188 from justmobilize/remove-set-socket
Browse files Browse the repository at this point in the history
Remove legacy requests.set_socket
  • Loading branch information
tannewt authored Feb 23, 2024
2 parents 0adb75b + a9129c9 commit 3042d19
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
20 changes: 12 additions & 8 deletions adafruit_esp32spi/adafruit_esp32spi_wifimanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

from time import sleep
from micropython import const
import adafruit_requests as requests
import adafruit_connection_manager
import adafruit_requests
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_socket as socket


# pylint: disable=too-many-instance-attributes
Expand Down Expand Up @@ -61,11 +61,15 @@ def __init__(
self.password = secrets.get("password", None)
self.attempts = attempts
self._connection_type = connection_type
requests.set_socket(socket, esp)
self.statuspix = status_pixel
self.pixel_status(0)
self._ap_index = 0

# create requests session
pool = adafruit_connection_manager.get_radio_socketpool(self.esp)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(self.esp)
self._requests = adafruit_requests.Session(pool, ssl_context)

# Check for WPA2 Enterprise keys in the secrets dictionary and load them if they exist
self.ent_ssid = secrets.get("ent_ssid", secrets["ssid"])
self.ent_ident = secrets.get("ent_ident", "")
Expand Down Expand Up @@ -220,7 +224,7 @@ def get(self, url, **kw):
if not self.esp.is_connected:
self.connect()
self.pixel_status((0, 0, 100))
return_val = requests.get(url, **kw)
return_val = self._requests.get(url, **kw)
self.pixel_status(0)
return return_val

Expand All @@ -239,7 +243,7 @@ def post(self, url, **kw):
if not self.esp.is_connected:
self.connect()
self.pixel_status((0, 0, 100))
return_val = requests.post(url, **kw)
return_val = self._requests.post(url, **kw)
self.pixel_status(0)
return return_val

Expand All @@ -258,7 +262,7 @@ def put(self, url, **kw):
if not self.esp.is_connected:
self.connect()
self.pixel_status((0, 0, 100))
return_val = requests.put(url, **kw)
return_val = self._requests.put(url, **kw)
self.pixel_status(0)
return return_val

Expand All @@ -277,7 +281,7 @@ def patch(self, url, **kw):
if not self.esp.is_connected:
self.connect()
self.pixel_status((0, 0, 100))
return_val = requests.patch(url, **kw)
return_val = self._requests.patch(url, **kw)
self.pixel_status(0)
return return_val

Expand All @@ -296,7 +300,7 @@ def delete(self, url, **kw):
if not self.esp.is_connected:
self.connect()
self.pixel_status((0, 0, 100))
return_val = requests.delete(url, **kw)
return_val = self._requests.delete(url, **kw)
self.pixel_status(0)
return return_val

Expand Down
8 changes: 5 additions & 3 deletions examples/esp32spi_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_requests
from adafruit_esp32spi import adafruit_esp32spi

# Get wifi details and more from a settings.toml file
Expand Down Expand Up @@ -57,7 +57,9 @@
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

requests.set_socket(socket, esp)
pool = adafruit_connection_manager.get_radio_socketpool(esp)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
requests = adafruit_requests.Session(pool, ssl_context)

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
print("ESP32 found and in idle mode")
Expand Down
8 changes: 5 additions & 3 deletions examples/esp32spi_simpletest_rp2040.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_requests
from adafruit_esp32spi import adafruit_esp32spi

# Get wifi details and more from a settings.toml file
Expand Down Expand Up @@ -36,7 +36,9 @@
spi = busio.SPI(board.GP10, board.GP11, board.GP12)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

requests.set_socket(socket, esp)
pool = adafruit_connection_manager.get_radio_socketpool(esp)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
requests = adafruit_requests.Session(pool, ssl_context)

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
print("ESP32 found and in idle mode")
Expand Down
9 changes: 5 additions & 4 deletions examples/esp32spi_wpa2ent_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import board
import busio
from digitalio import DigitalInOut

import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_requests
from adafruit_esp32spi import adafruit_esp32spi


Expand Down Expand Up @@ -53,7 +52,9 @@ def normalize(v):
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

requests.set_socket(socket, esp)
pool = adafruit_connection_manager.get_radio_socketpool(esp)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(esp)
requests = adafruit_requests.Session(pool, ssl_context)

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
print("ESP32 found and in idle mode")
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
# SPDX-License-Identifier: Unlicense

Adafruit-Blinka
adafruit-circuitpython-requests
adafruit-circuitpython-busdevice
adafruit-circuitpython-connectionmanager
adafruit-circuitpython-requests

0 comments on commit 3042d19

Please sign in to comment.