Files
RuView/firmware/esp32-csi-node/main/ota_update.h
T
Mathew Beaneandclaude-flow d25fb8192e fix(firmware): stop POST /ota overflowing the httpd stack
MEASURED 2026-09-29 on an ESP32-S3 (v0.8.12, 16 MB): every POST /ota of a
valid 1,228,672 B image died with "stack overflow in task httpd" and
RTC_SW_CPU_RST, so no OTA had ever completed on this firmware.

- ota_update.c: set config.stack_size = CONFIG_OTA_HTTPD_STACK_SIZE (new
  Kconfig, default 8192; HTTPD_DEFAULT_CONFIG gave 4096). Move the 1 KB
  receive buffer off the stack into a static (handlers are serialised on
  the one httpd task). Integer progress percent instead of %f.
  recv_wait_timeout stays 30 s.
- Log the httpd stack high-water mark after every POST /ota and
  POST /wasm/upload so the size rests on device data.
- wasm_upload.c: GET /wasm/list builds its 2 KB JSON on the heap.
- RUNBOOK §3 (over the air) records the failure and the high-water-mark
  log line.

Device check after the fix (same S3): "httpd stack after POST /ota: 4900 of
8192 bytes never used", i.e. about 3.3 KB peak. The ADR with the full
hardware evidence follows in this series (ADR-379).

This overlaps PR #1594, which raises the same stack. If #1594 lands first,
drop this commit; the rest of the series does not depend on it.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-10-02 03:11:07 -04:00

43 lines
1.2 KiB
C

/**
* @file ota_update.h
* @brief HTTP OTA firmware update endpoint for ESP32-S3 CSI Node.
*
* Provides an HTTP server endpoint that accepts firmware binaries
* for over-the-air updates without physical access to the device.
*/
#ifndef OTA_UPDATE_H
#define OTA_UPDATE_H
#include "esp_err.h"
/**
* Initialize the OTA update HTTP server.
* Starts a lightweight HTTP server on port 8032 that accepts
* POST /ota with a firmware binary payload.
*
* @return ESP_OK on success.
*/
esp_err_t ota_update_init(void);
/**
* Initialize the OTA update HTTP server and return the handle.
* Same as ota_update_init() but exposes the httpd_handle_t so
* other modules (e.g. WASM upload) can register additional endpoints.
*
* @param out_server Output: HTTP server handle (may be NULL on failure).
* @return ESP_OK on success.
*/
esp_err_t ota_update_init_ex(void **out_server);
/**
* Log the httpd task's stack high-water mark (bytes never used). Call from an
* HTTP handler on the OTA server after its deepest work, so the configured
* CONFIG_OTA_HTTPD_STACK_SIZE is backed by a measured margin.
*
* @param what Short label for the handler, e.g. "POST /ota".
*/
void ota_update_log_httpd_stack(const char *what);
#endif /* OTA_UPDATE_H */