Skip to content

Commit

Permalink
Merge pull request #98 from justmobilize/remove-secrets-usage
Browse files Browse the repository at this point in the history
Remove secrets usage
  • Loading branch information
FoamyGuy authored Feb 28, 2025
2 parents d776d6e + 2f031fc commit 13376b5
Showing 1 changed file with 11 additions and 14 deletions.
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

0 comments on commit 13376b5

Please sign in to comment.