Skip to content

Commit 35decfb

Browse files
committed
use secrets.py intead of settings.py
1 parent 3efa8e7 commit 35decfb

8 files changed

+43
-47
lines changed

adafruit_espatcontrol/adafruit_espatcontrol.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ def begin(self):
133133
except OKError:
134134
pass #retry
135135

136-
def connect(self, settings):
136+
def connect(self, secrets):
137137
"""Repeatedly try to connect to an access point with the details in
138-
the passed in 'settings' dictionary. Be sure 'ssid' and 'password' are
139-
defined in the settings dict! If 'timezone' is set, we'll also configure
138+
the passed in 'secrets' dictionary. Be sure 'ssid' and 'password' are
139+
defined in the secrets dict! If 'timezone' is set, we'll also configure
140140
SNTP"""
141141
# Connect to WiFi if not already
142142
retries = 3
@@ -147,13 +147,13 @@ def connect(self, settings):
147147
retries = 3
148148
AP = self.remote_AP # pylint: disable=invalid-name
149149
print("Connected to", AP[0])
150-
if AP[0] != settings['ssid']:
151-
self.join_AP(settings['ssid'], settings['password'])
152-
if 'timezone' in settings:
153-
tzone = settings['timezone']
150+
if AP[0] != secrets['ssid']:
151+
self.join_AP(secrets['ssid'], secrets['password'])
152+
if 'timezone' in secrets:
153+
tzone = secrets['timezone']
154154
ntp = None
155-
if 'ntp_server' in settings:
156-
ntp = settings['ntp_server']
155+
if 'ntp_server' in secrets:
156+
ntp = secrets['ntp_server']
157157
self.sntp_config(True, tzone, ntp)
158158
print("My IP Address:", self.local_ip)
159159
return # yay!

examples/espatcontrol_aio_post.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from adafruit_espatcontrol import adafruit_espatcontrol_requests as requests
77

88

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

1616

@@ -47,16 +47,16 @@
4747
# Connect to WiFi if not already
4848
while not esp.is_connected:
4949
print("Connecting...")
50-
esp.connect(settings)
50+
esp.connect(secrets)
5151
print("Connected to", esp.remote_AP)
5252
# great, lets get the data
5353
print("Posting data...", end='')
5454
data=counter
5555
feed='test'
5656
payload={'value':data}
5757
response=requests.post(
58-
"https://io.adafruit.com/api/v2/"+settings['aio_username']+"/feeds/"+feed+"/data",
59-
json=payload,headers={bytes("X-AIO-KEY","utf-8"):bytes(settings['aio_key'],"utf-8")})
58+
"https://io.adafruit.com/api/v2/"+secrets['aio_username']+"/feeds/"+feed+"/data",
59+
json=payload,headers={bytes("X-AIO-KEY","utf-8"):bytes(secrets['aio_key'],"utf-8")})
6060
print(response.json())
6161
response.close()
6262
counter = counter + 1

examples/espatcontrol_cheerlights.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import neopixel
1414
import adafruit_fancyled.adafruit_fancyled as fancy
1515

16-
# Get wifi details and more from a settings.py file
16+
# Get wifi details and more from a secrets.py file
1717
try:
18-
from settings import settings
18+
from espatcontrol_secrets import secrets
1919
except ImportError:
20-
print("WiFi settings are kept in settings.py, please add them there!")
20+
print("WiFi secrets are kept in secrets.py, please add them there!")
2121
raise
2222

2323
# CONFIGURATION
@@ -54,8 +54,8 @@
5454
try:
5555
while not esp.is_connected:
5656
builtin[0] = (100, 0, 0)
57-
# settings dictionary must contain 'ssid' and 'password' at a minimum
58-
esp.connect(settings)
57+
# secrets dictionary must contain 'ssid' and 'password' at a minimum
58+
esp.connect(secrets)
5959
builtin[0] = (0, 100, 0)
6060
# great, lets get the data
6161
print("Retrieving data source...", end='')

examples/espatcontrol_countviewer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
from adafruit_ht16k33 import segments
1414
import neopixel
1515

16-
# Get wifi details and more from a settings.py file
16+
# Get wifi details and more from a secrets.py file
1717
try:
18-
from settings import settings
18+
from espatcontrol_secrets import secrets
1919
except ImportError:
20-
print("WiFi settings are kept in settings.py, please add them there!")
20+
print("WiFi secrets are kept in secrets.py, please add them there!")
2121
raise
2222

2323
# CONFIGURATION
@@ -33,14 +33,14 @@
3333

3434
# Github stars! You can query 1ce a minute without an API key token
3535
#DATA_SOURCE = "https://api.github.com/repos/adafruit/circuitpython"
36-
#if 'github_token' in settings:
37-
# DATA_SOURCE += "?access_token="+settings['github_token']
36+
#if 'github_token' in secrets:
37+
# DATA_SOURCE += "?access_token="+secrets['github_token']
3838
#DATA_LOCATION = ["stargazers_count"]
3939

4040
# Youtube stats
4141
#CHANNEL_ID = "UCpOlOeQjj7EsVnDh3zuCgsA" # this isn't a secret but you have to look it up
4242
#DATA_SOURCE = "https://www.googleapis.com/youtube/v3/channels/?part=statistics&id=" \
43-
# + CHANNEL_ID +"&key="+settings['youtube_token']
43+
# + CHANNEL_ID +"&key="+secrets['youtube_token']
4444
# try also 'viewCount' or 'videoCount
4545
#DATA_LOCATION = ["items", 0, "statistics", "subscriberCount"]
4646

@@ -50,7 +50,7 @@
5050
#DATA_LOCATION = ["data", "subscribers"]
5151

5252
# Hackaday Skulls (likes), requires an API key
53-
#DATA_SOURCE = "https://api.hackaday.io/v1/projects/1340?api_key="+settings['hackaday_token']
53+
#DATA_SOURCE = "https://api.hackaday.io/v1/projects/1340?api_key="+secrets['hackaday_token']
5454
#DATA_LOCATION = ["skulls"]
5555

5656
# Twitter followers
@@ -110,8 +110,8 @@ def chime_light():
110110
while True:
111111
try:
112112
while not esp.is_connected:
113-
# settings dictionary must contain 'ssid' and 'password' at a minimum
114-
esp.connect(settings)
113+
# secrets dictionary must contain 'ssid' and 'password' at a minimum
114+
esp.connect(secrets)
115115

116116
the_time = esp.sntp_time
117117

examples/espatcontrol_quoteEPD.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
from adafruit_epd.il0373 import Adafruit_IL0373
1717

1818

19-
# Get wifi details and more from a settings.py file
19+
# Get wifi details and more from a secrets.py file
2020
try:
21-
from settings import settings
21+
from espatcontrol_secrets import secrets
2222
except ImportError:
23-
print("WiFi settings are kept in settings.py, please add them there!")
23+
print("WiFi secrets are kept in secrets.py, please add them there!")
2424
raise
2525

2626
# CONFIGURATION
@@ -170,8 +170,8 @@ def draw_bmp(filename, x, y): # pylint: disable=too-many-locals, too-many-branch
170170
while True:
171171
try:
172172
while not esp.is_connected:
173-
# settings dictionary must contain 'ssid' and 'password' at a minimum
174-
esp.connect(settings)
173+
# secrets dictionary must contain 'ssid' and 'password' at a minimum
174+
esp.connect(secrets)
175175
# great, lets get the data
176176

177177
print("Retrieving data source...", end='')

examples/espatcontrol_settings.py renamed to examples/espatcontrol_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' : 'my access point',
66
'password' : 'my password',
77
'timezone' : -5, # this is offset from UTC

examples/espatcontrol_simpletest.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from digitalio import DigitalInOut
55
from adafruit_espatcontrol import adafruit_espatcontrol
66

7-
# Get wifi details and more from a settings.py file
7+
# Get wifi details and more from a secrets.py file
88
try:
9-
from settings import settings
9+
from espatcontrol_secrets import secrets
1010
except ImportError:
11-
print("WiFi settings are kept in settings.py, please add them there!")
11+
print("WiFi secrets are kept in secrets.py, please add them there!")
1212
raise
1313

1414
# With a Metro or Feather M4
@@ -39,12 +39,8 @@
3939
print("Checking connection...")
4040
while not esp.is_connected:
4141
print("Initializing ESP module")
42-
#print("Scanning for AP's")
43-
#for ap in esp.scan_APs():
44-
# print(ap)
45-
# settings dictionary must contain 'ssid' and 'password' at a minimum
4642
print("Connecting...")
47-
esp.connect(settings)
43+
esp.connect(secrets)
4844
print("Connected to AT software version ", esp.version)
4945
print("Pinging 8.8.8.8...", end="")
5046
print(esp.ping("8.8.8.8"))

examples/espatcontrol_webclient.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from adafruit_espatcontrol import adafruit_espatcontrol
66
from adafruit_espatcontrol import adafruit_espatcontrol_requests as requests
77

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

1515
# With a Metro or Feather M4
@@ -41,7 +41,7 @@
4141
print("Checking connection...")
4242
while not esp.is_connected:
4343
print("Connecting...")
44-
esp.connect(settings)
44+
esp.connect(secrets)
4545
# great, lets get the data
4646
print("Retrieving URL...", end='')
4747
r = requests.get(URL)

0 commit comments

Comments
 (0)