Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove secrets usage #98

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import time
from os import getenv

import adafruit_tmp117
import adafruit_touchscreen
Expand Down Expand Up @@ -275,7 +276,7 @@ def list(self):
)
else:
print("\nTabLayout test with I2C Temperature sensor and I2C Realtime clock")
print("Add your WiFi SSID, WiFi password and Timezone in file: secrets.h\n")
print("Add your WiFi SSID, WiFi password and Timezone in file: settings.toml\n")

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

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

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

# Get our username, key and desired timezone
location = secrets.get("timezone", None)
# Get our desired timezone
location = getenv("timezone", None)

print("\nConnecting to AP...")
while not esp.is_connected:
try:
esp.connect_AP(secrets["ssid"], secrets["password"])
esp.connect_AP(ssid, password)
except RuntimeError as e:
print("could not connect to AP, retrying: ", e)
continue
Expand Down Expand Up @@ -359,7 +356,7 @@ def refresh_from_NTP():
myVars.write("online_time_present", True)
myVars.write("ntp_refresh", False)
# Get the current time in seconds since Jan 1, 1970 and correct it for local timezone
# (defined in secrets.h)
# (defined in settings.toml)
ntp_current_time = time.time()
if myVars.read("my_debug"):
print(f"Seconds since Jan 1, 1970: {ntp_current_time} seconds")
Expand All @@ -377,9 +374,9 @@ def refresh_from_NTP():
# Initialize the NTP object
ntp = NTP(esp)

location = secrets.get("timezone", location)
location = getenv("timezone", location)
if myVars.read("my_debug"):
print("location (from secrets.h) = ", location)
print(f"location (from settings.toml) = {location}")
if location == "Europe/Lisbon":
if myVars.read("my_debug"):
print("Using timezone Europe/Lisbon")
Expand Down