More work on the ESP32C3 Boilerplate

This commit is contained in:
2026-06-27 20:00:17 -05:00
parent bb7aa5d5ca
commit 54ae1e66da
21 changed files with 833 additions and 146 deletions

View File

@@ -1,4 +1,4 @@
#include "../app.h"
#include "app.h"
#include <HTTPClient.h>
#include <LittleFS.h>
@@ -160,7 +160,7 @@ static bool streamPackageFromUrl(const String &url, String &error) {
}
void handleOtaCheck() {
if (!authorize("/api/ota/check", "POST")) return;
if (!authorize()) return;
HTTPClient http;
http.begin(updateUrl);
int code = http.GET();
@@ -170,8 +170,8 @@ void handleOtaCheck() {
}
void handleOtaRun() {
if (!authorize("/api/ota/run", "POST")) return;
appendLog(LOG_INFO, "package URL update started");
if (!authorize()) return;
appendLog(LOG_SECURITY_AUDIT, "package URL update started");
String error;
if (!streamPackageFromUrl(updateUrl, error)) return sendJson(502, jsonError(error));
sendJson(200, jsonOk("\"restart\":true,\"filesystemUpdated\":true,\"firmwareUpdated\":true"));
@@ -180,7 +180,7 @@ void handleOtaRun() {
}
void handleUpdateUploadDone() {
if (!authorize("/api/update", "POST")) return;
if (!authorize()) return;
bool ok = packageState.stage == PKG_DONE;
String error = packageState.error.length() ? packageState.error : "Incomplete update package";
sendJson(ok ? 200 : 500, ok ? jsonOk("\"restart\":true,\"filesystemUpdated\":true,\"firmwareUpdated\":true") : jsonError(error));
@@ -193,8 +193,8 @@ void handleUpdateUploadDone() {
void handleUpdateUploadChunk() {
HTTPUpload &upload = server.upload();
if (upload.status == UPLOAD_FILE_START) {
if (!authorize("/api/update", "POST")) return;
appendLog(LOG_INFO, "package upload started");
if (!authorize()) return;
appendLog(LOG_SECURITY_AUDIT, "package upload started");
resetPackageState();
} else if (upload.status == UPLOAD_FILE_WRITE) {
feedPackageBytes(upload.buf, upload.currentSize);