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.
This commit is contained in:
@@ -22,6 +22,9 @@ last_rating = 0
|
|||||||
LOWER_COLOR = np.array([20, 100, 100])
|
LOWER_COLOR = np.array([20, 100, 100])
|
||||||
UPPER_COLOR = np.array([40, 255, 255])
|
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):
|
def on_connect(client, userdata, flags, rc):
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
print("Connected successfully to MQTT broker")
|
print("Connected successfully to MQTT broker")
|
||||||
@@ -30,6 +33,8 @@ def on_connect(client, userdata, flags, rc):
|
|||||||
publish_discovery_configurations()
|
publish_discovery_configurations()
|
||||||
# Publish initial rating of 0
|
# Publish initial rating of 0
|
||||||
publish_rating(0)
|
publish_rating(0)
|
||||||
|
# Request the retained snapshot to process the initial image
|
||||||
|
client.publish(MQTT_SNAPSHOT_TOPIC, "", qos=1)
|
||||||
else:
|
else:
|
||||||
print(f"Failed to connect, return code {rc}")
|
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}))
|
client.publish(MQTT_TOPIC_PUBLISH, json.dumps({"rating": rating}))
|
||||||
|
|
||||||
def on_message(client, userdata, msg):
|
def on_message(client, userdata, msg):
|
||||||
|
global initial_snapshot_processed
|
||||||
if msg.topic == MQTT_SNAPSHOT_TOPIC:
|
if msg.topic == MQTT_SNAPSHOT_TOPIC:
|
||||||
print("Snapshot received")
|
print("Snapshot received")
|
||||||
process_snapshot(msg.payload)
|
process_snapshot(msg.payload)
|
||||||
|
initial_snapshot_processed = True
|
||||||
|
|
||||||
def process_snapshot(payload):
|
def process_snapshot(payload):
|
||||||
if not payload:
|
if not payload:
|
||||||
|
|||||||
+9
-9
@@ -52,12 +52,12 @@ services:
|
|||||||
limits:
|
limits:
|
||||||
cpus: '0.9'
|
cpus: '0.9'
|
||||||
memory: 5000M
|
memory: 5000M
|
||||||
healthcheck:
|
#healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:5000/api/version"]
|
# test: ["CMD", "curl", "-f", "http://localhost:5000/api/version"]
|
||||||
interval: 30s
|
# interval: 30s
|
||||||
timeout: 10s
|
# timeout: 10s
|
||||||
retries: 5
|
# retries: 5
|
||||||
start_period: 30s
|
# start_period: 30s
|
||||||
|
|
||||||
dayglo_detector:
|
dayglo_detector:
|
||||||
container_name: dayglo_detector
|
container_name: dayglo_detector
|
||||||
@@ -73,9 +73,9 @@ services:
|
|||||||
MQTT_PASSWORD: 'RadGawlEikWothecOmtAmmoihumid8'
|
MQTT_PASSWORD: 'RadGawlEikWothecOmtAmmoihumid8'
|
||||||
FRIGATE_URL: 'http://frigate:5000'
|
FRIGATE_URL: 'http://frigate:5000'
|
||||||
INTERESTED_ZONES: 'Door_Front'
|
INTERESTED_ZONES: 'Door_Front'
|
||||||
depends_on:
|
#depends_on:
|
||||||
frigate:
|
# frigate:
|
||||||
condition: service_healthy
|
# condition: service_healthy
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
frigate-config:
|
frigate-config:
|
||||||
|
|||||||
Reference in New Issue
Block a user