Skip to content

Commit

Permalink
Update legacy set_socket examples
Browse files Browse the repository at this point in the history
  • Loading branch information
justmobilize committed Mar 1, 2024
1 parent 1a66da1 commit 637b274
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 60 deletions.
10 changes: 6 additions & 4 deletions examples/adafruit_io_http/adafruit_io_analog_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import busio
from analogio import AnalogIn
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
Expand Down Expand Up @@ -45,8 +46,9 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)
requests = adafruit_requests.Session(pool, ssl_context)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
Expand Down
10 changes: 6 additions & 4 deletions examples/adafruit_io_http/adafruit_io_digital_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import board
import busio
from digitalio import DigitalInOut, Direction
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
Expand Down Expand Up @@ -44,8 +45,9 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)
requests = adafruit_requests.Session(pool, ssl_context)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
Expand Down
10 changes: 6 additions & 4 deletions examples/adafruit_io_http/adafruit_io_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
Expand Down Expand Up @@ -44,8 +45,9 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)
requests = adafruit_requests.Session(pool, ssl_context)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
Expand Down
10 changes: 6 additions & 4 deletions examples/adafruit_io_http/adafruit_io_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP


Expand Down Expand Up @@ -45,8 +46,9 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)
requests = adafruit_requests.Session(pool, ssl_context)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
Expand Down
10 changes: 6 additions & 4 deletions examples/adafruit_io_http/adafruit_io_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
Expand Down Expand Up @@ -43,8 +44,9 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)
requests = adafruit_requests.Session(pool, ssl_context)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
Expand Down
10 changes: 6 additions & 4 deletions examples/adafruit_io_http/adafruit_io_randomizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
Expand Down Expand Up @@ -44,8 +45,9 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)
requests = adafruit_requests.Session(pool, ssl_context)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
Expand Down
10 changes: 6 additions & 4 deletions examples/adafruit_io_http/adafruit_io_simpletest_esp32spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
Expand Down Expand Up @@ -43,8 +44,9 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)
requests = adafruit_requests.Session(pool, ssl_context)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
Expand Down
10 changes: 6 additions & 4 deletions examples/adafruit_io_http/adafruit_io_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
import adafruit_requests
import adafruit_adt7410
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError

Expand Down Expand Up @@ -45,8 +46,9 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)
requests = adafruit_requests.Session(pool, ssl_context)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
Expand Down
10 changes: 6 additions & 4 deletions examples/adafruit_io_http/adafruit_io_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_connection_manager
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP

# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
Expand Down Expand Up @@ -43,8 +44,9 @@
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)
# Initialize a requests session
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)
requests = adafruit_requests.Session(pool, ssl_context)

# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
Expand Down
8 changes: 5 additions & 3 deletions examples/adafruit_io_mqtt/adafruit_io_feed_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_connection_manager
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
import neopixel
import adafruit_minimqtt.adafruit_minimqtt as MQTT
from adafruit_io.adafruit_io import IO_MQTT
Expand Down Expand Up @@ -94,15 +95,16 @@ def on_battery_msg(client, topic, message):
wifi.connect()
print("Connected!")

# Initialize MQTT interface with the esp interface
MQTT.set_socket(socket, esp)
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)

# Initialize a new MQTT Client object
mqtt_client = MQTT.MQTT(
broker="io.adafruit.com",
port=1883,
username=secrets["aio_username"],
password=secrets["aio_key"],
socket_pool=pool,
ssl_context=ssl_context,
)

# Initialize an Adafruit IO MQTT Client
Expand Down
8 changes: 5 additions & 3 deletions examples/adafruit_io_mqtt/adafruit_io_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_connection_manager
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
import neopixel
import adafruit_minimqtt.adafruit_minimqtt as MQTT
from adafruit_io.adafruit_io import IO_MQTT
Expand Down Expand Up @@ -85,15 +86,16 @@ def message(client, feed_id, payload):
wifi.connect()
print("Connected!")

# Initialize MQTT interface with the esp interface
MQTT.set_socket(socket, esp)
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)

# Initialize a new MQTT Client object
mqtt_client = MQTT.MQTT(
broker="io.adafruit.com",
port=1883,
username=secrets["aio_username"],
password=secrets["aio_key"],
socket_pool=pool,
ssl_context=ssl_context,
)

# Initialize an Adafruit IO MQTT Client
Expand Down
8 changes: 5 additions & 3 deletions examples/adafruit_io_mqtt/adafruit_io_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_connection_manager
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
import neopixel


Expand Down Expand Up @@ -85,15 +86,16 @@ def message(client, feed_id, payload):
wifi.connect()
print("Connected!")

# Initialize MQTT interface with the esp interface
MQTT.set_socket(socket, esp)
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)

# Initialize a new MQTT Client object
mqtt_client = MQTT.MQTT(
broker="io.adafruit.com",
port=1883,
username=secrets["aio_username"],
password=secrets["aio_key"],
socket_pool=pool,
ssl_context=ssl_context,
)

# Initialize an Adafruit IO MQTT Client
Expand Down
8 changes: 5 additions & 3 deletions examples/adafruit_io_mqtt/adafruit_io_pubsub_rp2040.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import board
import busio
from digitalio import DigitalInOut
import adafruit_connection_manager
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_esp32spi.adafruit_esp32spi_socket as pool
import adafruit_minimqtt.adafruit_minimqtt as MQTT
from adafruit_io.adafruit_io import IO_MQTT

Expand Down Expand Up @@ -70,15 +71,16 @@ def on_led_msg(client, topic, message):
wifi.connect()
print("Connected!")

# Initialize MQTT interface with the esp interface
MQTT.set_socket(socket, esp)
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, esp)

# Initialize a new MQTT Client object
mqtt_client = MQTT.MQTT(
broker="io.adafruit.com",
port=1883,
username=secrets["aio_username"],
password=secrets["aio_key"],
socket_pool=pool,
ssl_context=ssl_context,
)

# Initialize an Adafruit IO MQTT Client
Expand Down
8 changes: 5 additions & 3 deletions examples/adafruit_io_mqtt/adafruit_io_simpletest_cellular.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import busio
import digitalio

import adafruit_connection_manager
from adafruit_fona.adafruit_fona import FONA
from adafruit_fona.adafruit_fona_gsm import GSM
import adafruit_fona.adafruit_fona_socket as cellular_socket
import adafruit_fona.adafruit_fona_socket as pool

import adafruit_minimqtt.adafruit_minimqtt as MQTT
from adafruit_io.adafruit_io import IO_MQTT
Expand Down Expand Up @@ -82,15 +83,16 @@ def message(client, feed_id, payload):
print("Feed {0} received new value: {1}".format(feed_id, payload))


# Initialize MQTT interface with the ethernet interface
MQTT.set_socket(cellular_socket, fona)
ssl_context = adafruit_connection_manager.create_fake_ssl_context(pool, fona)

# Initialize a new MQTT Client object
mqtt_client = MQTT.MQTT(
broker="io.adafruit.com",
port=1883,
username=secrets["aio_username"],
password=secrets["aio_key"],
socket_pool=pool,
ssl_context=ssl_context,
)

# Initialize an Adafruit IO MQTT Client
Expand Down
Loading

0 comments on commit 637b274

Please sign in to comment.