Code: Select all
File "code.py", line 5, in <module>
ImportError: no module named 'socketpool
Moderators: adafruit_support_bill, adafruit
Code: Select all
File "code.py", line 5, in <module>
ImportError: no module named 'socketpool
Code: Select all
import time
import board
import displayio
import terminalio
import socketpool
import wifi
from adafruit_display_text.label import Label
from adafruit_bitmap_font import bitmap_font
from adafruit_matrixportal.network import Network
from adafruit_matrixportal.matrix import Matrix
import adafruit_minimqtt.adafruit_minimqtt as MQTT
BLINK = True
DEBUG = False
# Get wifi details and more from a secrets.py file
try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise
# Set your Adafruit IO Username and Key in secrets.py
# (visit io.adafruit.com if you need to create an account,
# or if you need your Adafruit IO key.)
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
# Setup a feed named 'onoff' for subscribing to changes
color_feed = secrets["aio_username"] + "/feeds/color-feed"
# Define callback methods which are called when events occur
# pylint: disable=unused-argument, redefined-outer-name
def connected(client, userdata, flags, rc):
# This function will be called when the client is connected
# successfully to the broker.
print("Connected to Adafruit IO! Listening for topic changes on %s" % onoff_feed)
# Subscribe to all changes on the onoff_feed.
client.subscribe(color-feed)
def disconnected(client, userdata, rc):
# This method is called when the client is disconnected
print("Disconnected from Adafruit IO!")
def message(client, topic, message):
# This method is called when a topic the client is subscribed to
# has a new message.
print("New message on topic {0}: {1}".format(topic, message))
# Create a socket pool
pool = socketpool.SocketPool(wifi.radio)
# Set up a MiniMQTT Client
mqtt_client = MQTT.MQTT(
broker='io.adafruit.com',
port=1883,
username=secrets["aio_username"],
password=secrets["aio_key"],
socket_pool=pool,
ssl_context=ssl.create_default_context(),
)
# Setup the callback methods above
mqtt_client.on_connect = connected
mqtt_client.on_disconnect = disconnected
mqtt_client.on_message = message
# Connect the client to the MQTT broker.
print("Connecting to Adafruit IO...")
mqtt_client.connect()
print("Open/Close SW Init")
# --- Display setup ---
matrix = Matrix()
display = matrix.display
network = Network(status_neopixel=board.NEOPIXEL, debug=False)
# --- Drawing setup ---
group = displayio.Group(max_size=4) # Create a Group
bitmap = displayio.Bitmap(64, 32, 2) # Create a bitmap object,width, height, bit depth
color = displayio.Palette(4) # Create a color palette
color[0] = 0x000000 # black background
color[1] = 0xFF0000 # red
color[2] = 0xCC4000 # amber
color[3] = 0x85FF00 # greenish:w
print(network.get_local_time())
# Create a TileGrid using the Bitmap and Palette
tile_grid = displayio.TileGrid(bitmap, pixel_shader=color)
group.append(tile_grid) # Add the TileGrid to the Group
display.show(group)
if not DEBUG:
font = bitmap_font.load_font("/IBMPlexMono-Medium-24_jep.bdf")
else:
font = terminalio.FONT
clock_label = Label(font, color=color[1], scale=1, text='CLOSED')
clock_label.y = display.height // 2
group.append(clock_label)
while True:
time.sleep(1)
Code: Select all
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
Code: Select all
import time
import board
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal
# --- Display setup ---
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=False)
feed = matrixportal.get_io_feed("color-feed", detailed=True)
value = feed["details"]["data"]["last"]["value"]
print(value)