Skip to content

switch to using secrets.py #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions adafruit_espatcontrol/adafruit_espatcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!
Expand Down
14 changes: 7 additions & 7 deletions examples/espatcontrol_aio_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
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 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
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
Expand Down Expand Up @@ -47,16 +47,16 @@
# 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='')
data=counter
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
Expand Down
28 changes: 22 additions & 6 deletions examples/espatcontrol_cheerlights.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand All @@ -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,
Expand All @@ -54,8 +70,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='')
Expand Down
37 changes: 27 additions & 10 deletions examples/espatcontrol_countviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand All @@ -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"]

Expand All @@ -50,17 +50,34 @@
#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
#DATA_SOURCE = "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?" + \
#"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,
Expand Down Expand Up @@ -110,8 +127,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

Expand Down
25 changes: 20 additions & 5 deletions examples/espatcontrol_quoteEPD.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,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 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
Expand All @@ -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,
Expand Down Expand Up @@ -173,8 +188,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='')
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 4 additions & 8 deletions examples/espatcontrol_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down Expand Up @@ -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"))
Expand Down
8 changes: 4 additions & 4 deletions examples/espatcontrol_webclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand Down Expand Up @@ -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)
Expand Down