Harden mesh utilities (#45)

This commit is contained in:
l5y
2025-09-14 22:02:06 +02:00
committed by GitHub
parent 7773bfc331
commit 547518a105
4 changed files with 16 additions and 12 deletions
+8 -7
View File
@@ -141,9 +141,11 @@ def store_packet_dict(p: dict):
if not text:
return # ignore non-text packets
# port filter (optional): ensure it's TEXT_MESSAGE_APP if present
portnum = _first(dec, "portnum", default=None)
# If you want to enforce: if portnum and portnum != "TEXT_MESSAGE_APP": return
# port filter: only keep packets from the TEXT_MESSAGE_APP port
portnum_raw = _first(dec, "portnum", default=None)
portnum = str(portnum_raw).upper() if portnum_raw is not None else None
if portnum and portnum not in {"1", "TEXT_MESSAGE_APP"}:
return # ignore non-text-message ports
# channel (prefer decoded.channel if present; else top-level)
ch = _first(dec, "channel", default=None)
@@ -192,14 +194,13 @@ def store_packet_dict(p: dict):
# PubSub receive handler
def on_receive(packet, interface):
p = None
try:
p = _pkt_to_dict(packet)
store_packet_dict(p)
except Exception as e:
try:
print("[warn] failed to store packet:", e, "| keys:", list(p.keys()) if isinstance(p, dict) else type(p))
except Exception:
print("[warn] failed to store packet:", e)
info = list(p.keys()) if isinstance(p, dict) else type(packet)
print(f"[warn] failed to store packet: {e} | info: {info}")
# --- Main ---------------------------------------------------------------------
def main():
+5 -3
View File
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
python -m venv .venv && source .venv/bin/activate
pip install meshtastic
python mesh.py
python -m venv .venv
source .venv/bin/activate
pip install -U meshtastic
exec python mesh.py
+1 -1
View File
@@ -46,7 +46,7 @@ get "/api/nodes" do
end
def query_messages(limit)
db = SQLite3::Database.new(DB_PATH)
db = SQLite3::Database.new(DB_PATH, readonly: true)
db.results_as_hash = true
rows = db.execute <<~SQL, [limit]
SELECT m.*, n.*, m.snr AS msg_snr
+2 -1
View File
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
bundle install
ruby app.rb -p 41447 -o 127.0.0.1
exec ruby app.rb -p 41447 -o 127.0.0.1