11# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22# SPDX-License-Identifier: MIT
33
4+ import os
45import time
56import board
67import busio
78from digitalio import DigitalInOut
89import neopixel
910from adafruit_esp32spi import adafruit_esp32spi
10- from adafruit_esp32spi import adafruit_esp32spi_wifimanager
1111import adafruit_esp32spi .adafruit_esp32spi_socket as socket
1212
1313import adafruit_minimqtt .adafruit_minimqtt as MQTT
1414
15- ### WiFi ###
15+ # Add settings.toml to your filesystem CIRCUITPY_WIFI_SSID and CIRCUITPY_WIFI_PASSWORD keys
16+ # with your WiFi credentials. Add your Adafruit IO username and key as well.
17+ # DO NOT share that file or commit it into Git or other source control.
1618
17- # Get wifi details and more from a secrets.py file
18- try :
19- from secrets import secrets
20- except ImportError :
21- print ("WiFi secrets are kept in secrets.py, please add them there!" )
22- raise
19+ aio_username = os .getenv ('aio_username' )
20+ aio_key = os .getenv ('aio_key' )
2321
2422# If you are using a board with pre-defined ESP32 Pins:
2523esp32_cs = DigitalInOut (board .ESP_CS )
4644# GREEN_LED = PWMOut.PWMOut(esp, 27)
4745# BLUE_LED = PWMOut.PWMOut(esp, 25)
4846# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
49- wifi = adafruit_esp32spi_wifimanager .ESPSPI_WiFiManager (esp , secrets , status_light )
5047
5148### Feeds ###
5249
5350# Setup a feed named 'photocell' for publishing to a feed
54- photocell_feed = secrets [ " aio_username" ] + "/feeds/photocell"
51+ photocell_feed = aio_username + "/feeds/photocell"
5552
5653# Setup a feed named 'onoff' for subscribing to changes
57- onoff_feed = secrets [ " aio_username" ] + "/feeds/onoff"
54+ onoff_feed = aio_username + "/feeds/onoff"
5855
5956### Code ###
6057
@@ -81,7 +78,7 @@ def message(client, topic, message):
8178
8279# Connect to WiFi
8380print ("Connecting to WiFi..." )
84- wifi . connect ( )
81+ esp . connect_AP ( os . getenv ( 'CIRCUITPY_WIFI_SSID' ), os . getenv ( 'CIRCUITPY_WIFI_PASSWORD' ) )
8582print ("Connected!" )
8683
8784# Initialize MQTT interface with the esp interface
@@ -90,8 +87,8 @@ def message(client, topic, message):
9087# Set up a MiniMQTT Client
9188mqtt_client = MQTT .MQTT (
9289 broker = "io.adafruit.com" ,
93- username = secrets [ " aio_username" ] ,
94- password = secrets [ " aio_key" ] ,
90+ username = aio_username ,
91+ password = aio_key ,
9592)
9693
9794# Setup the callback methods above
0 commit comments