From 0906cb22e6a819a0fb265d50060fe5461def79c2 Mon Sep 17 00:00:00 2001 From: Pi User Date: Fri, 3 Oct 2025 20:08:36 +1300 Subject: [PATCH] Add .env file support for UI client configuration - Use python-dotenv to load environment variables - Add CONTROL_SERVER_URI environment variable for WebSocket connection - Create .env.example with configuration examples - Update Pipfile to include python-dotenv dependency - Allows easy configuration for running UI on desktop pointing to Pi --- .env.example | 9 +++++++++ Pipfile | 1 + src/ui_client.py | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..430a4aa --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# Lighting Controller UI Client Configuration + +# WebSocket URI for the control server +# For local development (running UI on same machine as control server): +CONTROL_SERVER_URI=ws://localhost:8765 + +# For remote connection (running UI on desktop, control server on Pi): +# Replace with your Raspberry Pi's IP address +# CONTROL_SERVER_URI=ws://10.1.1.117:8765 diff --git a/Pipfile b/Pipfile index dac6148..00389d9 100644 --- a/Pipfile +++ b/Pipfile @@ -13,6 +13,7 @@ python-rtmidi = "*" pyaudio = "*" aubio = "*" websocket-client = "*" +python-dotenv = "*" [dev-packages] diff --git a/src/ui_client.py b/src/ui_client.py index 54ad28f..717590a 100644 --- a/src/ui_client.py +++ b/src/ui_client.py @@ -15,10 +15,14 @@ import logging from async_tkinter_loop import async_handler, async_mainloop import websockets import websocket +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() # Configuration CONFIG_FILE = "config.json" -CONTROL_SERVER_URI = "ws://localhost:8765" +CONTROL_SERVER_URI = os.getenv("CONTROL_SERVER_URI", "ws://localhost:8765") # Dark theme colors bg_color = "#2e2e2e"