From 9b7c76c801b1b4380e24971f949b7c4734bc34ed Mon Sep 17 00:00:00 2001 From: Roby Date: Sun, 1 Nov 2026 09:31:40 +0100 Subject: [PATCH] fix(telemetry): allineamento stati hangtime e risoluzione falsi positivi sui beacon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Backend (mqtt_service.py): Aggiunta logica per intercettare i pacchetti beacon in assenza di traffico voce. Il sistema ora pulisce la memoria dei modi alternativi (es. D-Star/YSF) se il beacon è DMR, prevenendo il blocco dell'interfaccia su un vecchio protocollo. - Frontend (app.js): La memorizzazione del colore e del modo per la gestione dell'hangtime (Hold) ora scatta con la condizione `!isIdle` anziché solo con il PTT voce (`isTx`). - I badge della dashboard Home ora mostrano coerentemente il protocollo corretto per tutta la durata dell'hangtime, sia dopo un passaggio voce che dopo un beacon di rete. --- services/mqtt_service.py | 52 +++++++++++++--------------------------- static/js/app.js | 4 ++-- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/services/mqtt_service.py b/services/mqtt_service.py index 99ce02c..5c64195 100644 --- a/services/mqtt_service.py +++ b/services/mqtt_service.py @@ -1,6 +1,5 @@ import json import re -import datetime from paho.mqtt import client as mqtt_client from core.config import config, logger from core.database import save_to_sqlite @@ -19,7 +18,7 @@ def on_connect(client, userdata, flags, reason_code, properties=None): default_topics = [ "servizi/+/stat", "dmr-gateway/+/json", "devices/+/services", "nxdn-gateway/+/json", "ysf-gateway/+/json", "p25-gateway/+/json", - "dstar-gateway/+/json", "mmdvm/+/json", "data/#", "aprs-gateway/aprs" + "dstar-gateway/+/json", "mmdvm/+/json", "data/#" ] topics_list = config.get('mqtt', {}).get('topics', default_topics) @@ -43,35 +42,6 @@ def on_message(client, userdata, msg): try: topic = msg.topic payload = msg.payload.decode('utf-8', errors='replace').strip() - - # NUOVO BLOCCO APRS - if topic == "aprs-gateway/aprs": - try: - raw_aprs = payload - # Formato atteso: SOURCE>DEST,PATH:PAYLOAD - if ">" in raw_aprs and ":" in raw_aprs: - header, aprs_payload = raw_aprs.split(":", 1) - source, rest = header.split(">", 1) - - if "," in rest: - dest, path = rest.split(",", 1) - else: - dest = rest - path = "" - - aprs_data = { - "time": datetime.datetime.now().strftime("%H:%M:%S"), - "source": source.strip(), - "dest": dest.strip(), - "path": path.strip(), - "payload": aprs_payload.strip() - } - - state.socketio.emit('aprs_msg', aprs_data) - except Exception as e: - logger.error(f"Errore decodifica APRS: {e}") - return # Esci per non processare il resto della logica su questo topic - parts = topic.split('/') if len(parts) < 2: return @@ -333,17 +303,17 @@ def on_message(client, userdata, msg): # Salvataggio nel DB per la console log if m and "running" not in m.lower(): save_to_sqlite(cid, {'src_id': f"🌐 {m}", 'dst_id': 'NET'}, protocol=proto) - - # --- LETTURA STATO MODI DA TOPIC data/+/MMDVM --- + + + # --- MODI OPERATIVI MMDVM --- elif len(parts) == 3 and p0 == 'data' and p2 == 'mmdvm': try: cid = parts[1].lower() - data = json.loads(payload) - state.operating_modes[cid] = data + state.operating_modes[cid] = json.loads(payload) state.notify_update() except Exception as e: logger.error(f"Errore parsing MMDVM modes per {cid}: {e}") - + # --- 8. TRAFFICO VOCE MMDVM (DMR & MODI DIGITALI) --- elif parts[0] == 'mmdvm': data = json.loads(payload) @@ -359,6 +329,16 @@ def on_message(client, userdata, msg): state.client_telemetry[cid]["idle"] = False + # --- ALLINEAMENTO MODI PER BEACON --- + curr_mode = data.get('MMDVM', {}).get('mode', '') + if curr_mode: + if curr_mode.upper() == 'DMR': + state.client_telemetry[cid]["alt"] = "" + else: + old_alt = state.client_telemetry[cid].get("alt", "") + if not any(i in old_alt for i in ['🟢','🟣','🔵','🟠']): + state.client_telemetry[cid]["alt"] = f"📡 {curr_mode.upper()} BEACON" + if 'DMR' in data: d = data['DMR'] act = d.get('action') diff --git a/static/js/app.js b/static/js/app.js index 4121fae..7974966 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -892,8 +892,8 @@ async function refreshStates() { } // --- NESSUN TIMER LOCALE: COMANDA MQTT --- - // Memorizza l'ultimo modo in trasmissione per usarlo durante l'Hangtime - if (isTx && isOnline) { + // Memorizza l'ultimo modo dedotto per usarlo durante l'Hangtime o i Beacon + if (!isIdle && isOnline) { cardDiv.dataset.lastMode = txModeStr.replace("TX ", "").trim(); cardDiv.dataset.lastColor = activeModeColor; }