From 043e56e6f71e9a2c258bfeaa37f64b6acb458d34 Mon Sep 17 00:00:00 2001 From: Marcus Brown Date: Sun, 20 Oct 2024 17:28:56 +1100 Subject: [PATCH] Fetch existing retained snapshot upon initial connection - Added logic to request the retained snapshot message upon MQTT connection. - Ensure initial snapshot is processed after connecting to the MQTT broker. - Improved debugging logs for better traceability. --- dayglo_detector/dayglo_detector.py | 7 +++++++ docker-compose.yml | 18 +++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/dayglo_detector/dayglo_detector.py b/dayglo_detector/dayglo_detector.py index c87b388..85f4ad7 100644 --- a/dayglo_detector/dayglo_detector.py +++ b/dayglo_detector/dayglo_detector.py @@ -22,6 +22,9 @@ last_rating = 0 LOWER_COLOR = np.array([20, 100, 100]) UPPER_COLOR = np.array([40, 255, 255]) +# Track if the initial snapshot has been processed +initial_snapshot_processed = False + def on_connect(client, userdata, flags, rc): if rc == 0: print("Connected successfully to MQTT broker") @@ -30,6 +33,8 @@ def on_connect(client, userdata, flags, rc): publish_discovery_configurations() # Publish initial rating of 0 publish_rating(0) + # Request the retained snapshot to process the initial image + client.publish(MQTT_SNAPSHOT_TOPIC, "", qos=1) else: print(f"Failed to connect, return code {rc}") @@ -50,9 +55,11 @@ def publish_rating(rating): client.publish(MQTT_TOPIC_PUBLISH, json.dumps({"rating": rating})) def on_message(client, userdata, msg): + global initial_snapshot_processed if msg.topic == MQTT_SNAPSHOT_TOPIC: print("Snapshot received") process_snapshot(msg.payload) + initial_snapshot_processed = True def process_snapshot(payload): if not payload: diff --git a/docker-compose.yml b/docker-compose.yml index c8b12c5..c3fd6aa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -52,12 +52,12 @@ services: limits: cpus: '0.9' memory: 5000M - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:5000/api/version"] - interval: 30s - timeout: 10s - retries: 5 - start_period: 30s + #healthcheck: + # test: ["CMD", "curl", "-f", "http://localhost:5000/api/version"] + # interval: 30s + # timeout: 10s + # retries: 5 + # start_period: 30s dayglo_detector: container_name: dayglo_detector @@ -73,9 +73,9 @@ services: MQTT_PASSWORD: 'RadGawlEikWothecOmtAmmoihumid8' FRIGATE_URL: 'http://frigate:5000' INTERESTED_ZONES: 'Door_Front' - depends_on: - frigate: - condition: service_healthy + #depends_on: + # frigate: + # condition: service_healthy volumes: frigate-config: