From 9fb0b01f30cacdad6590648d0935e87eec752e5d Mon Sep 17 00:00:00 2001 From: Roby Date: Fri, 16 Oct 2026 19:39:58 +0200 Subject: [PATCH] add RSSI data --- app.py | 17 ++++++++++++++--- templates/index.html | 13 ++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index ad23928..47751bc 100644 --- a/app.py +++ b/app.py @@ -95,6 +95,10 @@ def init_db(): try: c.execute("ALTER TABLE radio_logs ADD COLUMN source_ext TEXT DEFAULT ''") except sqlite3.OperationalError: pass + + try: + c.execute("ALTER TABLE radio_logs ADD COLUMN rssi REAL DEFAULT 0") + except sqlite3.OperationalError: pass c.execute('''CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT UNIQUE, password_hash TEXT, @@ -185,8 +189,15 @@ def save_cache(data): def save_to_sqlite(client_id, data, protocol="DMR"): conn = sqlite3.connect(DB_PATH, timeout=10) c = conn.cursor() - c.execute("INSERT INTO radio_logs (timestamp, client_id, protocol, source_id, target, slot, duration, ber, source_ext) VALUES (datetime('now', 'localtime'), ?, ?, ?, ?, ?, ?, ?, ?)", - (client_id, protocol, str(data.get('src_id', '---')), str(data.get('dst_id', '---')), data.get('slot', 0), round(data.get('duration', 0), 1), round(data.get('ber', 0), 2), str(data.get('src_ext', '')))) + + rssi_val = 0 + if 'rssi' in data and isinstance(data['rssi'], dict): + rssi_val = data['rssi'].get('ave', 0) + elif 'rssi' in data: + rssi_val = data['rssi'] + + c.execute("INSERT INTO radio_logs (timestamp, client_id, protocol, source_id, target, slot, duration, ber, source_ext, rssi) VALUES (datetime('now', 'localtime'), ?, ?, ?, ?, ?, ?, ?, ?, ?)", + (client_id, protocol, str(data.get('src_id', '---')), str(data.get('dst_id', '---')), data.get('slot', 0), round(data.get('duration', 0), 1), round(data.get('ber', 0), 2), str(data.get('src_ext', '')), rssi_val)) conn.commit() conn.close() notify_update('log_aggiornato') @@ -631,7 +642,7 @@ def get_clients(): def get_logs(): conn = sqlite3.connect(DB_PATH, timeout=10) c = conn.cursor() - c.execute("SELECT timestamp, client_id, protocol, source_id, target, slot, duration, ber, source_ext FROM radio_logs ORDER BY id DESC LIMIT 60") + c.execute("SELECT timestamp, client_id, protocol, source_id, target, slot, duration, ber, source_ext, rssi FROM radio_logs ORDER BY id DESC LIMIT 60") logs = c.fetchall() conn.close() return jsonify(logs) diff --git a/templates/index.html b/templates/index.html index dac5cb6..df5b41b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -213,6 +213,7 @@ Target / TG Duration BER + RSSI @@ -970,17 +971,23 @@ const time = row[0] ? row[0].split(' ')[1] : "--:--"; const clientId = row[1]; const protocol = row[2] || "DMR"; let source = row[3] || "---"; const target = row[4] || "---"; const rawSlot = row[5]; const source_ext = row[8]; + const rawRssi = row[9]; // Estrai il nuovo valore + let sourceHtml = esc(source); if (source_ext && source_ext.trim() !== "") { sourceHtml += ` /${esc(source_ext)}`; } const slotDisplay = protocol === "DMR" ? `TS${rawSlot}` : "--"; let protoColor = "#3b82f6"; if (protocol === "NXDN") protoColor = "#10b981"; else if (protocol === "YSF") protoColor = "#8b5cf6"; else if (protocol === "D-STAR") protoColor = "#06b6d4"; else if (protocol === "P25") protoColor = "#f59e0b"; + // Formatta l'RSSI (nascondilo se รจ 0) + const rssiDisplay = rawRssi && rawRssi !== 0 ? `${esc(rawRssi)} dBm` : '---'; + if (source.includes("๐ŸŒ")) { if (!networkLogs[clientId]) networkLogs[clientId] = ""; networkLogs[clientId] += `
[${esc(time)}] [${esc(protocol)}] ${esc(source.replace("๐ŸŒ", "").trim())}
`; } else { - tableHTML += `${esc(time)}${esc(String(clientId).toUpperCase())}${esc(protocol)}${esc(slotDisplay)}${sourceHtml}${esc(target.trim())}${esc(row[6])}s${esc(row[7])}%`; + // Aggiunto il TD per l'RSSI alla fine + tableHTML += `${esc(time)}${esc(String(clientId).toUpperCase())}${esc(protocol)}${esc(slotDisplay)}${sourceHtml}${esc(target.trim())}${esc(row[6])}s${esc(row[7])}%${rssiDisplay}`; } }); tbody.innerHTML = tableHTML; @@ -1121,10 +1128,10 @@ html += `
${esc(name)}${esc(String(status).toUpperCase())}
- ${!isOnline ? `` : ''} + ${!isOnline ? `` : ''} - ${isOnline ? `` : ''} + ${isOnline ? `` : ''}
`; }