Skip to content

Commit 1e6a1ab

Browse files
authored
Merge pull request #66 from justmobilize/remove-secrets-usage
Remove secrets usage
2 parents 24b9f95 + 99e1de5 commit 1e6a1ab

19 files changed

+270
-242
lines changed

README.rst

+27-13
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ To interact with Azure IoT Hub, you will need to create a hub, and a register a
106106

107107
- Open the `Azure Portal <https://aka.ms/AzurePortalHome>`_.
108108
- Follow the instructions in `Microsoft Docs <https://aka.ms/CreateIoTHub>`_ to create an Azure IoT Hub and register a device.
109-
- Copy the devices Primary or secondary connection string, and add this to your ``secrets.py`` file.
109+
- Copy the devices Primary or secondary connection string, and add this to your ``settings.toml`` file.
110110

111111
You can find the device connection string by selecting the IoT Hub in the `Azure Portal <https://aka.ms/AzurePortalHome>`_, *selecting Explorer -> IoT devices*, then selecting your device.
112112

@@ -128,7 +128,7 @@ Then copy either the primary or secondary connection string using the copy butto
128128
129129
from adafruit_azureiot import IoTHubDevice
130130
131-
device = IoTHubDevice(wifi, secrets["device_connection_string"])
131+
device = IoTHubDevice(wifi, device_connection_string)
132132
device.connect()
133133
134134
Once the device is connected, you will regularly need to run a ``loop`` to poll for messages from the cloud.
@@ -197,7 +197,7 @@ To use Azure IoT Central, you will need to create an Azure IoT Central app, crea
197197
- Head to `Azure IoT Central <https://apps.azureiotcentral.com/?WT.mc_id=academic-3168-jabenn>`__
198198
- Follow the instructions in the `Microsoft Docs <https://docs.microsoft.com/azure/iot-central/core/quick-deploy-iot-central?WT.mc_id=academic-3168-jabenn>`__ to create an application. Every tier is free for up to 2 devices.
199199
- Follow the instructions in the `Microsoft Docs <https://docs.microsoft.com/azure/iot-central/core/quick-create-simulated-device?WT.mc_id=academic-3168-jabenn>`__ to create a device template.
200-
- Create a device based off the template, and select **Connect** to get the device connection details. Store the ID Scope, Device ID and either the primary or secondary device SAS key in your ``secrets.py`` file.
200+
- Create a device based off the template, and select **Connect** to get the device connection details. Store the ID Scope, Device ID and either the primary or secondary device SAS key in your ``settings.toml`` file.
201201

202202
.. image:: iot-central-connect-button.png
203203
:alt: The IoT Central connect button
@@ -209,26 +209,40 @@ To use Azure IoT Central, you will need to create an Azure IoT Central app, crea
209209

210210
*The connection details dialog*
211211

212+
213+
settings.toml:
214+
212215
.. code-block:: python
213216
214-
secrets = {
215-
# WiFi settings
216-
"ssid": "",
217-
"password": "",
217+
# WiFi settings
218+
CIRCUITPY_WIFI_SSID="Your WiFi ssid"
219+
CIRCUITPY_WIFI_PASSWORD="Your WiFi password"
218220
219-
# Azure IoT Central settings
220-
"id_scope": "",
221-
"device_id": "",
222-
"device_sas_key": ""
223-
}
221+
# Azure IoT Central settings
222+
id_scope="Your ID Scope"
223+
device_id="Your Device ID"
224+
device_sas_key="Your Primary Key"
224225
225226
**Connect your device to your Azure IoT Central app**
226227

227228
.. code-block:: python
228229
230+
import wifi
231+
from os import getenv
229232
from adafruit_azureiot import IoTCentralDevice
233+
import adafruit_connection_manager
234+
235+
ssid = getenv("CIRCUITPY_WIFI_SSID")
236+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
237+
id_scope = getenv("id_scope")
238+
device_id = getenv("device_id")
239+
device_sas_key = getenv("device_sas_key")
240+
241+
wifi.radio.connect(ssid, password)
242+
243+
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
230244
231-
device = IoTCentralDevice(wifi, secrets["id_scope"], secrets["device_id"], secrets["device_sas_key"])
245+
device = IoTCentralDevice(pool, id_scope, device_id, device_sas_key)
232246
device.connect()
233247
234248
Once the device is connected, you will regularly need to run a ``loop`` to poll for messages from the cloud.

examples/azureiot_esp32spi/azureiot_central_commands.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
from os import getenv
45
import time
56
import board
67
import busio
@@ -10,12 +11,12 @@
1011
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
1112
import adafruit_connection_manager
1213

13-
# Get wifi details and more from a secrets.py file
14-
try:
15-
from secrets import secrets
16-
except ImportError:
17-
print("WiFi secrets are kept in secrets.py, please add them there!")
18-
raise
14+
# Get WiFi details and AWS Keys, ensure these are setup in settings.toml
15+
ssid = getenv("CIRCUITPY_WIFI_SSID")
16+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
17+
id_scope = getenv("id_scope")
18+
device_id = getenv("device_id")
19+
device_sas_key = getenv("device_sas_key")
1920

2021
# ESP32 Setup
2122
try:
@@ -31,19 +32,21 @@
3132
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
3233

3334
"""Use below for Most Boards"""
34-
status_light = neopixel.NeoPixel(
35+
status_pixel = neopixel.NeoPixel(
3536
board.NEOPIXEL, 1, brightness=0.2
3637
) # Uncomment for Most Boards
3738
"""Uncomment below for ItsyBitsy M4"""
38-
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
39+
# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
3940
# Uncomment below for an externally defined RGB LED
4041
# import adafruit_rgbled
4142
# from adafruit_esp32spi import PWMOut
4243
# RED_LED = PWMOut.PWMOut(esp, 26)
4344
# GREEN_LED = PWMOut.PWMOut(esp, 27)
4445
# BLUE_LED = PWMOut.PWMOut(esp, 25)
45-
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
46-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
46+
# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
47+
wifi = adafruit_esp32spi_wifimanager.WiFiManager(
48+
esp, ssid, password, status_pixel=status_pixel
49+
)
4750

4851
print("Connecting to WiFi...")
4952

@@ -86,7 +89,7 @@
8689
#
8790
# Next create a device using the device template, and select Connect to get the device connection
8891
# details.
89-
# Add the connection details to your secrets.py file, using the following values:
92+
# Add the connection details to your settings.toml file, using the following values:
9093
#
9194
# 'id_scope' - the devices ID scope
9295
# 'device_id' - the devices device id
@@ -108,9 +111,9 @@
108111
device = IoTCentralDevice(
109112
pool,
110113
ssl_context,
111-
secrets["id_scope"],
112-
secrets["device_id"],
113-
secrets["device_sas_key"],
114+
id_scope,
115+
device_id,
116+
device_sas_key,
114117
)
115118

116119

examples/azureiot_esp32spi/azureiot_central_notconnected.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
from os import getenv
45
import json
56
import random
67
import time
@@ -12,12 +13,12 @@
1213
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
1314
import adafruit_connection_manager
1415

15-
# Get wifi details and more from a secrets.py file
16-
try:
17-
from secrets import secrets
18-
except ImportError:
19-
print("WiFi secrets are kept in secrets.py, please add them there!")
20-
raise
16+
# Get WiFi details and AWS Keys, ensure these are setup in settings.toml
17+
ssid = getenv("CIRCUITPY_WIFI_SSID")
18+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
19+
id_scope = getenv("id_scope")
20+
device_id = getenv("device_id")
21+
device_sas_key = getenv("device_sas_key")
2122

2223
# ESP32 Setup
2324
try:
@@ -33,19 +34,21 @@
3334
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
3435

3536
"""Use below for Most Boards"""
36-
status_light = neopixel.NeoPixel(
37+
status_pixel = neopixel.NeoPixel(
3738
board.NEOPIXEL, 1, brightness=0.2
3839
) # Uncomment for Most Boards
3940
"""Uncomment below for ItsyBitsy M4"""
40-
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
41+
# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
4142
# Uncomment below for an externally defined RGB LED
4243
# import adafruit_rgbled
4344
# from adafruit_esp32spi import PWMOut
4445
# RED_LED = PWMOut.PWMOut(esp, 26)
4546
# GREEN_LED = PWMOut.PWMOut(esp, 27)
4647
# BLUE_LED = PWMOut.PWMOut(esp, 25)
47-
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
48-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
48+
# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
49+
wifi = adafruit_esp32spi_wifimanager.WiFiManager(
50+
esp, ssid, password, status_pixel=status_pixel
51+
)
4952

5053
print("Connecting to WiFi...")
5154

@@ -80,7 +83,7 @@
8083
#
8184
# Next create a device using the device template, and select Connect to get the device connection
8285
# details.
83-
# Add the connection details to your secrets.py file, using the following values:
86+
# Add the connection details to your settings.toml file, using the following values:
8487
#
8588
# 'id_scope' - the devices ID scope
8689
# 'device_id' - the devices device id
@@ -104,9 +107,9 @@
104107
device = IoTCentralDevice(
105108
pool,
106109
ssl_context,
107-
secrets["id_scope"],
108-
secrets["device_id"],
109-
secrets["device_sas_key"],
110+
id_scope,
111+
device_id,
112+
device_sas_key,
110113
)
111114

112115
# don't connect

examples/azureiot_esp32spi/azureiot_central_properties.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
from os import getenv
45
import random
56
import time
67
import board
@@ -11,12 +12,12 @@
1112
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
1213
import adafruit_connection_manager
1314

14-
# Get wifi details and more from a secrets.py file
15-
try:
16-
from secrets import secrets
17-
except ImportError:
18-
print("WiFi secrets are kept in secrets.py, please add them there!")
19-
raise
15+
# Get WiFi details and AWS Keys, ensure these are setup in settings.toml
16+
ssid = getenv("CIRCUITPY_WIFI_SSID")
17+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
18+
id_scope = getenv("id_scope")
19+
device_id = getenv("device_id")
20+
device_sas_key = getenv("device_sas_key")
2021

2122
# ESP32 Setup
2223
try:
@@ -32,19 +33,21 @@
3233
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
3334

3435
"""Use below for Most Boards"""
35-
status_light = neopixel.NeoPixel(
36+
status_pixel = neopixel.NeoPixel(
3637
board.NEOPIXEL, 1, brightness=0.2
3738
) # Uncomment for Most Boards
3839
"""Uncomment below for ItsyBitsy M4"""
39-
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
40+
# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
4041
# Uncomment below for an externally defined RGB LED
4142
# import adafruit_rgbled
4243
# from adafruit_esp32spi import PWMOut
4344
# RED_LED = PWMOut.PWMOut(esp, 26)
4445
# GREEN_LED = PWMOut.PWMOut(esp, 27)
4546
# BLUE_LED = PWMOut.PWMOut(esp, 25)
46-
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
47-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
47+
# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
48+
wifi = adafruit_esp32spi_wifimanager.WiFiManager(
49+
esp, ssid, password, status_pixel=status_pixel
50+
)
4851

4952
print("Connecting to WiFi...")
5053

@@ -87,7 +90,7 @@
8790
#
8891
# Next create a device using the device template, and select Connect to get the device connection
8992
# details.
90-
# Add the connection details to your secrets.py file, using the following values:
93+
# Add the connection details to your settings.toml file, using the following values:
9194
#
9295
# 'id_scope' - the devices ID scope
9396
# 'device_id' - the devices device id
@@ -105,9 +108,9 @@
105108
device = IoTCentralDevice(
106109
pool,
107110
ssl_context,
108-
secrets["id_scope"],
109-
secrets["device_id"],
110-
secrets["device_sas_key"],
111+
id_scope,
112+
device_id,
113+
device_sas_key,
111114
)
112115

113116

examples/azureiot_esp32spi/azureiot_central_simpletest.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
from os import getenv
45
import json
56
import random
67
import time
@@ -12,12 +13,12 @@
1213
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
1314
import adafruit_connection_manager
1415

15-
# Get wifi details and more from a secrets.py file
16-
try:
17-
from secrets import secrets
18-
except ImportError:
19-
print("WiFi secrets are kept in secrets.py, please add them there!")
20-
raise
16+
# Get WiFi details and AWS Keys, ensure these are setup in settings.toml
17+
ssid = getenv("CIRCUITPY_WIFI_SSID")
18+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
19+
id_scope = getenv("id_scope")
20+
device_id = getenv("device_id")
21+
device_sas_key = getenv("device_sas_key")
2122

2223
# ESP32 Setup
2324
try:
@@ -33,19 +34,21 @@
3334
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
3435

3536
"""Use below for Most Boards"""
36-
status_light = neopixel.NeoPixel(
37+
status_pixel = neopixel.NeoPixel(
3738
board.NEOPIXEL, 1, brightness=0.2
3839
) # Uncomment for Most Boards
3940
"""Uncomment below for ItsyBitsy M4"""
40-
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
41+
# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
4142
# Uncomment below for an externally defined RGB LED
4243
# import adafruit_rgbled
4344
# from adafruit_esp32spi import PWMOut
4445
# RED_LED = PWMOut.PWMOut(esp, 26)
4546
# GREEN_LED = PWMOut.PWMOut(esp, 27)
4647
# BLUE_LED = PWMOut.PWMOut(esp, 25)
47-
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
48-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
48+
# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
49+
wifi = adafruit_esp32spi_wifimanager.WiFiManager(
50+
esp, ssid, password, status_pixel=status_pixel
51+
)
4952

5053
print("Connecting to WiFi...")
5154

@@ -88,7 +91,7 @@
8891
#
8992
# Next create a device using the device template, and select Connect to get the device connection
9093
# details.
91-
# Add the connection details to your secrets.py file, using the following values:
94+
# Add the connection details to your settings.toml file, using the following values:
9295
#
9396
# 'id_scope' - the devices ID scope
9497
# 'device_id' - the devices device id
@@ -106,9 +109,9 @@
106109
device = IoTCentralDevice(
107110
pool,
108111
ssl_context,
109-
secrets["id_scope"],
110-
secrets["device_id"],
111-
secrets["device_sas_key"],
112+
id_scope,
113+
device_id,
114+
device_sas_key,
112115
)
113116

114117
print("Connecting to Azure IoT Central...")

0 commit comments

Comments
 (0)