OTA works

This commit is contained in:
technyon
2022-06-14 22:50:14 +02:00
parent b39c051027
commit d64975c5ef
5 changed files with 14 additions and 8 deletions

View File

@@ -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);

2
Ota.h
View File

@@ -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;

View File

@@ -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("<FORM ACTION=method=get >");
response.concat("<h3>MQTT COnfiguration</h3>");
response.concat("<h3>MQTT Configuration</h3>");
response.concat("<table>");
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);

View File

@@ -61,6 +61,7 @@ private:
char _credUser[20] = {0};
char _credPassword[20] = {0};
bool _allowRestartToPortal = false;
uint32_t _transferredSize = 0;
String _confirmCode = "----";

View File

@@ -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);