Skip to content

Commit 3c09df1

Browse files
authored
Merge pull request #26 from jerryneedell/jerryn_secrets
switch to using secrets.py
2 parents 271dff7 + d57a99f commit 3c09df1

8 files changed

+94
-50
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
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 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

1717
# With a Metro or Feather M4
1818
resetpin = DigitalInOut(board.D5)
19-
rtspin = DigitalInOut(board.D9)
19+
rtspin = DigitalInOut(board.D6)
2020
uart = busio.UART(board.TX, board.RX, timeout=0.1)
2121

2222
# With a Particle Argon
@@ -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: 22 additions & 6 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 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
@@ -29,7 +29,23 @@
2929

3030
uart = busio.UART(board.TX, board.RX, timeout=0.1)
3131
resetpin = DigitalInOut(board.D5)
32-
rtspin = DigitalInOut(board.D9)
32+
rtspin = DigitalInOut(board.D6)
33+
34+
35+
# With a Particle Argon
36+
"""
37+
RX = board.ESP_TX
38+
TX = board.ESP_RX
39+
resetpin = DigitalInOut(board.ESP_WIFI_EN)
40+
rtspin = DigitalInOut(board.ESP_CTS)
41+
uart = busio.UART(TX, RX, timeout=0.1)
42+
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
43+
from digitalio import Direction
44+
esp_boot.direction = Direction.OUTPUT
45+
esp_boot.value = True
46+
"""
47+
48+
3349

3450
# Create the connection to the co-processor and reset
3551
esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200, run_baudrate=460800,
@@ -54,8 +70,8 @@
5470
try:
5571
while not esp.is_connected:
5672
builtin[0] = (100, 0, 0)
57-
# settings dictionary must contain 'ssid' and 'password' at a minimum
58-
esp.connect(settings)
73+
# secrets dictionary must contain 'ssid' and 'password' at a minimum
74+
esp.connect(secrets)
5975
builtin[0] = (0, 100, 0)
6076
# great, lets get the data
6177
print("Retrieving data source...", end='')

examples/espatcontrol_countviewer.py

Lines changed: 27 additions & 10 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 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,17 +50,34 @@
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
5757
#DATA_SOURCE = "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?" + \
5858
#"screen_names=adafruit"
5959
#DATA_LOCATION = [0, "followers_count"]
6060

61+
# on metro_m4
6162
uart = busio.UART(board.TX, board.RX, timeout=0.1)
6263
resetpin = DigitalInOut(board.D5)
63-
rtspin = DigitalInOut(board.D9)
64+
rtspin = DigitalInOut(board.D6)
65+
66+
67+
# With a Particle Argon
68+
"""
69+
RX = board.ESP_TX
70+
TX = board.ESP_RX
71+
resetpin = DigitalInOut(board.ESP_WIFI_EN)
72+
rtspin = DigitalInOut(board.ESP_CTS)
73+
uart = busio.UART(TX, RX, timeout=0.1)
74+
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
75+
from digitalio import Direction
76+
esp_boot.direction = Direction.OUTPUT
77+
esp_boot.value = True
78+
"""
79+
80+
6481

6582
# Create the connection to the co-processor and reset
6683
esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200, run_baudrate=921600,
@@ -110,8 +127,8 @@ def chime_light():
110127
while True:
111128
try:
112129
while not esp.is_connected:
113-
# settings dictionary must contain 'ssid' and 'password' at a minimum
114-
esp.connect(settings)
130+
# secrets dictionary must contain 'ssid' and 'password' at a minimum
131+
esp.connect(secrets)
115132

116133
the_time = esp.sntp_time
117134

examples/espatcontrol_quoteEPD.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
from adafruit_epd.il0373 import Adafruit_IL0373
2020

2121

22-
# Get wifi details and more from a settings.py file
22+
# Get wifi details and more from a secrets.py file
2323
try:
24-
from settings import settings
24+
from secrets import secrets
2525
except ImportError:
26-
print("WiFi settings are kept in settings.py, please add them there!")
26+
print("WiFi secrets are kept in secrets.py, please add them there!")
2727
raise
2828

2929
# CONFIGURATION
@@ -46,6 +46,21 @@
4646
resetpin = DigitalInOut(board.D5)
4747
rtspin = DigitalInOut(board.D6)
4848

49+
50+
# With a Particle Argon
51+
"""
52+
RX = board.ESP_TX
53+
TX = board.ESP_RX
54+
resetpin = DigitalInOut(board.ESP_WIFI_EN)
55+
rtspin = DigitalInOut(board.ESP_CTS)
56+
uart = busio.UART(TX, RX, timeout=0.1)
57+
esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
58+
from digitalio import Direction
59+
esp_boot.direction = Direction.OUTPUT
60+
esp_boot.value = True
61+
"""
62+
63+
4964
# Create the connection to the co-processor and reset
5065
esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200, run_baudrate=115200,
5166
reset_pin=resetpin,
@@ -173,8 +188,8 @@ def draw_bmp(filename, x, y): # pylint: disable=too-many-locals, too-many-branch
173188
while True:
174189
try:
175190
while not esp.is_connected:
176-
# settings dictionary must contain 'ssid' and 'password' at a minimum
177-
esp.connect(settings)
191+
# secrets dictionary must contain 'ssid' and 'password' at a minimum
192+
esp.connect(secrets)
178193
# great, lets get the data
179194

180195
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 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 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)