Skip to content

Commit 6fc1398

Browse files
authored
Merge pull request #2410 from adafruit/ESP32-S2-TFT-Boxing-Tracker-1
First Commit
2 parents d36bae8 + 6196472 commit 6fc1398

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

CPBoxing_Glove_Tracker/code.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2023 Trevor Beaton for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
4+
import os
45
import time
56
import ssl
67
import math
@@ -13,25 +14,18 @@
1314
from adafruit_adxl34x import ADXL345
1415
from adafruit_lc709203f import LC709203F, PackSize
1516

16-
17-
try:
18-
from secrets import secrets
19-
except ImportError:
20-
print("WiFi and Adafruit IO credentials are kept in secrets.py - please add them there!")
21-
raise
22-
23-
aio_username = secrets["aio_username"]
24-
aio_key = secrets["aio_key"]
17+
aio_username = os.getenv('aio_username')
18+
aio_key = os.getenv('aio_key')
2519

2620
# Wi-Fi
2721
try:
28-
print("Connecting to %s" % secrets["ssid"])
29-
wifi.radio.connect(secrets["ssid"], secrets["password"])
30-
print("Connected to %s!" % secrets["ssid"])
22+
print("Connecting to %s" % os.getenv('CIRCUITPY_WIFI_SSID'))
23+
wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
24+
print("Connected to %s!" % os.getenv('CIRCUITPY_WIFI_SSID'))
3125
# Wi-Fi connectivity fails with error messages, not specific errors, so this except is broad.
3226
except Exception as e: # pylint: disable=broad-except
33-
print("Failed to connect to WiFi. Error:", e, "\nBoard will hard reset in 5 seconds.")
34-
time.sleep(5)
27+
print("Failed to connect to WiFi. Error:", e, "\nBoard will hard reset in 30 seconds.")
28+
time.sleep(30)
3529
microcontroller.reset()
3630

3731
# Create a socket pool
@@ -40,8 +34,8 @@
4034
# Initialize a new MQTT Client object
4135
mqtt_client = MQTT.MQTT(
4236
broker="io.adafruit.com",
43-
username=secrets["aio_username"],
44-
password=secrets["aio_key"],
37+
username= aio_username,
38+
password= aio_key,
4539
socket_pool=pool,
4640
ssl_context=ssl.create_default_context(),
4741
)
@@ -50,26 +44,27 @@
5044
io = IO_MQTT(mqtt_client)
5145

5246
try:
53-
# If Adafruit IO is not connected...
5447
if not io.is_connected:
5548
# Connect the client to the MQTT broker.
5649
print("Connecting to Adafruit IO...")
5750
io.connect()
5851
print("Connected to Adafruit IO!")
5952
except Exception as e: # pylint: disable=broad-except
6053
print("Failed to get or send data, or connect. Error:", e,
61-
"\nBoard will hard reset in 30 seconds.")
54+
"\nBoard will hard reset in 30 seconds./n")
6255
time.sleep(30)
6356
microcontroller.reset()
6457

65-
threshold = 25 # set threshold value here
58+
threshold = 20 # set threshold value here
6659
time_interval = 0.5 # set the time interval in seconds
6760

6861
# create the I2C bus object
6962
i2c = board.STEMMA_I2C()
63+
7064
# For ADXL345
7165
accelerometer = ADXL345(i2c)
7266

67+
# To monitor the battery
7368
battery_monitor = LC709203F(i2c)
7469
battery_monitor.pack_size = PackSize.MAH400
7570

0 commit comments

Comments
 (0)