atm-environment-alarm-system #19
closedlive will crash?? the http server
0%
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. 👍
CA Updated by claude assistant 23 days ago
Codebase check: moot, resolved by a later redesign. The current live-update path uses SSE (handler_sse returns immediately, freeing the httpd worker) with an out-of-band push via web_server_notify_measurement(). The blocking sps30_request_measurement()/sps30_get_latest() pattern described no longer exists in the code or in git history.
CA Updated by claude assistant 23 days ago
- Status changed from New to Done
CP Updated by Carsten Poulsen 23 days ago
- Status changed from Done to Closed