diff --git a/adafruit_esp32spi/adafruit_esp32spi.py b/adafruit_esp32spi/adafruit_esp32spi.py index a492888..76e6cc8 100644 --- a/adafruit_esp32spi/adafruit_esp32spi.py +++ b/adafruit_esp32spi/adafruit_esp32spi.py @@ -410,10 +410,10 @@ class ESP_SPIcontrol: # pylint: disable=too-many-public-methods self.reset() return False - def connect(self, settings): - """Connect to an access point using a settings dictionary + def connect(self, secrets): + """Connect to an access point using a secrets dictionary that contains a 'ssid' and 'password' entry""" - self.connect_AP(settings['ssid'], settings['password']) + self.connect_AP(secrets['ssid'], secrets['password']) def connect_AP(self, ssid, password): # pylint: disable=invalid-name """Connect to an access point with given name and password. diff --git a/adafruit_esp32spi/adafruit_esp32spi_wifimanager.py b/adafruit_esp32spi/adafruit_esp32spi_wifimanager.py index cc65f92..5f20afa 100755 --- a/adafruit_esp32spi/adafruit_esp32spi_wifimanager.py +++ b/adafruit_esp32spi/adafruit_esp32spi_wifimanager.py @@ -39,10 +39,10 @@ class ESPSPI_WiFiManager: """ A class to help manage the Wifi connection """ - def __init__(self, esp, settings, status_neopixel=None, attempts=2): + def __init__(self, esp, secrets, status_neopixel=None, attempts=2): """ :param ESP_SPIcontrol esp: The ESP object we are using - :param dict settings: The WiFi and Adafruit IO Settings (See examples) + :param dict secrets: The WiFi and Adafruit IO secrets dict (See examples) :param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2) :param status_neopixel: (Optional) The neopixel pin - Usually board.NEOPIXEL (default=None) :type status_neopixel: Pin @@ -50,8 +50,8 @@ class ESPSPI_WiFiManager: # Read the settings self._esp = esp self.debug = False - self.ssid = settings['ssid'] - self.password = settings['password'] + self.ssid = secrets['ssid'] + self.password = secrets['password'] self.attempts = attempts requests.set_interface(self._esp) if status_neopixel: diff --git a/examples/esp32spi_aio_post.py b/examples/esp32spi_aio_post.py index 2527369..e0e3bf5 100644 --- a/examples/esp32spi_aio_post.py +++ b/examples/esp32spi_aio_post.py @@ -8,11 +8,11 @@ from adafruit_esp32spi import adafruit_esp32spi_wifimanager print("ESP32 SPI webclient test") -# Get wifi details and more from a settings.py file +# Get wifi details and more from a secrets.py file try: - from esp32spi_settings import settings + from esp32spi_secrets import secrets except ImportError: - print("WiFi settings are kept in esp32spi_settings.py, please add them there!") + print("WiFi secrets are kept in secrets.py, please add them there!") raise esp32_cs = DigitalInOut(board.D9) @@ -20,7 +20,7 @@ esp32_ready = DigitalInOut(board.D10) esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, settings, board.NEOPIXEL) +wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, board.NEOPIXEL) counter = 0 while True: @@ -30,8 +30,8 @@ while True: feed = 'test' payload = {'value':data} response = wifi.post( - "https://io.adafruit.com/api/v2/"+settings['aio_username']+"/feeds/"+feed+"/data", - json=payload,headers={bytes("X-AIO-KEY","utf-8"):bytes(settings['aio_key'],"utf-8")}) + "https://io.adafruit.com/api/v2/"+secrets['aio_username']+"/feeds/"+feed+"/data", + json=payload,headers={bytes("X-AIO-KEY","utf-8"):bytes(secrets['aio_key'],"utf-8")}) print(response.json()) response.close() counter = counter + 1 diff --git a/examples/esp32spi_cheerlights.py b/examples/esp32spi_cheerlights.py index b44060f..37339ae 100644 --- a/examples/esp32spi_cheerlights.py +++ b/examples/esp32spi_cheerlights.py @@ -9,11 +9,11 @@ from adafruit_esp32spi import adafruit_esp32spi_wifimanager import neopixel import adafruit_fancyled.adafruit_fancyled as fancy -# Get wifi details and more from a settings.py file +# Get wifi details and more from a secrets.py file try: - from esp32spi_settings import settings + from esp32spi_secrets import secrets except ImportError: - print("WiFi settings are kept in esp32spi_settings.py, please add them there!") + print("WiFi secrets are kept in secrets.py, please add them there!") raise print("ESP32 SPI webclient test") @@ -26,7 +26,7 @@ esp32_ready = DigitalInOut(board.D10) esp32_reset = DigitalInOut(board.D5) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, settings, board.NEOPIXEL) +wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, board.NEOPIXEL) # neopixels pixels = neopixel.NeoPixel(board.A1, 16, brightness=0.3) diff --git a/examples/esp32spi_localtime.py b/examples/esp32spi_localtime.py index 87cc0a4..4bb606d 100644 --- a/examples/esp32spi_localtime.py +++ b/examples/esp32spi_localtime.py @@ -7,11 +7,11 @@ from adafruit_esp32spi import adafruit_esp32spi from adafruit_esp32spi import adafruit_esp32spi_wifimanager import rtc -# Get wifi details and more from a settings.py file +# Get wifi details and more from a secrets.py file try: - from settings import settings + from secrets import secrets except ImportError: - print("WiFi settings are kept in settings.py, please add them there!") + print("WiFi secrets are kept in secrets.py, please add them there!") raise print("ESP32 local time") @@ -24,7 +24,7 @@ esp32_gpio0 = DigitalInOut(microcontroller.pin.PB15) esp32_reset = DigitalInOut(microcontroller.pin.PB17) spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) -wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, settings, board.NEOPIXEL) +wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, board.NEOPIXEL) the_rtc = rtc.RTC() diff --git a/examples/esp32spi_settings.py b/examples/esp32spi_secrets.py similarity index 96% rename from examples/esp32spi_settings.py rename to examples/esp32spi_secrets.py index 4b5013d..0f3a3fd 100644 --- a/examples/esp32spi_settings.py +++ b/examples/esp32spi_secrets.py @@ -1,7 +1,7 @@ # This file is where you keep secret settings, passwords, and tokens! # If you put them in the code you risk committing that info or sharing it -settings = { +secrets = { 'ssid' : 'yourssid', 'password' : 'yourpassword', 'timezone' : -5, # this is offset from UTC diff --git a/examples/esp32spi_simpletest.py b/examples/esp32spi_simpletest.py index b4b9a29..67d67c7 100644 --- a/examples/esp32spi_simpletest.py +++ b/examples/esp32spi_simpletest.py @@ -23,10 +23,12 @@ if esp.status == adafruit_esp32spi.WL_IDLE_STATUS: print("ESP32 found and in idle mode") print("Firmware vers.", esp.firmware_version) print("MAC addr:", [hex(i) for i in esp.MAC_address]) + for ap in esp.scan_networks(): print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi'])) + print("Connecting to AP...") -esp.connect_AP(b'adafruit', b'ffffffff') +esp.connect_AP(b'MY_SSID_NAME', b'MY_SSID_PASSWORD') print("Connected to", str(esp.ssid, 'utf-8'), "\tRSSI:", esp.rssi) print("My IP address is", esp.pretty_ip(esp.ip_address)) print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))