boiler energy counter, stored in nvs

This commit is contained in:
MichaelDvP
2023-09-03 17:53:48 +02:00
parent 4c1b66279d
commit bd92345793
11 changed files with 173 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
#include <RestartService.h>
#include <esp_ota_ops.h>
#include "../../src/emsesp_stub.hpp"
using namespace std::placeholders; // for `_1` etc
RestartService::RestartService(AsyncWebServer * server, SecurityManager * securityManager) {
@@ -11,6 +13,7 @@ RestartService::RestartService(AsyncWebServer * server, SecurityManager * securi
}
void RestartService::restart(AsyncWebServerRequest * request) {
emsesp::EMSESP::system_.store_boiler_energy();
request->onDisconnect(RestartService::restartNow);
request->send(200);
}
@@ -19,6 +22,7 @@ void RestartService::partition(AsyncWebServerRequest * request) {
const esp_partition_t * factory_partition = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
if (factory_partition) {
esp_ota_set_boot_partition(factory_partition);
emsesp::EMSESP::system_.store_boiler_energy();
request->onDisconnect(RestartService::restartNow);
request->send(200);
return;
@@ -35,6 +39,7 @@ void RestartService::partition(AsyncWebServerRequest * request) {
return;
}
esp_ota_set_boot_partition(ota_partition);
emsesp::EMSESP::system_.store_boiler_energy();
request->onDisconnect(RestartService::restartNow);
request->send(200);
}

View File

@@ -1,6 +1,8 @@
#include <UploadFileService.h>
#include <esp_ota_ops.h>
#include "../../src/emsesp_stub.hpp"
using namespace std::placeholders; // for `_1` etc
static bool is_firmware = false;
@@ -112,6 +114,7 @@ void UploadFileService::uploadComplete(AsyncWebServerRequest * request) {
// did we complete uploading a json file?
if (request->_tempFile) {
request->_tempFile.close(); // close the file handle as the upload is now done
emsesp::EMSESP::system_.store_boiler_energy();
request->onDisconnect(RestartService::restartNow);
AsyncWebServerResponse * response = request->beginResponse(200);
request->send(response);
@@ -121,6 +124,7 @@ void UploadFileService::uploadComplete(AsyncWebServerRequest * request) {
// check if it was a firmware upgrade
// if no error, send the success response as a JSON
if (is_firmware && !request->_tempObject) {
emsesp::EMSESP::system_.store_boiler_energy();
request->onDisconnect(RestartService::restartNow);
AsyncWebServerResponse * response = request->beginResponse(200);
request->send(response);