Improve MQTT resilience, clarify behavior, and minor UX

Switch to Paho v2 callbacks; add loop_start() and reconnect_delay_set() for auto-reconnect
Rework on_connect/on_disconnect to v2 signatures; handle session_present and reconnection flows
Gate heartbeats with client.is_connected() and add short retry on rc=4 (NO_CONN)
Re-send discovery after reconnect; ensure re-subscription to all topics
Add startup terminal message with ISO timestamp in simclient.py
Docs: update README and Copilot instructions with reconnection/heartbeat guidance and benign rc=4 notes
This commit is contained in:
RobbStarkAustria
2025-11-30 09:20:48 +01:00
parent d14789b1f4
commit 65d7b99198
5 changed files with 166 additions and 33 deletions

View File

@@ -2,6 +2,9 @@
# Copy this file to .env and fill in values appropriate for your environment.
# Environment
# IMPORTANT: CEC TV control is automatically DISABLED when ENV=development
# to avoid constantly switching the TV on/off during testing.
# Set to 'production' to enable automatic CEC TV control.
ENV=development # development | production
DEBUG_MODE=0 # 1 to enable debug mode
LOG_LEVEL=INFO # DEBUG | INFO | WARNING | ERROR
@@ -12,17 +15,27 @@ MQTT_BROKER=<your-mqtt-broker-host-or-ip>
MQTT_PORT=1883
# Timing Configuration (seconds)
HEARTBEAT_INTERVAL=60
SCREENSHOT_INTERVAL=180
DISPLAY_CHECK_INTERVAL=15
HEARTBEAT_INTERVAL=60 # Heartbeat frequency in seconds
SCREENSHOT_INTERVAL=180 # Screenshot capture frequency in seconds
DISPLAY_CHECK_INTERVAL=15 # Display Manager event check frequency in seconds
# File/API Server (used to download presentation files)
# If event URLs use host 'server', the client rewrites them to this server.
# You can either set FILE_SERVER_BASE_URL (preferred) or FILE_SERVER_HOST+PORT+SCHEME.
FILE_SERVER_HOST=
FILE_SERVER_PORT=8000
FILE_SERVER_SCHEME=http
# FILE_SERVER_BASE_URL=http://<your-file-server-host>:8000 # optional, takes precedence
# By default, the client rewrites incoming file URLs that point to 'server' to this host.
# If not set, FILE_SERVER_HOST defaults to the same host as MQTT_BROKER.
# You can also set FILE_SERVER_BASE_URL (e.g., http://192.168.1.10:8000) to override entirely.
FILE_SERVER_HOST= # optional: e.g., 192.168.43.100
FILE_SERVER_PORT=8000 # default port for API server
FILE_SERVER_SCHEME=http # http or https
# FILE_SERVER_BASE_URL= # optional: takes precedence over the above when set
# HDMI-CEC TV Control (optional)
# Automatically turn TV on/off based on event scheduling
# NOTE: CEC is automatically DISABLED when ENV=development to avoid constantly switching TV on/off during testing
CEC_ENABLED=true # Enable automatic TV power control in production (true/false)
CEC_DEVICE=0 # Target CEC device (TV, 0, etc.)
CEC_TURN_OFF_DELAY=30 # Seconds to wait before turning off TV after last event ends
CEC_POWER_ON_WAIT=5 # Seconds to wait after power ON command (for TV to boot up)
CEC_POWER_OFF_WAIT=5 # Seconds to wait after power OFF command (increased for slower TVs)
# Optional: MQTT authentication (if your broker requires username/password)
#MQTT_USERNAME=