backup
This commit is contained in:
@@ -32,6 +32,7 @@ file(GLOB SRCFILES
|
||||
NukiWrapper.cpp
|
||||
NukiOpenerWrapper.cpp
|
||||
MqttTopics.h
|
||||
Ota.cpp
|
||||
WebCfgServer.cpp
|
||||
PresenceDetection.cpp
|
||||
PreferencesKeys.h
|
||||
|
||||
29
Ota.cpp
Normal file
29
Ota.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <Arduino.h>
|
||||
#include "Ota.h"
|
||||
|
||||
#define FULL_PACKET 1436 // HTTP_UPLOAD_BUFLEN in WebServer,h
|
||||
|
||||
void Ota::updateFirmware(uint8_t buf, size_t size)
|
||||
{
|
||||
if (!_updateFlag)
|
||||
{ //If it's the first packet of OTA since bootup, begin OTA
|
||||
Serial.println("BeginOTA");
|
||||
esp_ota_begin(esp_ota_get_next_update_partition(NULL), OTA_SIZE_UNKNOWN, &otaHandler);
|
||||
_updateFlag = true;
|
||||
}
|
||||
esp_ota_write(otaHandler, (const void*)buf, size);
|
||||
if (size != FULL_PACKET)
|
||||
{
|
||||
esp_ota_end(otaHandler);
|
||||
Serial.println("EndOTA");
|
||||
if (ESP_OK == esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL)))
|
||||
{
|
||||
delay(2000);
|
||||
esp_restart();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Upload Error");
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Ota.h
Normal file
15
Ota.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstddef>
|
||||
#include "esp_ota_ops.h"
|
||||
|
||||
class Ota
|
||||
{
|
||||
public:
|
||||
void updateFirmware(uint8_t buf, size_t size);
|
||||
|
||||
private:
|
||||
bool _updateFlag = false;
|
||||
esp_ota_handle_t otaHandler = 0;
|
||||
};
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define nuki_hub_version "3.1"
|
||||
#define nuki_hub_version "3.2"
|
||||
@@ -662,21 +662,10 @@ void WebCfgServer::handleOtaUpload()
|
||||
filename = "/" + filename;
|
||||
}
|
||||
Serial.print("handleFileUpload Name: "); Serial.println(filename);
|
||||
// fsUploadFile = FILESYSTEM.open(filename, "w");
|
||||
filename = String();
|
||||
} else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||
//DBG_OUTPUT_PORT.print("handleFileUpload Data: "); DBG_OUTPUT_PORT.println(upload.currentSize);
|
||||
// if (fsUploadFile) {
|
||||
// fsUploadFile.write(upload.buf, upload.currentSize);
|
||||
// }
|
||||
for(int i=0; i < upload.currentSize; i++)
|
||||
{
|
||||
Serial.print((char)upload.buf[i]);
|
||||
}
|
||||
Serial.println(upload.currentSize);
|
||||
_ota.updateFirmware(*upload.buf, upload.currentSize);
|
||||
} else if (upload.status == UPLOAD_FILE_END) {
|
||||
// if (fsUploadFile) {
|
||||
// fsUploadFile.close();
|
||||
// }
|
||||
Serial.println();
|
||||
Serial.print("handleFileUpload Size: "); Serial.println(upload.totalSize);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "NukiWrapper.h"
|
||||
#include "Network.h"
|
||||
#include "NukiOpenerWrapper.h"
|
||||
#include "Ota.h"
|
||||
|
||||
enum class TokenType
|
||||
{
|
||||
@@ -54,6 +55,7 @@ private:
|
||||
NukiOpenerWrapper* _nukiOpener;
|
||||
Network* _network;
|
||||
Preferences* _preferences;
|
||||
Ota _ota;
|
||||
|
||||
bool _hasCredentials = false;
|
||||
char _credUser[20] = {0};
|
||||
|
||||
Reference in New Issue
Block a user