Skip to content

Commit bdd282b

Browse files
authored
Merge pull request #33 from justmobilize/remove-secrets-usage
Remove secrets usage
2 parents 00f9efa + 4d57929 commit bdd282b

File tree

3 files changed

+23
-33
lines changed

3 files changed

+23
-33
lines changed

examples/fona_aio_post.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: MIT
33

44
# pylint: disable=unused-import
5+
from os import getenv
56
import time
67
import board
78
import busio
@@ -13,12 +14,13 @@
1314
import adafruit_fona.adafruit_fona_network as network
1415
import adafruit_fona.adafruit_fona_socket as pool
1516

16-
# Get GPRS details and more from a secrets.py file
17-
try:
18-
from secrets import secrets
19-
except ImportError:
20-
print("GPRS secrets are kept in secrets.py, please add them there!")
21-
raise
17+
# Get FONA details and Adafruit IO keys, ensure these are setup in settings.toml
18+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
19+
apn = getenv("apn")
20+
apn_username = getenv("apn_username")
21+
apn_password = getenv("apn_password")
22+
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
23+
aio_key = getenv("ADAFRUIT_AIO_KEY")
2224

2325
# Create a serial connection for the FONA
2426
uart = busio.UART(board.TX, board.RX)
@@ -31,9 +33,7 @@
3133
# fona = FONA3G(uart, rst)
3234

3335
# Initialize cellular data network
34-
network = network.CELLULAR(
35-
fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"])
36-
)
36+
network = network.CELLULAR(fona, (apn, apn_username, apn_password))
3737

3838
while not network.is_attached:
3939
print("Attaching to network...")
@@ -58,13 +58,9 @@
5858
feed = "test"
5959
payload = {"value": data}
6060
response = requests.post(
61-
"http://io.adafruit.com/api/v2/"
62-
+ secrets["aio_username"]
63-
+ "/feeds/"
64-
+ feed
65-
+ "/data",
61+
"http://io.adafruit.com/api/v2/" + aio_username + "/feeds/" + feed + "/data",
6662
json=payload,
67-
headers={"X-AIO-KEY": secrets["aio_key"]},
63+
headers={"X-AIO-KEY": aio_key},
6864
)
6965
print(response.json())
7066
response.close()

examples/fona_cheerlights.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: MIT
33

44
# pylint: disable=unused-import
5+
from os import getenv
56
import time
67
import board
78
import busio
@@ -15,12 +16,10 @@
1516
import adafruit_fona.adafruit_fona_network as network
1617
import adafruit_fona.adafruit_fona_socket as pool
1718

18-
# Get GPRS details and more from a secrets.py file
19-
try:
20-
from secrets import secrets
21-
except ImportError:
22-
print("GPRS secrets are kept in secrets.py, please add them there!")
23-
raise
19+
# Get FONA details, ensure these are setup in settings.toml
20+
apn = getenv("apn")
21+
apn_username = getenv("apn_username")
22+
apn_password = getenv("apn_password")
2423

2524
# Create a serial connection for the FONA
2625
uart = busio.UART(board.TX, board.RX)
@@ -33,9 +32,7 @@
3332
# fona = FONA3G(uart, rst)
3433

3534
# Initialize cellular data network
36-
network = network.CELLULAR(
37-
fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"])
38-
)
35+
network = network.CELLULAR(fona, (apn, apn_username, apn_password))
3936

4037
while not network.is_attached:
4138
print("Attaching to network...")

examples/fona_simpletest.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: MIT
33

44
# pylint: disable=unused-import
5+
from os import getenv
56
import time
67
import board
78
import busio
@@ -18,12 +19,10 @@
1819
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
1920
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"
2021

21-
# Get GPRS details and more from a secrets.py file
22-
try:
23-
from secrets import secrets
24-
except ImportError:
25-
print("GPRS secrets are kept in secrets.py, please add them there!")
26-
raise
22+
# Get FONA details, ensure these are setup in settings.toml
23+
apn = getenv("apn")
24+
apn_username = getenv("apn_username")
25+
apn_password = getenv("apn_password")
2726

2827
# Create a serial connection for the FONA connection
2928
uart = busio.UART(board.TX, board.RX)
@@ -36,9 +35,7 @@
3635
# fona = FONA3G(uart, rst)
3736

3837
# Initialize cellular data network
39-
network = network.CELLULAR(
40-
fona, (secrets["apn"], secrets["apn_username"], secrets["apn_password"])
41-
)
38+
network = network.CELLULAR(fona, (apn, apn_username, apn_password))
4239

4340
while not network.is_attached:
4441
print("Attaching to network...")

0 commit comments

Comments
 (0)