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
+9 -5
View File
@@ -415,10 +415,10 @@ async def handle_telemetry_request(endpoint: str):
# 1. Fetch systemd logs asynchronously
logs_list = await get_systemd_logs(lines=200, service_name="smartwave")
# 2. Unpack temperature and humidity from sensors.temp_hum
# 2. Unpack temperature and humidity
ambient_temp, ambient_humidity = temp_hum.get_temperature_and_humidity_with_retry()
# 3. Build the telemetry payload
# 3. Build the telemetry payload (returns a JSON string)
telemetry_payload = payloads.telemetry_payload(
device_id=DEVICE_ID,
microwave_states=microwave_states,
@@ -431,14 +431,18 @@ async def handle_telemetry_request(endpoint: str):
logs=logs_list
)
print(telemetry_payload)
print(f"[Telemetry] Sending payload with {len(logs_list)} log entries...")
# 4. Offload blocking HTTP POST to thread pool
# 4. Wait for he microwave turn to send the telemetry data to the cloud endpoint
timeout = int(DEVICE_ID.split("_")[-1]) * config.TELEMETRY_SEND_INTERVAL
print(f"[Telemetry] Waiting for {timeout}s before sending telemetry to avoid collisions...")
await asyncio.sleep(timeout)
# 5. Offload blocking HTTP POST to thread pool
response = await asyncio.to_thread(
requests.post,
endpoint,
json=telemetry_payload,
data=telemetry_payload, # <-- Changed from json=telemetry_payload
headers={"Content-Type": "application/json"},
timeout=15
)