Web updater improved

This commit is contained in:
2026-03-05 19:10:03 +01:00
parent 627790b5fc
commit b55ce57ce9
5 changed files with 17 additions and 28 deletions

View File

@@ -42,7 +42,7 @@ build_flags =
build_unflags =
-std=gnu++11
custom_version = 0.2.0
custom_version = 0.1.1
custom_versionformat = DEVELOP # Version format switch: e.g.DEVELOP=dev<yyyymmdd>|RELEASE=1.0.0
[env:obpkp61]

View File

@@ -22,16 +22,5 @@ String get_sha256(String payload) {
buffer[i*2+1] = hexmap[shaResult[i] & 0x0F];
}
buffer[sizeof(buffer) - 1] = '\0';
String hash = String(buffer);
ESP_LOGI(TAG, "SHA256 payload: %s", payload);
ESP_LOGI(TAG, "SHA256 hash: %s", hash.c_str());
//Serial.print("SHA256 payload: ");
//Serial.print(payload);
//Serial.println();
//Serial.print("SHA256-Hash: ");
//Serial.print(hash);
//Serial.println();
return hash;
return String(buffer);
}

View File

@@ -2,7 +2,6 @@
#include "config.h"
#include "webserver.h"
#include "led.h"
#include "hash.h"
#include <ArduinoJson.h>
#include <WiFi.h>
#include <Wire.h>
@@ -481,9 +480,6 @@ void setup() {
sht_available = (stat == 0x8010);
LOGI(TAG, "SHT31 state=0x%X", stat);
// Additional tests
String passhash = get_sha256("secretTEST");
xTaskCreatePinnedToCore(
ledTask, // Task function
"LEDTask", // Task name

View File

@@ -1,6 +1,7 @@
#include "main.h"
#include "config.h"
#include "webserver.h"
#include "hash.h"
#include "led.h"
#include <map>
#include <AsyncTCP.h>
@@ -96,11 +97,14 @@ void webserver_init() {
});
server.on("/api/checkpass", HTTP_GET, [](AsyncWebServerRequest *request) {
// hash has to be in sha256 format
LOGD(TAG, "checkpass called");
String hash = request->arg("hash");
StaticJsonDocument<100> doc;
// TODO _hash überprüfen!
// LOGD(TAG, "check hash: %s", hash);
doc["status"] = "OK";
String passhash = get_sha256(config.getString("adminPassword"));
LOGD(TAG, "check hash: %s", hash.c_str());
LOGD(TAG, "check against: %s", passhash.c_str());
doc["status"] = hash == passhash ? "OK" : "FAILED";
String out;
serializeJson(doc, out);
request->send(200, "application/json", out);
@@ -245,7 +249,7 @@ void webserver_init() {
LOGD(TAG, "POST %s=%s; key not found!", p->name(), p->value());
continue;
}
LOGD(TAG, "POST %s=%s", p->name(), p->value());
LOGD(TAG, "POST %s=%s", p->name(), p->value().c_str());
// get old value for comparison
ConfigValue oldval = config.get(p->name().c_str());
config.setValue(p->name().c_str(), p->value().c_str());
@@ -273,11 +277,15 @@ void webserver_init() {
server.on("/api/update", HTTP_POST, [](AsyncWebServerRequest *request) {
// the request handler is triggered after the upload has finished...
// create the response, add header, and send response
LOGI(TAG, "update called");
LOGD(TAG, "Firmware update finished");
StaticJsonDocument<100> doc;
if (updateSuccess) {
doc["status"] = "OK";
doc["message"] = "Update sucessfull, rebooting...";
// Wait for TCP ACK to ensure response is received completely
request->client()->onAck([](void* arg, AsyncClient* c, size_t len, uint32_t time) {
ESP.restart();
});
} else {
doc["status"] = "FAILED";
doc["message"] = updateError;
@@ -285,14 +293,10 @@ void webserver_init() {
String out;
serializeJson(doc, out);
request->send(200, "application/json", out);
if (updateSuccess) {
delay(100); // Ensure response is sent
ESP.restart();
}
}, [](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
// this is the new image upload part
if (index == 0) {
LOGI(TAG, "Retrieving firmware image named: %s", filename);
LOGI(TAG, "Retrieving firmware image named: %s", filename.c_str());
if (! Update.begin(UPDATE_SIZE_UNKNOWN)) {
Update.printError(Serial);
updateError = "Update.begin() failed";

View File

@@ -135,7 +135,7 @@ if (!window.isSecureContext) {
<input type="file" name="file1" id="uploadFile">
</div>
<div class="row">
<span class="label"></span>
<span class="label">Details</span>
<span id="imageProperties" class="value"></span>
</div>
<div id="uploadProgress">