diff --git a/adafruit_esp32spi/adafruit_esp32spi.py b/adafruit_esp32spi/adafruit_esp32spi.py index 346593a..e2c16ea 100644 --- a/adafruit_esp32spi/adafruit_esp32spi.py +++ b/adafruit_esp32spi/adafruit_esp32spi.py @@ -28,6 +28,7 @@ import struct import time +import warnings from micropython import const from adafruit_bus_device.spi_device import SPIDevice from digitalio import Direction @@ -660,9 +661,13 @@ def connect(self, ssid, password=None, timeout=10): **Deprecated functionality:** If the first argument (``ssid``) is a ``dict``, assume it is a dictionary with entries for keys ``"ssid"`` and, optionally, ``"password"``. This mimics the previous signature for ``connect()``. - This upward compatbility will be removed in a future release. + This upward compatibility will be removed in a future release. """ if isinstance(ssid, dict): # secrets + warnings.warn( + "The passing in of `secrets`, is deprecated. Use connect() with `ssid` and " + "`password` instead and fetch values from settings.toml with `os.getenv()`." + ) ssid, password = ssid["ssid"], ssid.get("password") self.connect_AP(ssid, password, timeout_s=timeout) diff --git a/adafruit_esp32spi/adafruit_esp32spi_wifimanager.py b/adafruit_esp32spi/adafruit_esp32spi_wifimanager.py index 68cd058..4db7463 100755 --- a/adafruit_esp32spi/adafruit_esp32spi_wifimanager.py +++ b/adafruit_esp32spi/adafruit_esp32spi_wifimanager.py @@ -13,6 +13,7 @@ # pylint: disable=no-name-in-module +import warnings from time import sleep from micropython import const import adafruit_connection_manager @@ -21,7 +22,7 @@ # pylint: disable=too-many-instance-attributes -class ESPSPI_WiFiManager: +class WiFiManager: """ A class to help manage the Wifi connection """ @@ -33,7 +34,11 @@ class ESPSPI_WiFiManager: def __init__( self, esp, - secrets, + ssid, + password=None, + *, + enterprise_ident=None, + enterprise_user=None, status_pixel=None, attempts=2, connection_type=NORMAL, @@ -41,9 +46,11 @@ def __init__( ): """ :param ESP_SPIcontrol esp: The ESP object we are using - :param dict secrets: The WiFi and Adafruit IO secrets dict (See examples) - The use of secrets.py to populate the secrets dict is depreciated - in favor of using settings.toml. + :param str ssid: the SSID of the access point. Must be less than 32 chars. + :param str password: the password for the access point. Must be 8-63 chars. + :param str enterprise_ident: the ident to use when connecting to an enterprise access point. + :param str enterprise_user: the username to use when connecting to an enterprise access + point. :param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar, or RGB LED (default=None). The status LED, if given, turns red when attempting to connect to a Wi-Fi network or create an access point, @@ -57,8 +64,8 @@ def __init__( # Read the settings self.esp = esp self.debug = debug - self.ssid = secrets["ssid"] - self.password = secrets.get("password", None) + self.ssid = ssid + self.password = password self.attempts = attempts self._connection_type = connection_type self.statuspix = status_pixel @@ -70,11 +77,11 @@ def __init__( 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", "") - self.ent_user = secrets.get("ent_user") - self.ent_password = secrets.get("ent_password") + # Check for WPA2 Enterprise values + self.ent_ssid = ssid + self.ent_ident = enterprise_ident + self.ent_user = enterprise_user + self.ent_password = password # pylint: enable=too-many-arguments @@ -97,9 +104,9 @@ def connect(self): print("MAC addr:", [hex(i) for i in self.esp.MAC_address]) for access_pt in self.esp.scan_networks(): print("\t%s\t\tRSSI: %d" % (access_pt.ssid, access_pt.rssi)) - if self._connection_type == ESPSPI_WiFiManager.NORMAL: + if self._connection_type == WiFiManager.NORMAL: self.connect_normal() - elif self._connection_type == ESPSPI_WiFiManager.ENTERPRISE: + elif self._connection_type == WiFiManager.ENTERPRISE: self.connect_enterprise() else: raise TypeError("Invalid WiFi connection type specified") @@ -347,3 +354,53 @@ def signal_strength(self): if not self.esp.is_connected: self.connect() return self.esp.ap_info.rssi + + +# pylint: disable=too-many-instance-attributes +class ESPSPI_WiFiManager(WiFiManager): + """ + A legacy class to help manage the Wifi connection. Please update to using WiFiManager + """ + + # pylint: disable=too-many-arguments + def __init__( + self, + esp, + secrets, + status_pixel=None, + attempts=2, + connection_type=WiFiManager.NORMAL, + debug=False, + ): + """ + :param ESP_SPIcontrol esp: The ESP object we are using + :param dict secrets: The WiFi secrets dict + The use of secrets.py to populate the secrets dict is deprecated + in favor of using settings.toml. + :param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar, + or RGB LED (default=None). The status LED, if given, turns red when + attempting to connect to a Wi-Fi network or create an access point, + turning green upon success. Additionally, if given, it will turn blue + when attempting an HTTP method or returning IP address, turning off + upon success. + :type status_pixel: NeoPixel, DotStar, or RGB LED + :param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2) + :param const connection_type: (Optional) Type of WiFi connection: NORMAL or ENTERPRISE + """ + + warnings.warn( + "ESP32WiFiManager, which uses `secrets`, is deprecated. Use WifiManager instead and " + "fetch values from settings.toml with `os.getenv()`." + ) + + super().__init__( + esp=esp, + ssid=secrets.get("ssid"), + password=secrets.get("password"), + enterprise_ident=secrets.get("ent_ident", ""), + enterprise_user=secrets.get("ent_user"), + status_pixel=status_pixel, + attempts=attempts, + connection_type=connection_type, + debug=debug, + ) diff --git a/examples/esp32spi_aio_post.py b/examples/esp32spi_aio_post.py index c4b5f7f..9438856 100644 --- a/examples/esp32spi_aio_post.py +++ b/examples/esp32spi_aio_post.py @@ -8,28 +8,18 @@ from digitalio import DigitalInOut import neopixel from adafruit_esp32spi import adafruit_esp32spi -from adafruit_esp32spi import adafruit_esp32spi_wifimanager +from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager print("ESP32 SPI webclient test") # Get wifi details and more from a settings.toml file # tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD -# CIRCUITPY_AIO_USERNAME, CIRCUITPY_AIO_KEY -secrets = {} -for token in ["ssid", "password"]: - if getenv("CIRCUITPY_WIFI_" + token.upper()): - secrets[token] = getenv("CIRCUITPY_WIFI_" + token.upper()) -for token in ["aio_username", "aio_key"]: - if getenv("CIRCUITPY_" + token.upper()): - secrets[token] = getenv("CIRCUITPY_" + token.upper()) +# ADAFRUIT_AIO_USERNAME, ADAFRUIT_AIO_KEY +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") -if not secrets: - try: - # Fallback on secrets.py until depreciation is over and option is removed - from secrets import secrets - except ImportError: - print("WiFi secrets are kept in settings.toml, please add them there!") - raise +aio_username = getenv("ADAFRUIT_AIO_USERNAME") +aio_key = getenv("ADAFRUIT_AIO_KEY") # If you are using a board with pre-defined ESP32 Pins: esp32_cs = DigitalInOut(board.ESP_CS) @@ -48,18 +38,18 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) """Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) """Uncomment below for an externally defined RGB LED (including Arduino Nano Connect)""" # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +wifi = WiFiManager(esp, ssid, password, status_pixel=status_pixel) counter = 0 @@ -71,12 +61,12 @@ payload = {"value": data} response = wifi.post( "https://io.adafruit.com/api/v2/" - + secrets["aio_username"] + + aio_username + "/feeds/" + feed + "/data", json=payload, - headers={"X-AIO-KEY": secrets["aio_key"]}, + headers={"X-AIO-KEY": aio_key}, ) print(response.json()) response.close() diff --git a/examples/esp32spi_cheerlights.py b/examples/esp32spi_cheerlights.py index 9bac915..735dd4a 100644 --- a/examples/esp32spi_cheerlights.py +++ b/examples/esp32spi_cheerlights.py @@ -11,21 +11,12 @@ import adafruit_fancyled.adafruit_fancyled as fancy from adafruit_esp32spi import adafruit_esp32spi -from adafruit_esp32spi import adafruit_esp32spi_wifimanager +from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager # Get wifi details and more from a settings.toml file # tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD -secrets = { - "ssid": getenv("CIRCUITPY_WIFI_SSID"), - "password": getenv("CIRCUITPY_WIFI_PASSWORD"), -} -if secrets == {"ssid": None, "password": None}: - try: - # Fallback on secrets.py until depreciation is over and option is removed - from secrets import secrets - except ImportError: - print("WiFi secrets are kept in settings.toml, please add them there!") - raise +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") print("ESP32 SPI webclient test") @@ -49,17 +40,17 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) """Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) """Uncomment below for an externally defined RGB LED (including Arduino Nano Connect)""" # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +wifi = WiFiManager(esp, ssid, password, status_pixel=status_pixel) # neopixels pixels = neopixel.NeoPixel(board.A1, 16, brightness=0.3) diff --git a/examples/esp32spi_ipconfig.py b/examples/esp32spi_ipconfig.py index 7e98df6..dec0f3a 100644 --- a/examples/esp32spi_ipconfig.py +++ b/examples/esp32spi_ipconfig.py @@ -11,17 +11,8 @@ # Get wifi details and more from a settings.toml file # tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD -secrets = { - "ssid": getenv("CIRCUITPY_WIFI_SSID"), - "password": getenv("CIRCUITPY_WIFI_PASSWORD"), -} -if secrets == {"ssid": None, "password": None}: - try: - # Fallback on secrets.py until depreciation is over and option is removed - from secrets import secrets - except ImportError: - print("WiFi secrets are kept in settings.toml, please add them there!") - raise +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") HOSTNAME = "esp32-spi-hostname-test" @@ -66,7 +57,7 @@ print("Connecting to AP...") while not esp.is_connected: try: - esp.connect_AP(secrets["ssid"], secrets["password"]) + esp.connect_AP(ssid, password) except OSError as e: print("could not connect to AP, retrying: ", e) continue diff --git a/examples/esp32spi_localtime.py b/examples/esp32spi_localtime.py index b6ee671..53f8efa 100644 --- a/examples/esp32spi_localtime.py +++ b/examples/esp32spi_localtime.py @@ -9,21 +9,12 @@ import neopixel import rtc from adafruit_esp32spi import adafruit_esp32spi -from adafruit_esp32spi import adafruit_esp32spi_wifimanager +from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager # Get wifi details and more from a settings.toml file # tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD -secrets = { - "ssid": getenv("CIRCUITPY_WIFI_SSID"), - "password": getenv("CIRCUITPY_WIFI_PASSWORD"), -} -if secrets == {"ssid": None, "password": None}: - try: - # Fallback on secrets.py until depreciation is over and option is removed - from secrets import secrets - except ImportError: - print("WiFi secrets are kept in settings.toml, please add them there!") - raise +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") print("ESP32 local time") @@ -47,18 +38,18 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) """Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) """Uncomment below for an externally defined RGB LED (including Arduino Nano Connect)""" # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light) +wifi = WiFiManager(esp, ssid, password, status_pixel=status_pixel) the_rtc = rtc.RTC() diff --git a/examples/esp32spi_settings.toml b/examples/esp32spi_settings.toml index 16208bd..4f5866e 100644 --- a/examples/esp32spi_settings.toml +++ b/examples/esp32spi_settings.toml @@ -10,5 +10,5 @@ CIRCUITPY_WIFI_SSID="yourssid" CIRCUITPY_WIFI_PASSWORD="yourpassword" CIRCUITPY_TIMEZONE="America/New_York" -CIRCUITPY_AIO_USERNAME="youraiousername" -CIRCUITPY_AIO_KEY="youraiokey" +ADAFRUIT_AIO_USERNAME="youraiousername" +ADAFRUIT_AIO_KEY="youraiokey" diff --git a/examples/esp32spi_simpletest.py b/examples/esp32spi_simpletest.py index c194648..d9a8edf 100644 --- a/examples/esp32spi_simpletest.py +++ b/examples/esp32spi_simpletest.py @@ -11,17 +11,8 @@ # Get wifi details and more from a settings.toml file # tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD -secrets = { - "ssid": getenv("CIRCUITPY_WIFI_SSID"), - "password": getenv("CIRCUITPY_WIFI_PASSWORD"), -} -if secrets == {"ssid": None, "password": None}: - try: - # Fallback on secrets.py until depreciation is over and option is removed - from secrets import secrets - except ImportError: - print("WiFi secrets are kept in settings.toml, please add them there!") - raise +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") print("ESP32 SPI webclient test") @@ -72,7 +63,7 @@ print("Connecting to AP...") while not esp.is_connected: try: - esp.connect_AP(secrets["ssid"], secrets["password"]) + esp.connect_AP(ssid, password) except OSError as e: print("could not connect to AP, retrying: ", e) continue diff --git a/examples/esp32spi_simpletest_rp2040.py b/examples/esp32spi_simpletest_rp2040.py index eb5b8dd..1ee3fd6 100644 --- a/examples/esp32spi_simpletest_rp2040.py +++ b/examples/esp32spi_simpletest_rp2040.py @@ -11,17 +11,8 @@ # Get wifi details and more from a settings.toml file # tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD -secrets = { - "ssid": getenv("CIRCUITPY_WIFI_SSID"), - "password": getenv("CIRCUITPY_WIFI_PASSWORD"), -} -if secrets == {"ssid": None, "password": None}: - try: - # Fallback on secrets.py until depreciation is over and option is removed - from secrets import secrets - except ImportError: - print("WiFi secrets are kept in settings.toml, please add them there!") - raise +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") print("Raspberry Pi RP2040 - ESP32 SPI webclient test") @@ -51,7 +42,7 @@ print("Connecting to AP...") while not esp.is_connected: try: - esp.connect_AP(secrets["ssid"], secrets["password"]) + esp.connect_AP(ssid, password) except OSError as e: print("could not connect to AP, retrying: ", e) continue diff --git a/examples/esp32spi_tcp_client.py b/examples/esp32spi_tcp_client.py index 2ec5d2a..275c1ce 100644 --- a/examples/esp32spi_tcp_client.py +++ b/examples/esp32spi_tcp_client.py @@ -10,17 +10,8 @@ # Get wifi details and more from a settings.toml file # tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD -secrets = { - "ssid": getenv("CIRCUITPY_WIFI_SSID"), - "password": getenv("CIRCUITPY_WIFI_PASSWORD"), -} -if secrets == {"ssid": None, "password": None}: - try: - # Fallback on secrets.py until depreciation is over and option is removed - from secrets import secrets # pylint: disable=no-name-in-module - except ImportError: - print("WiFi secrets are kept in settings.toml, please add them there!") - raise +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") TIMEOUT = 5 # edit host and port to match server @@ -42,7 +33,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) # connect to wifi AP -esp.connect(secrets) +esp.connect(ssid, password) # test for connectivity to server print("Server ping:", esp.ping(HOST), "ms") diff --git a/examples/esp32spi_udp_client.py b/examples/esp32spi_udp_client.py index 3dace7b..2321c03 100644 --- a/examples/esp32spi_udp_client.py +++ b/examples/esp32spi_udp_client.py @@ -12,17 +12,8 @@ # Get wifi details and more from a settings.toml file # tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD -secrets = { - "ssid": getenv("CIRCUITPY_WIFI_SSID"), - "password": getenv("CIRCUITPY_WIFI_PASSWORD"), -} -if secrets == {"ssid": None, "password": None}: - try: - # Fallback on secrets.py until depreciation is over and option is removed - from secrets import secrets # pylint: disable=no-name-in-module - except ImportError: - print("WiFi secrets are kept in settings.toml, please add them there!") - raise +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") TIMEOUT = 5 # edit host and port to match server @@ -45,7 +36,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) # connect to wifi AP -esp.connect(secrets) +esp.connect(ssid, password) # test for connectivity to server print("Server ping:", esp.ping(HOST), "ms") diff --git a/examples/esp32spi_wpa2ent_aio_post.py b/examples/esp32spi_wpa2ent_aio_post.py index 197f279..d9f62d1 100644 --- a/examples/esp32spi_wpa2ent_aio_post.py +++ b/examples/esp32spi_wpa2ent_aio_post.py @@ -8,28 +8,21 @@ from digitalio import DigitalInOut import neopixel from adafruit_esp32spi import adafruit_esp32spi -from adafruit_esp32spi.adafruit_esp32spi_wifimanager import ESPSPI_WiFiManager +from adafruit_esp32spi.adafruit_esp32spi_wifimanager import WiFiManager print("ESP32 SPI WPA2 Enterprise webclient test") # Get wifi details and more from a settings.toml file -# tokens used by this Demo: CIRCUITPY_AIO_USERNAME, CIRCUITPY_AIO_KEY, -# CIRCUITPY_WIFI_ENT_SSID, CIRCUITPY_WIFI_ENT_PASSWORD, -# CIRCUITPY_WIFI_ENT_USER, CIRCUITPY_WIFI_ENT_IDENT -secrets = {} -for token in ["ssid", "password", "user", "ident"]: - if getenv("CIRCUITPY_WIFI_ENT_" + token.upper()): - secrets[token] = getenv("CIRCUITPY_WIFI_" + token.upper()) -for token in ["aio_username", "aio_key"]: - if getenv("CIRCUITPY_" + token.upper()): - secrets[token] = getenv("CIRCUITPY_" + token.upper()) -if not secrets: - try: - # Fallback on secrets.py until depreciation is over and option is removed - from secrets import secrets # pylint: disable=no-name-in-module - except ImportError: - print("WiFi secrets are kept in settings.toml, please add them there!") - raise +# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD, +# CIRCUITPY_WIFI_ENT_USER, CIRCUITPY_WIFI_ENT_IDENT, +# ADAFRUIT_AIO_USERNAME, ADAFRUIT_AIO_KEY +ssid = getenv("CIRCUITPY_WIFI_SSID") +password = getenv("CIRCUITPY_WIFI_PASSWORD") +enterprise_ident = getenv("CIRCUITPY_WIFI_ENT_IDENT") +enterprise_user = getenv("CIRCUITPY_WIFI_ENT_USER") + +aio_username = getenv("ADAFRUIT_AIO_USERNAME") +aio_key = getenv("ADAFRUIT_AIO_KEY") # ESP32 setup # If your board does define the three pins listed below, @@ -51,19 +44,25 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) """Use below for Most Boards""" -status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) +status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) """Uncomment below for ItsyBitsy M4""" -# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) +# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) """Uncomment below for an externally defined RGB LED (including Arduino Nano Connect)""" # import adafruit_rgbled # from adafruit_esp32spi import PWMOut # RED_LED = PWMOut.PWMOut(esp, 26) # GREEN_LED = PWMOut.PWMOut(esp, 27) # BLUE_LED = PWMOut.PWMOut(esp, 25) -# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) +# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED) -wifi = ESPSPI_WiFiManager( - esp, secrets, status_light, connection_type=ESPSPI_WiFiManager.ENTERPRISE +wifi = WiFiManager( + esp, + ssid, + password, + enterprise_ident=enterprise_ident, + enterprise_user=enterprise_user, + status_pixel=status_pixel, + connection_type=WiFiManager.ENTERPRISE, ) counter = 0 @@ -76,12 +75,12 @@ payload = {"value": data} response = wifi.post( "https://io.adafruit.com/api/v2/" - + secrets["aio_username"] + + aio_username + "/feeds/" + feed + "/data", json=payload, - headers={"X-AIO-KEY": secrets["aio_key"]}, + headers={"X-AIO-KEY": aio_key}, ) print(response.json()) response.close()
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: