diff --git a/data/mesh.py b/data/mesh.py index 94ddce5..50eb435 100644 --- a/data/mesh.py +++ b/data/mesh.py @@ -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(): diff --git a/data/mesh.sh b/data/mesh.sh index cd2e7ff..5204e55 100755 --- a/data/mesh.sh +++ b/data/mesh.sh @@ -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 diff --git a/web/app.rb b/web/app.rb index f385807..1d1e0b9 100644 --- a/web/app.rb +++ b/web/app.rb @@ -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 diff --git a/web/app.sh b/web/app.sh index d7f729f..2ec1754 100755 --- a/web/app.sh +++ b/web/app.sh @@ -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