Skip to content

Commit 1434532

Browse files
committed
update settings to secrets
1 parent abf17e7 commit 1434532

File tree

7 files changed

+25
-23
lines changed

7 files changed

+25
-23
lines changed

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,10 @@ def is_connected(self):
410410
self.reset()
411411
return False
412412

413-
def connect(self, settings):
414-
"""Connect to an access point using a settings dictionary
413+
def connect(self, secrets):
414+
"""Connect to an access point using a secrets dictionary
415415
that contains a 'ssid' and 'password' entry"""
416-
self.connect_AP(settings['ssid'], settings['password'])
416+
self.connect_AP(secrets['ssid'], secrets['password'])
417417

418418
def connect_AP(self, ssid, password): # pylint: disable=invalid-name
419419
"""Connect to an access point with given name and password.

adafruit_esp32spi/adafruit_esp32spi_wifimanager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ class ESPSPI_WiFiManager:
3939
"""
4040
A class to help manage the Wifi connection
4141
"""
42-
def __init__(self, esp, settings, status_neopixel=None, attempts=2):
42+
def __init__(self, esp, secrets, status_neopixel=None, attempts=2):
4343
"""
4444
:param ESP_SPIcontrol esp: The ESP object we are using
45-
:param dict settings: The WiFi and Adafruit IO Settings (See examples)
45+
:param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
4646
:param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
4747
:param status_neopixel: (Optional) The neopixel pin - Usually board.NEOPIXEL (default=None)
4848
:type status_neopixel: Pin
4949
"""
5050
# Read the settings
5151
self._esp = esp
5252
self.debug = False
53-
self.ssid = settings['ssid']
54-
self.password = settings['password']
53+
self.ssid = secrets['ssid']
54+
self.password = secrets['password']
5555
self.attempts = attempts
5656
requests.set_interface(self._esp)
5757
if status_neopixel:

examples/esp32spi_aio_post.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88

99
print("ESP32 SPI webclient test")
1010

11-
# Get wifi details and more from a settings.py file
11+
# Get wifi details and more from a secrets.py file
1212
try:
13-
from esp32spi_settings import settings
13+
from esp32spi_secrets import secrets
1414
except ImportError:
15-
print("WiFi settings are kept in esp32spi_settings.py, please add them there!")
15+
print("WiFi secrets are kept in secrets.py, please add them there!")
1616
raise
1717

1818
esp32_cs = DigitalInOut(board.D9)
1919
esp32_ready = DigitalInOut(board.D10)
2020
esp32_reset = DigitalInOut(board.D5)
2121
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
2222
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
23-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, settings, board.NEOPIXEL)
23+
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, board.NEOPIXEL)
2424

2525
counter = 0
2626
while True:
@@ -30,8 +30,8 @@
3030
feed = 'test'
3131
payload = {'value':data}
3232
response = wifi.post(
33-
"https://io.adafruit.com/api/v2/"+settings['aio_username']+"/feeds/"+feed+"/data",
34-
json=payload,headers={bytes("X-AIO-KEY","utf-8"):bytes(settings['aio_key'],"utf-8")})
33+
"https://io.adafruit.com/api/v2/"+secrets['aio_username']+"/feeds/"+feed+"/data",
34+
json=payload,headers={bytes("X-AIO-KEY","utf-8"):bytes(secrets['aio_key'],"utf-8")})
3535
print(response.json())
3636
response.close()
3737
counter = counter + 1

examples/esp32spi_cheerlights.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import neopixel
1010
import adafruit_fancyled.adafruit_fancyled as fancy
1111

12-
# Get wifi details and more from a settings.py file
12+
# Get wifi details and more from a secrets.py file
1313
try:
14-
from esp32spi_settings import settings
14+
from esp32spi_secrets import secrets
1515
except ImportError:
16-
print("WiFi settings are kept in esp32spi_settings.py, please add them there!")
16+
print("WiFi secrets are kept in secrets.py, please add them there!")
1717
raise
1818

1919
print("ESP32 SPI webclient test")
@@ -26,7 +26,7 @@
2626
esp32_reset = DigitalInOut(board.D5)
2727
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
2828
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
29-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, settings, board.NEOPIXEL)
29+
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, board.NEOPIXEL)
3030

3131
# neopixels
3232
pixels = neopixel.NeoPixel(board.A1, 16, brightness=0.3)

examples/esp32spi_localtime.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
88
import rtc
99

10-
# Get wifi details and more from a settings.py file
10+
# Get wifi details and more from a secrets.py file
1111
try:
12-
from settings import settings
12+
from secrets import secrets
1313
except ImportError:
14-
print("WiFi settings are kept in settings.py, please add them there!")
14+
print("WiFi secrets are kept in secrets.py, please add them there!")
1515
raise
1616

1717
print("ESP32 local time")
@@ -24,7 +24,7 @@
2424
esp32_reset = DigitalInOut(microcontroller.pin.PB17)
2525
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
2626
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
27-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, settings, board.NEOPIXEL)
27+
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, board.NEOPIXEL)
2828

2929
the_rtc = rtc.RTC()
3030

examples/esp32spi_settings.py renamed to examples/esp32spi_secrets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is where you keep secret settings, passwords, and tokens!
22
# If you put them in the code you risk committing that info or sharing it
33

4-
settings = {
4+
secrets = {
55
'ssid' : 'yourssid',
66
'password' : 'yourpassword',
77
'timezone' : -5, # this is offset from UTC

examples/esp32spi_simpletest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
print("ESP32 found and in idle mode")
2424
print("Firmware vers.", esp.firmware_version)
2525
print("MAC addr:", [hex(i) for i in esp.MAC_address])
26+
2627
for ap in esp.scan_networks():
2728
print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi']))
29+
2830
print("Connecting to AP...")
29-
esp.connect_AP(b'adafruit', b'ffffffff')
31+
esp.connect_AP(b'MY_SSID_NAME', b'MY_SSID_PASSWORD')
3032
print("Connected to", str(esp.ssid, 'utf-8'), "\tRSSI:", esp.rssi)
3133
print("My IP address is", esp.pretty_ip(esp.ip_address))
3234
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))

0 commit comments

Comments
 (0)