Timeout before sending + fix api
Build, push image, and notify Watchtower / build-image (push) Successful in 43s
Build, push image, and notify Watchtower / notify (push) Successful in 11s

This commit is contained in:
2026-08-10 14:20:36 +02:00
parent 6af00b7990
commit 1c2c07471e
4 changed files with 27 additions and 10 deletions
+12 -2
View File
@@ -3,6 +3,7 @@ import base64
import uuid
import datetime
import sys
import json
from flask import Flask, request, jsonify
from pymongo import MongoClient
from APIs import generate, EdamamAPI
@@ -112,14 +113,23 @@ def cooking_params():
def telemetry():
data = request.get_json()
if not data:
if data is None:
return jsonify({"error": "Invalid or missing JSON payload"}), 400
# If the payload was double-encoded as a string, deserialize it
if isinstance(data, str):
try:
data = json.loads(data)
except (json.JSONDecodeError, TypeError):
return jsonify({"error": "String payload could not be parsed as JSON"}), 400
if not isinstance(data, dict):
return jsonify({"error": "Expected a JSON object/dictionary"}), 400
# Stamp UTC timestamp for Node-RED queries
data["received_at"] = datetime.datetime.now(datetime.timezone.utc).isoformat()
try:
# Mongo creates '_id' automatically upon insertion
telemetry_collection.insert_one(data)
return jsonify({"status": "success", "message": "Telemetry saved"}), 200