Skip to content

Commit 2f031fc

Browse files
committedFeb 27, 2025·
Remove secrets usage
1 parent d776d6e commit 2f031fc

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed
 

‎examples/hotplug_sensor_examples/displayio_layout_hotplug_temp_sensor.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212

1313
import time
14+
from os import getenv
1415

1516
import adafruit_tmp117
1617
import adafruit_touchscreen
@@ -275,7 +276,7 @@ def list(self):
275276
)
276277
else:
277278
print("\nTabLayout test with I2C Temperature sensor and I2C Realtime clock")
278-
print("Add your WiFi SSID, WiFi password and Timezone in file: secrets.h\n")
279+
print("Add your WiFi SSID, WiFi password and Timezone in file: settings.toml\n")
279280

280281
if myVars.read("my_debug"):
281282
while not i2c.try_lock():
@@ -303,13 +304,9 @@ def list(self):
303304
# NOTE: there is also the board.SD_CARD_DETECT pin (33)(but I don't know yet how to interface it)
304305
####
305306

306-
# you'll need to pass in an io username and key
307-
# Get wifi details and more from a secrets.py file
308-
try:
309-
from secrets import secrets
310-
except ImportError:
311-
print("WiFi secrets are kept in secrets.py, please add them there!")
312-
raise
307+
# Get WiFi details, ensure these are setup in settings.toml
308+
ssid = getenv("CIRCUITPY_WIFI_SSID")
309+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
313310

314311
if myVars.read("my_debug"):
315312
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
@@ -320,13 +317,13 @@ def list(self):
320317
for ap in esp.scan_networks():
321318
print("\t%s\t\tRSSI: %d" % (str(ap["ssid"], "utf-8"), ap["rssi"]))
322319

323-
# Get our username, key and desired timezone
324-
location = secrets.get("timezone", None)
320+
# Get our desired timezone
321+
location = getenv("timezone", None)
325322

326323
print("\nConnecting to AP...")
327324
while not esp.is_connected:
328325
try:
329-
esp.connect_AP(secrets["ssid"], secrets["password"])
326+
esp.connect_AP(ssid, password)
330327
except RuntimeError as e:
331328
print("could not connect to AP, retrying: ", e)
332329
continue
@@ -359,7 +356,7 @@ def refresh_from_NTP():
359356
myVars.write("online_time_present", True)
360357
myVars.write("ntp_refresh", False)
361358
# Get the current time in seconds since Jan 1, 1970 and correct it for local timezone
362-
# (defined in secrets.h)
359+
# (defined in settings.toml)
363360
ntp_current_time = time.time()
364361
if myVars.read("my_debug"):
365362
print(f"Seconds since Jan 1, 1970: {ntp_current_time} seconds")
@@ -377,9 +374,9 @@ def refresh_from_NTP():
377374
# Initialize the NTP object
378375
ntp = NTP(esp)
379376

380-
location = secrets.get("timezone", location)
377+
location = getenv("timezone", location)
381378
if myVars.read("my_debug"):
382-
print("location (from secrets.h) = ", location)
379+
print(f"location (from settings.toml) = {location}")
383380
if location == "Europe/Lisbon":
384381
if myVars.read("my_debug"):
385382
print("Using timezone Europe/Lisbon")

0 commit comments

Comments
 (0)
Please sign in to comment.