From d64975c5ef51dfe8d7dc8d858c07620101dcdbb2 Mon Sep 17 00:00:00 2001 From: technyon Date: Tue, 14 Jun 2022 22:50:14 +0200 Subject: [PATCH] OTA works --- Ota.cpp | 4 ++-- Ota.h | 2 +- WebCfgServer.cpp | 13 +++++++++---- WebCfgServer.h | 1 + main.cpp | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Ota.cpp b/Ota.cpp index cb3a925..7948266 100644 --- a/Ota.cpp +++ b/Ota.cpp @@ -3,7 +3,7 @@ #define FULL_PACKET 1436 // HTTP_UPLOAD_BUFLEN in WebServer,h -void Ota::updateFirmware(uint8_t buf, size_t size) +void Ota::updateFirmware(uint8_t* buf, size_t size) { if (!_updateFlag) { //If it's the first packet of OTA since bootup, begin OTA @@ -11,7 +11,7 @@ void Ota::updateFirmware(uint8_t buf, size_t size) esp_ota_begin(esp_ota_get_next_update_partition(NULL), OTA_SIZE_UNKNOWN, &otaHandler); _updateFlag = true; } - esp_ota_write(otaHandler, (const void*)buf, size); + esp_ota_write(otaHandler, buf, size); if (size != FULL_PACKET) { esp_ota_end(otaHandler); diff --git a/Ota.h b/Ota.h index 4b3a38f..967c1d5 100644 --- a/Ota.h +++ b/Ota.h @@ -7,7 +7,7 @@ class Ota { public: - void updateFirmware(uint8_t buf, size_t size); + void updateFirmware(uint8_t* buf, size_t size); private: bool _updateFlag = false; diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index 1a9a235..9cbb08e 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -125,7 +125,8 @@ void WebCfgServer::initialize() return _server.requestAuthentication(); } - String response = "ok"; + String response = ""; + buildConfirmHtml(response, "Initiating Over-the-air Update. This will take a moment, please be patient.", 35); _server.send(200, "text/html", response); }, [&]() { @@ -463,7 +464,7 @@ void WebCfgServer::buildOtaHtml(String &response) void WebCfgServer::buildMqttConfigHtml(String &response) { response.concat("
"); - response.concat("

MQTT COnfiguration

"); + response.concat("

MQTT Configuration

"); response.concat(""); printInputField(response, "HOSTNAME", "Host name", _preferences->getString(preference_hostname).c_str(), 100); printInputField(response, "MQTTSERVER", "MQTT Broker", _preferences->getString(preference_mqtt_broker).c_str(), 100); @@ -655,6 +656,9 @@ void WebCfgServer::handleOtaUpload() if (_server.uri() != "/uploadota") { return; } + + esp_task_wdt_init(30, false); + HTTPUpload& upload = _server.upload(); if (upload.status == UPLOAD_FILE_START) { String filename = upload.filename; @@ -663,8 +667,9 @@ void WebCfgServer::handleOtaUpload() } Serial.print("handleFileUpload Name: "); Serial.println(filename); } else if (upload.status == UPLOAD_FILE_WRITE) { - Serial.println(upload.currentSize); - _ota.updateFirmware(*upload.buf, upload.currentSize); + _transferredSize = _transferredSize + upload.currentSize; + Serial.println(_transferredSize); + _ota.updateFirmware(upload.buf, upload.currentSize); } else if (upload.status == UPLOAD_FILE_END) { Serial.println(); Serial.print("handleFileUpload Size: "); Serial.println(upload.totalSize); diff --git a/WebCfgServer.h b/WebCfgServer.h index 4bba569..c55f0e8 100644 --- a/WebCfgServer.h +++ b/WebCfgServer.h @@ -61,6 +61,7 @@ private: char _credUser[20] = {0}; char _credPassword[20] = {0}; bool _allowRestartToPortal = false; + uint32_t _transferredSize = 0; String _confirmCode = "----"; diff --git a/main.cpp b/main.cpp index d346620..94d1cfd 100644 --- a/main.cpp +++ b/main.cpp @@ -89,7 +89,7 @@ void setupTasks() { // configMAX_PRIORITIES is 25 - xTaskCreate(networkTask, "ntw", 8192, NULL, 3, NULL); + xTaskCreatePinnedToCore(networkTask, "ntw", 8192, NULL, 3, NULL, 1); xTaskCreate(nukiTask, "nuki", 4096, NULL, 2, NULL); xTaskCreate(presenceDetectionTask, "prdet", 768, NULL, 5, NULL); xTaskCreate(checkMillisTask, "mlchk", 512, NULL, 1, NULL);