From 35decfb22c605a123d9220e56f1dba2614e69d20 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sat, 23 Feb 2019 20:44:55 -0500 Subject: [PATCH 1/2] use secrets.py intead of settings.py --- adafruit_espatcontrol/adafruit_espatcontrol.py | 18 +++++++++--------- examples/espatcontrol_aio_post.py | 12 ++++++------ examples/espatcontrol_cheerlights.py | 10 +++++----- examples/espatcontrol_countviewer.py | 18 +++++++++--------- examples/espatcontrol_quoteEPD.py | 10 +++++----- ...rol_settings.py => espatcontrol_secrets.py} | 2 +- examples/espatcontrol_simpletest.py | 12 ++++-------- examples/espatcontrol_webclient.py | 8 ++++---- 8 files changed, 43 insertions(+), 47 deletions(-) rename examples/{espatcontrol_settings.py => espatcontrol_secrets.py} (96%) diff --git a/adafruit_espatcontrol/adafruit_espatcontrol.py b/adafruit_espatcontrol/adafruit_espatcontrol.py index 2b67561..9cece08 100644 --- a/adafruit_espatcontrol/adafruit_espatcontrol.py +++ b/adafruit_espatcontrol/adafruit_espatcontrol.py @@ -133,10 +133,10 @@ def begin(self): except OKError: pass #retry - def connect(self, settings): + def connect(self, secrets): """Repeatedly try to connect to an access point with the details in - the passed in 'settings' dictionary. Be sure 'ssid' and 'password' are - defined in the settings dict! If 'timezone' is set, we'll also configure + the passed in 'secrets' dictionary. Be sure 'ssid' and 'password' are + defined in the secrets dict! If 'timezone' is set, we'll also configure SNTP""" # Connect to WiFi if not already retries = 3 @@ -147,13 +147,13 @@ def connect(self, settings): retries = 3 AP = self.remote_AP # pylint: disable=invalid-name print("Connected to", AP[0]) - if AP[0] != settings['ssid']: - self.join_AP(settings['ssid'], settings['password']) - if 'timezone' in settings: - tzone = settings['timezone'] + if AP[0] != secrets['ssid']: + self.join_AP(secrets['ssid'], secrets['password']) + if 'timezone' in secrets: + tzone = secrets['timezone'] ntp = None - if 'ntp_server' in settings: - ntp = settings['ntp_server'] + if 'ntp_server' in secrets: + ntp = secrets['ntp_server'] self.sntp_config(True, tzone, ntp) print("My IP Address:", self.local_ip) return # yay! diff --git a/examples/espatcontrol_aio_post.py b/examples/espatcontrol_aio_post.py index 31a52fa..e1aae11 100644 --- a/examples/espatcontrol_aio_post.py +++ b/examples/espatcontrol_aio_post.py @@ -6,11 +6,11 @@ from adafruit_espatcontrol import adafruit_espatcontrol_requests as requests -# 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 espatcontorl_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 @@ -47,7 +47,7 @@ # Connect to WiFi if not already while not esp.is_connected: print("Connecting...") - esp.connect(settings) + esp.connect(secrets) print("Connected to", esp.remote_AP) # great, lets get the data print("Posting data...", end='') @@ -55,8 +55,8 @@ feed='test' payload={'value':data} response=requests.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/espatcontrol_cheerlights.py b/examples/espatcontrol_cheerlights.py index 4a05622..4e41b80 100644 --- a/examples/espatcontrol_cheerlights.py +++ b/examples/espatcontrol_cheerlights.py @@ -13,11 +13,11 @@ 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 settings import settings + from espatcontrol_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 # CONFIGURATION @@ -54,8 +54,8 @@ try: while not esp.is_connected: builtin[0] = (100, 0, 0) - # settings dictionary must contain 'ssid' and 'password' at a minimum - esp.connect(settings) + # secrets dictionary must contain 'ssid' and 'password' at a minimum + esp.connect(secrets) builtin[0] = (0, 100, 0) # great, lets get the data print("Retrieving data source...", end='') diff --git a/examples/espatcontrol_countviewer.py b/examples/espatcontrol_countviewer.py index d91179a..c2e7e2d 100644 --- a/examples/espatcontrol_countviewer.py +++ b/examples/espatcontrol_countviewer.py @@ -13,11 +13,11 @@ from adafruit_ht16k33 import segments import neopixel -# 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 espatcontrol_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 # CONFIGURATION @@ -33,14 +33,14 @@ # Github stars! You can query 1ce a minute without an API key token #DATA_SOURCE = "https://api.github.com/repos/adafruit/circuitpython" -#if 'github_token' in settings: -# DATA_SOURCE += "?access_token="+settings['github_token'] +#if 'github_token' in secrets: +# DATA_SOURCE += "?access_token="+secrets['github_token'] #DATA_LOCATION = ["stargazers_count"] # Youtube stats #CHANNEL_ID = "UCpOlOeQjj7EsVnDh3zuCgsA" # this isn't a secret but you have to look it up #DATA_SOURCE = "https://www.googleapis.com/youtube/v3/channels/?part=statistics&id=" \ -# + CHANNEL_ID +"&key="+settings['youtube_token'] +# + CHANNEL_ID +"&key="+secrets['youtube_token'] # try also 'viewCount' or 'videoCount #DATA_LOCATION = ["items", 0, "statistics", "subscriberCount"] @@ -50,7 +50,7 @@ #DATA_LOCATION = ["data", "subscribers"] # Hackaday Skulls (likes), requires an API key -#DATA_SOURCE = "https://api.hackaday.io/v1/projects/1340?api_key="+settings['hackaday_token'] +#DATA_SOURCE = "https://api.hackaday.io/v1/projects/1340?api_key="+secrets['hackaday_token'] #DATA_LOCATION = ["skulls"] # Twitter followers @@ -110,8 +110,8 @@ def chime_light(): while True: try: while not esp.is_connected: - # settings dictionary must contain 'ssid' and 'password' at a minimum - esp.connect(settings) + # secrets dictionary must contain 'ssid' and 'password' at a minimum + esp.connect(secrets) the_time = esp.sntp_time diff --git a/examples/espatcontrol_quoteEPD.py b/examples/espatcontrol_quoteEPD.py index 3c789b0..4adccec 100644 --- a/examples/espatcontrol_quoteEPD.py +++ b/examples/espatcontrol_quoteEPD.py @@ -16,11 +16,11 @@ from adafruit_epd.il0373 import Adafruit_IL0373 -# 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 espatcontrol_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 # CONFIGURATION @@ -170,8 +170,8 @@ def draw_bmp(filename, x, y): # pylint: disable=too-many-locals, too-many-branch while True: try: while not esp.is_connected: - # settings dictionary must contain 'ssid' and 'password' at a minimum - esp.connect(settings) + # secrets dictionary must contain 'ssid' and 'password' at a minimum + esp.connect(secrets) # great, lets get the data print("Retrieving data source...", end='') diff --git a/examples/espatcontrol_settings.py b/examples/espatcontrol_secrets.py similarity index 96% rename from examples/espatcontrol_settings.py rename to examples/espatcontrol_secrets.py index 79c9fb2..dd2fea4 100644 --- a/examples/espatcontrol_settings.py +++ b/examples/espatcontrol_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' : 'my access point', 'password' : 'my password', 'timezone' : -5, # this is offset from UTC diff --git a/examples/espatcontrol_simpletest.py b/examples/espatcontrol_simpletest.py index 6c4f395..299cf9b 100644 --- a/examples/espatcontrol_simpletest.py +++ b/examples/espatcontrol_simpletest.py @@ -4,11 +4,11 @@ from digitalio import DigitalInOut from adafruit_espatcontrol import adafruit_espatcontrol -# 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 espatcontrol_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 # With a Metro or Feather M4 @@ -39,12 +39,8 @@ print("Checking connection...") while not esp.is_connected: print("Initializing ESP module") - #print("Scanning for AP's") - #for ap in esp.scan_APs(): - # print(ap) - # settings dictionary must contain 'ssid' and 'password' at a minimum print("Connecting...") - esp.connect(settings) + esp.connect(secrets) print("Connected to AT software version ", esp.version) print("Pinging 8.8.8.8...", end="") print(esp.ping("8.8.8.8")) diff --git a/examples/espatcontrol_webclient.py b/examples/espatcontrol_webclient.py index 31423d1..8d3de3a 100644 --- a/examples/espatcontrol_webclient.py +++ b/examples/espatcontrol_webclient.py @@ -5,11 +5,11 @@ from adafruit_espatcontrol import adafruit_espatcontrol from adafruit_espatcontrol import adafruit_espatcontrol_requests as requests -# 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 espatcontrol_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 # With a Metro or Feather M4 @@ -41,7 +41,7 @@ print("Checking connection...") while not esp.is_connected: print("Connecting...") - esp.connect(settings) + esp.connect(secrets) # great, lets get the data print("Retrieving URL...", end='') r = requests.get(URL) From d57a99f83f49b95a8226030a201175fe411df9eb Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sat, 23 Feb 2019 21:28:14 -0500 Subject: [PATCH 2/2] fixing secrets --- examples/espatcontrol_aio_post.py | 4 ++-- examples/espatcontrol_cheerlights.py | 20 ++++++++++++++++++-- examples/espatcontrol_countviewer.py | 21 +++++++++++++++++++-- examples/espatcontrol_quoteEPD.py | 17 ++++++++++++++++- examples/espatcontrol_simpletest.py | 2 +- examples/espatcontrol_webclient.py | 2 +- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/examples/espatcontrol_aio_post.py b/examples/espatcontrol_aio_post.py index e1aae11..adf7b5c 100644 --- a/examples/espatcontrol_aio_post.py +++ b/examples/espatcontrol_aio_post.py @@ -8,7 +8,7 @@ # Get wifi details and more from a secrets.py file try: - from espatcontorl_secrets import secrets + from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise @@ -16,7 +16,7 @@ # With a Metro or Feather M4 resetpin = DigitalInOut(board.D5) -rtspin = DigitalInOut(board.D9) +rtspin = DigitalInOut(board.D6) uart = busio.UART(board.TX, board.RX, timeout=0.1) # With a Particle Argon diff --git a/examples/espatcontrol_cheerlights.py b/examples/espatcontrol_cheerlights.py index 4e41b80..5640215 100644 --- a/examples/espatcontrol_cheerlights.py +++ b/examples/espatcontrol_cheerlights.py @@ -15,7 +15,7 @@ # Get wifi details and more from a secrets.py file try: - from espatcontrol_secrets import secrets + from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise @@ -29,7 +29,23 @@ uart = busio.UART(board.TX, board.RX, timeout=0.1) resetpin = DigitalInOut(board.D5) -rtspin = DigitalInOut(board.D9) +rtspin = DigitalInOut(board.D6) + + +# With a Particle Argon +""" +RX = board.ESP_TX +TX = board.ESP_RX +resetpin = DigitalInOut(board.ESP_WIFI_EN) +rtspin = DigitalInOut(board.ESP_CTS) +uart = busio.UART(TX, RX, timeout=0.1) +esp_boot = DigitalInOut(board.ESP_BOOT_MODE) +from digitalio import Direction +esp_boot.direction = Direction.OUTPUT +esp_boot.value = True +""" + + # Create the connection to the co-processor and reset esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200, run_baudrate=460800, diff --git a/examples/espatcontrol_countviewer.py b/examples/espatcontrol_countviewer.py index c2e7e2d..3eb2309 100644 --- a/examples/espatcontrol_countviewer.py +++ b/examples/espatcontrol_countviewer.py @@ -15,7 +15,7 @@ # Get wifi details and more from a secrets.py file try: - from espatcontrol_secrets import secrets + from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise @@ -58,9 +58,26 @@ #"screen_names=adafruit" #DATA_LOCATION = [0, "followers_count"] +# on metro_m4 uart = busio.UART(board.TX, board.RX, timeout=0.1) resetpin = DigitalInOut(board.D5) -rtspin = DigitalInOut(board.D9) +rtspin = DigitalInOut(board.D6) + + +# With a Particle Argon +""" +RX = board.ESP_TX +TX = board.ESP_RX +resetpin = DigitalInOut(board.ESP_WIFI_EN) +rtspin = DigitalInOut(board.ESP_CTS) +uart = busio.UART(TX, RX, timeout=0.1) +esp_boot = DigitalInOut(board.ESP_BOOT_MODE) +from digitalio import Direction +esp_boot.direction = Direction.OUTPUT +esp_boot.value = True +""" + + # Create the connection to the co-processor and reset esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200, run_baudrate=921600, diff --git a/examples/espatcontrol_quoteEPD.py b/examples/espatcontrol_quoteEPD.py index eb1bd5f..ea126aa 100644 --- a/examples/espatcontrol_quoteEPD.py +++ b/examples/espatcontrol_quoteEPD.py @@ -21,7 +21,7 @@ # Get wifi details and more from a secrets.py file try: - from espatcontrol_secrets import secrets + from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise @@ -46,6 +46,21 @@ resetpin = DigitalInOut(board.D5) rtspin = DigitalInOut(board.D6) + +# With a Particle Argon +""" +RX = board.ESP_TX +TX = board.ESP_RX +resetpin = DigitalInOut(board.ESP_WIFI_EN) +rtspin = DigitalInOut(board.ESP_CTS) +uart = busio.UART(TX, RX, timeout=0.1) +esp_boot = DigitalInOut(board.ESP_BOOT_MODE) +from digitalio import Direction +esp_boot.direction = Direction.OUTPUT +esp_boot.value = True +""" + + # Create the connection to the co-processor and reset esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200, run_baudrate=115200, reset_pin=resetpin, diff --git a/examples/espatcontrol_simpletest.py b/examples/espatcontrol_simpletest.py index 299cf9b..f2203f5 100644 --- a/examples/espatcontrol_simpletest.py +++ b/examples/espatcontrol_simpletest.py @@ -6,7 +6,7 @@ # Get wifi details and more from a secrets.py file try: - from espatcontrol_secrets import secrets + from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise diff --git a/examples/espatcontrol_webclient.py b/examples/espatcontrol_webclient.py index 8d3de3a..678b117 100644 --- a/examples/espatcontrol_webclient.py +++ b/examples/espatcontrol_webclient.py @@ -7,7 +7,7 @@ # Get wifi details and more from a secrets.py file try: - from espatcontrol_secrets import secrets + from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise