feat: ping drivers and push groups from the devices modal
POST /devices/ping broadcasts an ESP-NOW PING_REQ, collects the drivers' PING_RSP for timeout_s and registers or renames the ones that answer. A reply also counts as the driver being heard, so group updates go to it again. POST /devices/groups sends every ESP-NOW driver its groups and reports the acks. The devices modal gets the Ping drivers and Update groups buttons from main, with per-driver ping dots. UI files are now served with Cache-Control: no-cache and the firmware build hash as ETag, so a browser picks up a new UI right after an update instead of a day later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e7f238aebc
commit
19fea0b0a1
10 files changed
+559
-29
No files matched your search
+27
-6
@@ -1,8 +1,10 @@
|
||||
#include "web.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "esp_app_desc.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "web";
|
||||
@@ -98,8 +100,21 @@ void web_each(const char *prefix, void (*fn)(const char *name, void *ctx), void
|
||||
}
|
||||
}
|
||||
|
||||
// Every file changes only with the firmware, so the build's hash is the ETag: browsers revalidate on
|
||||
// each load (no-cache) and get a 304 until the next update, instead of running a stale UI for a day.
|
||||
static const char *etag(void)
|
||||
{
|
||||
static char tag[20];
|
||||
if (!tag[0]) {
|
||||
const uint8_t *sha = esp_app_get_description()->app_elf_sha256;
|
||||
snprintf(tag, sizeof(tag), "\"%02x%02x%02x%02x%02x%02x%02x%02x\"", sha[0], sha[1], sha[2], sha[3], sha[4], sha[5],
|
||||
sha[6], sha[7]);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
// path is the URL-relative name, e.g. "static/zones.js"
|
||||
static esp_err_t send_gz(httpd_req_t *req, const char *path, bool immutable)
|
||||
static esp_err_t send_gz(httpd_req_t *req, const char *path)
|
||||
{
|
||||
const uint8_t *data;
|
||||
uint32_t len;
|
||||
@@ -109,25 +124,31 @@ static esp_err_t send_gz(httpd_req_t *req, const char *path, bool immutable)
|
||||
if (!find_file(path, &data, &len)) {
|
||||
return httpd_resp_send_404(req);
|
||||
}
|
||||
httpd_resp_set_hdr(req, "Cache-Control", "no-cache");
|
||||
httpd_resp_set_hdr(req, "ETag", etag());
|
||||
char inm[24];
|
||||
if (httpd_req_get_hdr_value_str(req, "If-None-Match", inm, sizeof(inm)) == ESP_OK && !strcmp(inm, etag())) {
|
||||
httpd_resp_set_status(req, "304 Not Modified");
|
||||
return httpd_resp_send(req, NULL, 0);
|
||||
}
|
||||
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");
|
||||
return httpd_resp_send(req, (const char *)data, len);
|
||||
}
|
||||
|
||||
esp_err_t web_send_page(httpd_req_t *req, const char *name)
|
||||
{
|
||||
return send_gz(req, name, false);
|
||||
return send_gz(req, name);
|
||||
}
|
||||
|
||||
static esp_err_t index_handler(httpd_req_t *req)
|
||||
{
|
||||
return send_gz(req, "index.html", false);
|
||||
return send_gz(req, "index.html");
|
||||
}
|
||||
|
||||
static esp_err_t audio_page_handler(httpd_req_t *req)
|
||||
{
|
||||
return send_gz(req, "audio.html", false);
|
||||
return send_gz(req, "audio.html");
|
||||
}
|
||||
|
||||
static esp_err_t static_handler(httpd_req_t *req)
|
||||
@@ -140,7 +161,7 @@ static esp_err_t static_handler(httpd_req_t *req)
|
||||
}
|
||||
memcpy(path, uri, n);
|
||||
path[n] = 0;
|
||||
return send_gz(req, path, true);
|
||||
return send_gz(req, path);
|
||||
}
|
||||
|
||||
static esp_err_t favicon_handler(httpd_req_t *req)
|
||||
|
||||
Reference in new issue
Block a user