From 66948648285ce1b044e2666c4159681c48d56209 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Mon, 12 Apr 2021 09:58:25 -0700 Subject: [PATCH 1/2] Fix issue with checking if esp is connected --- adafruit_matrixportal/wifi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_matrixportal/wifi.py b/adafruit_matrixportal/wifi.py index 5312887..f298f39 100755 --- a/adafruit_matrixportal/wifi.py +++ b/adafruit_matrixportal/wifi.py @@ -77,7 +77,7 @@ def __init__(self, *, status_neopixel=None, esp=None, external_spi=None): ) requests.set_socket(socket, self.esp) - if esp.is_connected: + if self.esp.is_connected: self.requests = requests self._manager = None From 1f249440ae02eb7ed9cdb92d02dd9b870fefec02 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 22 Apr 2021 10:14:24 -0700 Subject: [PATCH 2/2] Make use of the new PortalBase WiFi modules --- adafruit_matrixportal/network.py | 10 ++- adafruit_matrixportal/wifi.py | 118 ------------------------------- docs/api.rst | 3 - 3 files changed, 9 insertions(+), 122 deletions(-) delete mode 100755 adafruit_matrixportal/wifi.py diff --git a/adafruit_matrixportal/network.py b/adafruit_matrixportal/network.py index 8d7b953..90aee94 100755 --- a/adafruit_matrixportal/network.py +++ b/adafruit_matrixportal/network.py @@ -27,8 +27,9 @@ """ import gc +import neopixel from adafruit_portalbase.network import NetworkBase -from adafruit_matrixportal.wifi import WiFi +from adafruit_portalbase.wifi_coprocessor import WiFi __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal.git" @@ -55,6 +56,13 @@ def __init__(self, **kwargs): extract_values = kwargs.pop("extract_values") if "debug" in kwargs: debug = kwargs.pop("debug") + + if "status_neopixel" in kwargs: + status_neopixel = kwargs.pop("status_neopixel") + status_led = neopixel.NeoPixel(status_neopixel, 1, brightness=0.2) + else: + status_led = None + kwargs["status_led"] = status_led wifi = WiFi(**kwargs) super().__init__( diff --git a/adafruit_matrixportal/wifi.py b/adafruit_matrixportal/wifi.py deleted file mode 100755 index f298f39..0000000 --- a/adafruit_matrixportal/wifi.py +++ /dev/null @@ -1,118 +0,0 @@ -# SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense -""" -`adafruit_matrixportal.wifi` -================================================================================ - -Helper library for the MatrixPortal M4 or Adafruit RGB Matrix Shield + Metro M4 Airlift Lite. - -* Author(s): Melissa LeBlanc-Williams - -Implementation Notes --------------------- - -**Hardware:** - -* `Adafruit MatrixPortal M4 `_ -* `Adafruit Metro M4 Express AirLift `_ -* `Adafruit RGB Matrix Shield `_ -* `64x32 RGB LED Matrix `_ - -**Software and Dependencies:** - -* Adafruit CircuitPython firmware for the supported boards: - https://github.com/adafruit/circuitpython/releases - -""" - -import gc -import board -import busio -from digitalio import DigitalInOut -import neopixel -from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager -import adafruit_esp32spi.adafruit_esp32spi_socket as socket -import adafruit_requests as requests - -__version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal.git" - - -class WiFi: - """Class representing the ESP. - - :param status_neopixel: The pin for the status NeoPixel. Use ``board.NEOPIXEL`` for the on-board - NeoPixel. Defaults to ``None``, not the status LED - :param esp: A passed ESP32 object, Can be used in cases where the ESP32 chip needs to be used - before calling the pyportal class. Defaults to ``None``. - :param busio.SPI external_spi: A previously declared spi object. Defaults to ``None``. - - """ - - def __init__(self, *, status_neopixel=None, esp=None, external_spi=None): - - if status_neopixel: - self.neopix = neopixel.NeoPixel(status_neopixel, 1, brightness=0.2) - else: - self.neopix = None - self.neo_status(0) - self.requests = None - - if esp: # If there was a passed ESP Object - self.esp = esp - if external_spi: # If SPI Object Passed - spi = external_spi - else: # Else: Make ESP32 connection - spi = busio.SPI(board.SCK, board.MOSI, board.MISO) - else: - esp32_ready = DigitalInOut(board.ESP_BUSY) - esp32_gpio0 = DigitalInOut(board.ESP_GPIO0) - esp32_reset = DigitalInOut(board.ESP_RESET) - esp32_cs = DigitalInOut(board.ESP_CS) - spi = busio.SPI(board.SCK, board.MOSI, board.MISO) - - self.esp = adafruit_esp32spi.ESP_SPIcontrol( - spi, esp32_cs, esp32_ready, esp32_reset, esp32_gpio0 - ) - - requests.set_socket(socket, self.esp) - if self.esp.is_connected: - self.requests = requests - self._manager = None - - gc.collect() - - def connect(self, ssid, password): - """ - Connect to WiFi using the settings found in secrets.py - """ - self.esp.connect({"ssid": ssid, "password": password}) - self.requests = requests - - def neo_status(self, value): - """The status NeoPixel. - - :param value: The color to change the NeoPixel. - - """ - if self.neopix: - self.neopix.fill(value) - - def manager(self, secrets): - """Initialize the WiFi Manager if it hasn't been cached and return it""" - if self._manager is None: - self._manager = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager( - self.esp, secrets, None - ) - return self._manager - - @property - def is_connected(self): - """Return whether we are connected.""" - return self.esp.is_connected - - @property - def enabled(self): - """Not currently disablable on the ESP32 Coprocessor""" - return True diff --git a/docs/api.rst b/docs/api.rst index 97f7fa8..9e5eecc 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -11,6 +11,3 @@ .. automodule:: adafruit_matrixportal.network :members: - -.. automodule:: adafruit_matrixportal.wifi - :members: