docs: precise SNEK callback config for JSON POST body

- Step-by-step field-by-field callback config table
- Common pitfall documented: don't paste JSON body in "Line pattern"
- Exact JSON body template format (spaces around colons required)
- Companion dashboard deployment steps

Backend also cleaned up: unified query-string / JSON body parsing
via a single _num() helper instead of nested try/except blocks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 17:58:05 +02:00
parent a77776d6d8
commit 2e24415224
2 changed files with 66 additions and 35 deletions
+17 -12
View File
@@ -63,19 +63,24 @@ def index():
return send_from_directory("static", "index.html")
@app.route("/webhook", methods=["POST"])
def _num(x, cast=float):
try:
return cast(x)
except (TypeError, ValueError):
return None
@app.route("/webhook", methods=["POST", "GET"])
def webhook():
"""
SNEK callback endpoint.
SNEK sends JSON with: device, time, data, rssi, snr, seqNumber, etc.
"""
body = request.get_json(force=True, silent=True) or {}
device = (body.get("device") or "").lower()
raw = (body.get("data") or "").lower()
ts = float(body.get("time") or time.time())
rssi = body.get("rssi")
snr = body.get("snr")
seq_number = body.get("seqNumber")
"""SNEK callback endpoint. Accepts JSON body OR query string / form params."""
src = request.get_json(force=True, silent=True) or request.values
device = (src.get("device") or "").lower()
raw = (src.get("data") or "").lower()
ts = _num(src.get("time")) or time.time()
rssi = _num(src.get("rssi"))
snr = _num(src.get("snr"))
seq_number = _num(src.get("seqNumber") or src.get("seqnumber"), int)
if not device or not raw:
return jsonify({"error": "missing device or data"}), 400