mirror of
https://github.com/l5yth/potato-mesh.git
synced 2026-08-07 09:22:53 +02:00
Harden mesh utilities (#45)
This commit is contained in:
+8
-7
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user