feat(v2): ESP32-S3 controller with Ethernet, I2S mic beat detection and ESP-NOW

New ESP-IDF project in v2/ that replaces the Pi and the UART bridge:

- W5500 Ethernet, INMP441 beat/tempo detector (from esp32-eth), ESP-NOW master
- LittleFS data store and a JSON API over the Pi's db/*.json collections,
  with /db import and export; web UI minified and gzipped at build time
- Zone play/stop as 0x4C GROUP_CMD, preset push/send as CMD (binary v2
  envelope, byte-identical to src/util/binary_envelope.py), sequencer and
  scenes, driver registration from the boot hello
- Reliable bulk link: acks with retransmit, fragments, state-version digest
  and resync; beat frames sent twice with a lead so drivers fire together
- Bench tooling: lossy-link mode, synthetic beats with echo measurement,
  USB and logic-analyzer latency scripts, and docs/BENCH_TEST.md

Needs the matching led-driver changes (p2p branch) to receive the link and
beat frames.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Sonnet 5.5 committed 2026-10-27 17:15:28 +13:00
1 parent 7336c7fb22
commit a94d6a7de5
37 files changed
+5109

No files matched your search

+114
View File
@@ -0,0 +1,114 @@
#include "web.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"
static const char *TAG = "web";
#define CHUNK 2048
static const struct {
const char *ext;
const char *type;
} MIME[] = {
{ ".html", "text/html; charset=utf-8" },
{ ".js", "application/javascript; charset=utf-8" },
{ ".css", "text/css; charset=utf-8" },
{ ".json", "application/json" },
{ ".svg", "image/svg+xml" },
{ ".png", "image/png" },
{ ".ico", "image/x-icon" },
{ ".woff2", "font/woff2" },
};
static const char *mime_for(const char *path)
{
const char *dot = strrchr(path, '.');
for (size_t i = 0; dot && i < sizeof(MIME) / sizeof(MIME[0]); i++) {
if (strcmp(dot, MIME[i].ext) == 0) {
return MIME[i].type;
}
}
return "application/octet-stream";
}
// path is the URL-relative name, e.g. "static/zones.js"; the file on flash is "/www/<path>.gz"
static esp_err_t send_gz(httpd_req_t *req, const char *path, bool immutable)
{
char fs[128];
if (strstr(path, "..") || snprintf(fs, sizeof(fs), "/www/%s.gz", path) >= (int)sizeof(fs)) {
return httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "bad path");
}
FILE *f = fopen(fs, "rb");
if (!f) {
return httpd_resp_send_404(req);
}
httpd_resp_set_type(req, mime_for(path));
httpd_resp_set_hdr(req, "Content-Encoding", "gzip");
httpd_resp_set_hdr(req, "Cache-Control", immutable ? "public, max-age=86400" : "no-cache");
char *buf = malloc(CHUNK);
if (!buf) {
fclose(f);
return httpd_resp_send_500(req);
}
esp_err_t ret = ESP_OK;
size_t n;
while (ret == ESP_OK && (n = fread(buf, 1, CHUNK, f)) > 0) {
ret = httpd_resp_send_chunk(req, buf, n);
}
if (ret == ESP_OK) {
ret = httpd_resp_send_chunk(req, NULL, 0);
}
free(buf);
fclose(f);
return ret;
}
esp_err_t web_send_page(httpd_req_t *req, const char *name)
{
return send_gz(req, name, false);
}
static esp_err_t index_handler(httpd_req_t *req)
{
return send_gz(req, "index.html", false);
}
static esp_err_t static_handler(httpd_req_t *req)
{
char path[96];
const char *uri = req->uri + 1; // drop the leading '/'
size_t n = strcspn(uri, "?");
if (n >= sizeof(path)) {
return httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "uri too long");
}
memcpy(path, uri, n);
path[n] = 0;
return send_gz(req, path, true);
}
static esp_err_t favicon_handler(httpd_req_t *req)
{
httpd_resp_set_status(req, "204 No Content");
return httpd_resp_send(req, NULL, 0);
}
esp_err_t web_register(httpd_handle_t server)
{
const httpd_uri_t uris[] = {
{ .uri = "/", .method = HTTP_GET, .handler = index_handler },
{ .uri = "/static/*", .method = HTTP_GET, .handler = static_handler },
{ .uri = "/favicon.ico", .method = HTTP_GET, .handler = favicon_handler },
};
for (size_t i = 0; i < sizeof(uris) / sizeof(uris[0]); i++) {
esp_err_t err = httpd_register_uri_handler(server, &uris[i]);
if (err != ESP_OK) {
ESP_LOGE(TAG, "register %s: %s", uris[i].uri, esp_err_to_name(err));
return err;
}
}
return ESP_OK;
}