Wire WiFi creds via .env + build-time injection, add heartbeat reporting
Adopts the weather-display pattern: .env file parsed by tools/load_env.py and injected as -D compiler flags. WIFI_NETWORKS uses "SSID:password" format. ESP32 now sends a heartbeat POST after each display update so the server can track frame status for the HA integration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
27
firmware/tools/load_env.py
Normal file
27
firmware/tools/load_env.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""
|
||||
PlatformIO pre-build script: reads .env and injects values as -D build flags.
|
||||
|
||||
Handles quoting so that comma-separated WIFI_NETWORKS works as a single string.
|
||||
"""
|
||||
|
||||
Import("env")
|
||||
import os
|
||||
|
||||
env_file = os.path.join(env.get("PROJECT_DIR", "."), ".env")
|
||||
if not os.path.exists(env_file):
|
||||
print("WARNING: .env file not found, skipping credential injection")
|
||||
else:
|
||||
with open(env_file) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
key, _, value = line.partition("=")
|
||||
key = key.strip()
|
||||
value = value.strip().strip('"').strip("'")
|
||||
if not key or not value:
|
||||
continue
|
||||
# Escape for C string literal
|
||||
escaped = value.replace("\\", "\\\\").replace('"', '\\"')
|
||||
env.Append(CPPDEFINES=[(key, env.StringifyMacro(escaped))])
|
||||
print(f" .env: {key} = {value[:20]}...")
|
||||
Reference in New Issue
Block a user