feat(mqtt): make subscription topics configurable via config.json
This commit is contained in:
@@ -172,18 +172,22 @@ def on_connect(client, userdata, flags, reason_code, properties=None):
|
|||||||
logger.info("✅ Successfully connected to MQTT Broker! Subscribing to topics...")
|
logger.info("✅ Successfully connected to MQTT Broker! Subscribing to topics...")
|
||||||
# Invia lo stato Online ai client web
|
# Invia lo stato Online ai client web
|
||||||
socketio.emit('mqtt_status', {'connected': True})
|
socketio.emit('mqtt_status', {'connected': True})
|
||||||
client.subscribe([
|
|
||||||
("servizi/+/stat", 0),
|
# --- LETTURA DINAMICA DEI TOPIC ---
|
||||||
("dmr-gateway/+/json", 0),
|
default_topics = [
|
||||||
("devices/+/services", 0),
|
"servizi/+/stat", "dmr-gateway/+/json", "devices/+/services",
|
||||||
("nxdn-gateway/+/json", 0),
|
"nxdn-gateway/+/json", "ysf-gateway/+/json", "p25-gateway/+/json",
|
||||||
("ysf-gateway/+/json", 0),
|
"dstar-gateway/+/json", "mmdvm/+/json", "devices/#", "data/#"
|
||||||
("p25-gateway/+/json", 0),
|
]
|
||||||
("dstar-gateway/+/json", 0),
|
|
||||||
("mmdvm/+/json", 0),
|
# Cerca la lista "topics" nel config.json, se non la trova usa quella di default
|
||||||
("devices/#", 0),
|
topics_list = config.get('mqtt', {}).get('topics', default_topics)
|
||||||
("data/#", 0)
|
|
||||||
])
|
# Converte la lista di stringhe nel formato richiesto da paho-mqtt: [(topic, qos), (topic, qos)...]
|
||||||
|
subscribe_list = [(topic, 0) for topic in topics_list]
|
||||||
|
|
||||||
|
client.subscribe(subscribe_list)
|
||||||
|
logger.info(f"Subscribed to {len(subscribe_list)} MQTT topics.")
|
||||||
else:
|
else:
|
||||||
mqtt_connected_status = False
|
mqtt_connected_status = False
|
||||||
socketio.emit('mqtt_status', {'connected': False})
|
socketio.emit('mqtt_status', {'connected': False})
|
||||||
|
|||||||
+13
-1
@@ -4,7 +4,19 @@
|
|||||||
"port": 1883,
|
"port": 1883,
|
||||||
"user": "your_username",
|
"user": "your_username",
|
||||||
"password": "your_password",
|
"password": "your_password",
|
||||||
"client_id": "fleet_backend_prod"
|
"client_id": "fleet_backend_prod",
|
||||||
|
"topics": [
|
||||||
|
"servizi/+/stat",
|
||||||
|
"dmr-gateway/+/json",
|
||||||
|
"devices/+/services",
|
||||||
|
"nxdn-gateway/+/json",
|
||||||
|
"ysf-gateway/+/json",
|
||||||
|
"p25-gateway/+/json",
|
||||||
|
"dstar-gateway/+/json",
|
||||||
|
"mmdvm/+/json",
|
||||||
|
"devices/#",
|
||||||
|
"data/#"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"web_admin": {
|
"web_admin": {
|
||||||
"default_user": "admin",
|
"default_user": "admin",
|
||||||
|
|||||||
Reference in New Issue
Block a user