1
1
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2
2
# SPDX-License-Identifier: MIT
3
3
4
+ import os
4
5
import time
5
6
import board
6
7
import busio
7
8
from digitalio import DigitalInOut
8
9
import neopixel
9
10
from adafruit_esp32spi import adafruit_esp32spi
10
- from adafruit_esp32spi import adafruit_esp32spi_wifimanager
11
11
import adafruit_esp32spi .adafruit_esp32spi_socket as socket
12
12
13
13
import adafruit_minimqtt .adafruit_minimqtt as MQTT
14
14
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.
16
18
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' )
23
21
24
22
# If you are using a board with pre-defined ESP32 Pins:
25
23
esp32_cs = DigitalInOut (board .ESP_CS )
46
44
# GREEN_LED = PWMOut.PWMOut(esp, 27)
47
45
# BLUE_LED = PWMOut.PWMOut(esp, 25)
48
46
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
49
- wifi = adafruit_esp32spi_wifimanager .ESPSPI_WiFiManager (esp , secrets , status_light )
50
47
51
48
### Feeds ###
52
49
53
50
# 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"
55
52
56
53
# Setup a feed named 'onoff' for subscribing to changes
57
- onoff_feed = secrets [ " aio_username" ] + "/feeds/onoff"
54
+ onoff_feed = aio_username + "/feeds/onoff"
58
55
59
56
### Code ###
60
57
@@ -81,7 +78,7 @@ def message(client, topic, message):
81
78
82
79
# Connect to WiFi
83
80
print ("Connecting to WiFi..." )
84
- wifi . connect ( )
81
+ esp . connect_AP ( os . getenv ( 'CIRCUITPY_WIFI_SSID' ), os . getenv ( 'CIRCUITPY_WIFI_PASSWORD' ) )
85
82
print ("Connected!" )
86
83
87
84
# Initialize MQTT interface with the esp interface
@@ -90,8 +87,8 @@ def message(client, topic, message):
90
87
# Set up a MiniMQTT Client
91
88
mqtt_client = MQTT .MQTT (
92
89
broker = "io.adafruit.com" ,
93
- username = secrets [ " aio_username" ] ,
94
- password = secrets [ " aio_key" ] ,
90
+ username = aio_username ,
91
+ password = aio_key ,
95
92
)
96
93
97
94
# Setup the callback methods above
0 commit comments