Skip to content

Commit 1ad8085

Browse files
committed
updating simpletest
1 parent e5f9530 commit 1ad8085

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

examples/minimqtt_simpletest.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
import os
45
import ssl
56
import socketpool
67
import wifi
78
import adafruit_minimqtt.adafruit_minimqtt as MQTT
89

9-
# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
10-
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
10+
# Add settings.toml to your filesystem CIRCUITPY_WIFI_SSID and CIRCUITPY_WIFI_PASSWORD keys
11+
# with your WiFi credentials. DO NOT share that file or commit it into Git or other
1112
# source control.
12-
# pylint: disable=no-name-in-module,wrong-import-order
13-
try:
14-
from secrets import secrets
15-
except ImportError:
16-
print("WiFi secrets are kept in secrets.py, please add them there!")
17-
raise
18-
19-
# Set your Adafruit IO Username and Key in secrets.py
13+
14+
# Set your Adafruit IO Username and Key in settings.toml
2015
# (visit io.adafruit.com if you need to create an account,
2116
# or if you need your Adafruit IO key.)
22-
aio_username = secrets["aio_username"]
23-
aio_key = secrets["aio_key"]
24-
25-
print("Connecting to %s" % secrets["ssid"])
26-
wifi.radio.connect(secrets["ssid"], secrets["password"])
27-
print("Connected to %s!" % secrets["ssid"])
17+
aio_username = os.getenv("aio_username")
18+
aio_key = os.getenv("aio_key")
19+
aio_broker = os.getenv("broker")
20+
aio_port = os.getenv("port")
21+
22+
print("Connecting to %s" % os.getenv("CIRCUITPY_WIFI_SSID"))
23+
wifi.radio.connect(
24+
os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")
25+
)
26+
print("Connected to %s!" % os.getenv("CIRCUITPY_WIFI_SSID"))
2827

2928
### Topic Setup ###
3029

@@ -36,6 +35,7 @@
3635
# Use this topic if you'd like to connect to io.adafruit.com
3736
# mqtt_topic = secrets["aio_username"] + '/feeds/temperature'
3837

38+
3939
### Code ###
4040
# Define callback methods which are called when events occur
4141
# pylint: disable=unused-argument, redefined-outer-name
@@ -77,10 +77,10 @@ def message(client, topic, message):
7777

7878
# Set up a MiniMQTT Client
7979
mqtt_client = MQTT.MQTT(
80-
broker=secrets["broker"],
81-
port=secrets["port"],
82-
username=secrets["aio_username"],
83-
password=secrets["aio_key"],
80+
broker=aio_broker,
81+
port=aio_port,
82+
username=os.getenv("CIRCUITPY_WIFI_SSID"),
83+
password=os.getenv("CIRCUITPY_WIFI_PASSWORD"),
8484
socket_pool=pool,
8585
ssl_context=ssl.create_default_context(),
8686
)

0 commit comments

Comments
 (0)