|
8 | 8 | Author: Melissa LeBlanc-Williams for Adafruit Industries |
9 | 9 | """ |
10 | 10 |
|
| 11 | +import os |
11 | 12 | import time |
12 | 13 | import ssl |
13 | 14 | import json |
|
27 | 28 | # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller |
28 | 29 | sht = adafruit_shtc3.SHTC3(i2c) |
29 | 30 |
|
30 | | -# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and |
31 | | -# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other |
32 | | -# source control. |
33 | | -# pylint: disable=no-name-in-module,wrong-import-order |
34 | | -try: |
35 | | - from secrets import secrets |
36 | | -except ImportError: |
37 | | - print("WiFi secrets are kept in secrets.py, please add them there!") |
38 | | - raise |
39 | | - |
40 | | -wifi.radio.connect(secrets["ssid"], secrets["password"]) |
41 | | -print("Connected to %s!" % secrets["ssid"]) |
| 31 | +wifi.radio.connect(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")) |
| 32 | +print("Connected to %s!" % os.getenv("CIRCUITPY_WIFI_SSID")) |
42 | 33 |
|
43 | 34 | # Create a socket pool |
44 | 35 | pool = socketpool.SocketPool(wifi.radio) |
45 | 36 |
|
46 | 37 | # Set up a MiniMQTT Client |
47 | 38 | mqtt_client = MQTT.MQTT( |
48 | | - broker=secrets["mqtt_broker"], |
49 | | - port=secrets["mqtt_port"], |
50 | | - username=secrets["mqtt_username"], |
51 | | - password=secrets["mqtt_password"], |
| 39 | + broker=os.getenv("MQTT_BROKER"), |
| 40 | + port=os.getenv("MQTT_PORT"), |
| 41 | + username=os.getenv("MQTT_USERNAME"), |
| 42 | + password=os.getenv("MQTT_PASSWORD"), |
52 | 43 | socket_pool=pool, |
53 | 44 | ssl_context=ssl.create_default_context(), |
54 | 45 | ) |
|
0 commit comments