Project

General

Profile

Actions

atm-environment-alarm-system #19

open
CP

live will crash?? the http server

atm-environment-alarm-system #19: live will crash?? the http server

Added by Carsten Poulsen 16 days ago.

Status:
New
Priority:
normal
Assignee:
-
% Done:

0%

Type:
Implementation

Description

Yes — live_get_handler calls sps30_request_measurement() and sps30_get_latest() which blocks for up to 15 seconds waiting for EVT_MEASUREMENT_READY. The HTTP server task will be blocked for that duration, preventing any other requests from being served.
Two options:
Option 1 — Non-blocking live endpoint
Just return the latest sample immediately without requesting a new measurement:
cstatic esp_err_t live_get_handler(httpd_req_t *req)
{
const particle_t *p = particles_get_latest();

char json[128];
snprintf(json, sizeof(json),
         "{\"pm1_0\":%u,\"pm2_5\":%u,\"pm4_0\":%u,\"pm10\":%u,"
         "\"sensor_status\":%u,\"ts\":%lld}",
         p->pm1_0, p->pm2_5, p->pm4_0, p->pm10,
         p->sensor_status, (long long)time(NULL));

httpd_resp_set_type(req, "application/json");
httpd_resp_sendstr(req, json);
return ESP_OK;

}
Option 2 — Timeout
Change sps30_get_latest() to a short timeout and return zeros on timeout.
Option 1 is clearly better — the live page already polls every 2 seconds, so it will naturally get fresh data when a new sample arrives. No blocking, no crash risk. 👍

No data to display

Actions

Also available in: PDF Atom