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:
+17
-12
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user