Skip to content

Commit 8e59509

Browse files
authored
Merge pull request #29 from justmobilize/remove-secrets-usage
Remove secrets usage
2 parents e3db30c + bba799d commit 8e59509

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

docs/examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Preview images on LCD then save BMP images to SD on Kaluga 1.3 fitted with an il
8989
Kaluga 1.3 with Adafruit IO
9090
~~~~~~~~~~~~~~~~~~~~~~~~~~~
9191

92-
Upload JPEG images to Adafruit IO. Requires that WIFI and Adafruit IO be configured in ``secrets.py``.
92+
Upload JPEG images to Adafruit IO. Requires that WIFI and Adafruit IO be configured in ``settings.toml``.
9393

9494
.. literalinclude:: ../examples/ov2640_aio_kaluga1_3.py
9595
:caption: ov2640_aio_kaluga1_3.py

examples/ov2640_aio_kaluga1_3.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
I2C pull-ups(!)
1212
1313
This example requires that your WIFI and Adafruit IO credentials be configured
14-
in CIRCUITPY/secrets.py, and that you have created a feed called "image" with
14+
in CIRCUITPY/settings.toml, and that you have created a feed called "image" with
1515
history disabled.
1616
1717
The maximum image size is 100kB after base64 encoding, or about 65kB before
@@ -21,31 +21,38 @@
2121
"""
2222

2323
import binascii
24-
import ssl
2524
import time
26-
from secrets import secrets # pylint: disable=no-name-in-module
25+
from os import getenv
2726

2827
import board
2928
import busio
3029
import wifi
31-
import socketpool
30+
import adafruit_connection_manager
3231
import adafruit_minimqtt.adafruit_minimqtt as MQTT
3332
from adafruit_io.adafruit_io import IO_MQTT
3433
import adafruit_ov2640
3534

3635
feed_name = "image"
3736

37+
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
38+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
39+
ssid = getenv("CIRCUITPY_WIFI_SSID")
40+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
41+
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
42+
aio_key = getenv("ADAFRUIT_AIO_KEY")
43+
3844
print("Connecting to WIFI")
39-
wifi.radio.connect(secrets["ssid"], secrets["password"])
40-
pool = socketpool.SocketPool(wifi.radio)
45+
wifi.radio.connect(ssid, password)
46+
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
47+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
4148

4249
print("Connecting to Adafruit IO")
4350
mqtt_client = MQTT.MQTT(
4451
broker="io.adafruit.com",
45-
username=secrets["aio_username"],
46-
password=secrets["aio_key"],
52+
username=aio_username,
53+
password=aio_key,
4754
socket_pool=pool,
48-
ssl_context=ssl.create_default_context(),
55+
ssl_context=ssl_context,
4956
)
5057
mqtt_client.connect()
5158
io = IO_MQTT(mqtt_client)

examples/ov2640_aio_saola.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
This exampl us for the Espressif Soala Wrover with an OV2640 Camera
88
99
This example requires that your WIFI and Adafruit IO credentials be configured
10-
in CIRCUITPY/secrets.py, and that you have created a feed called "image" with
10+
in CIRCUITPY/settings.toml, and that you have created a feed called "image" with
1111
history disabled.
1212
1313
The maximum image size is 100kB after base64 encoding, or about 65kB before
@@ -17,31 +17,38 @@
1717
"""
1818

1919
import binascii
20-
import ssl
2120
import time
22-
from secrets import secrets # pylint: disable=no-name-in-module
21+
from os import getenv
2322

2423
import board
2524
import busio
2625
import wifi
27-
import socketpool
26+
import adafruit_connection_manager
2827
import adafruit_minimqtt.adafruit_minimqtt as MQTT
2928
from adafruit_io.adafruit_io import IO_MQTT
3029
import adafruit_ov2640
3130

3231
feed_name = "image-saola-ov2640"
3332

33+
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
34+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
35+
ssid = getenv("CIRCUITPY_WIFI_SSID")
36+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
37+
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
38+
aio_key = getenv("ADAFRUIT_AIO_KEY")
39+
3440
print("Connecting to WIFI")
35-
wifi.radio.connect(secrets["ssid"], secrets["password"])
36-
pool = socketpool.SocketPool(wifi.radio)
41+
wifi.radio.connect(ssid, password)
42+
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
43+
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
3744

3845
print("Connecting to Adafruit IO")
3946
mqtt_client = MQTT.MQTT(
4047
broker="io.adafruit.com",
41-
username=secrets["aio_username"],
42-
password=secrets["aio_key"],
48+
username=aio_username,
49+
password=aio_key,
4350
socket_pool=pool,
44-
ssl_context=ssl.create_default_context(),
51+
ssl_context=ssl_context,
4552
)
4653
mqtt_client.connect()
4754
io = IO_MQTT(mqtt_client)

0 commit comments

Comments
 (0)