Fix: .env wird automatisch geladen (MQTT-Events kamen nicht an)

Ohne 'source .env' liefen Broker/Topic auf Defaults (127.0.0.1 statt
192.168.10.7, vehiclecounter/cam1 statt counter/cam1) -> keine Events.
Jetzt laedt app.py die .env per python-dotenv beim Start.

- load_dotenv() vor dem Auslesen von os.environ
- README: .env-Konfig + supervisord-Hinweis (directory=), python-dotenv

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-01 14:35:13 +02:00
parent bde547368d
commit d593f9e8af
2 changed files with 28 additions and 1 deletions

8
app.py
View File

@@ -26,6 +26,14 @@ from flask import (
from werkzeug.utils import secure_filename
from ultralytics import YOLO
# .env laden, BEVOR os.environ ausgelesen wird (Broker-/Kamera-/MQTT-Konfig).
# load_dotenv versteht auch "export VAR=..."-Zeilen und Inline-Kommentare.
try:
from dotenv import load_dotenv
load_dotenv()
except ImportError:
print("[config] python-dotenv nicht installiert - .env wird ignoriert", flush=True)
# ---------------------------------------------------------------------------
# Konfiguration
# ---------------------------------------------------------------------------