Skip to content

Commit

Permalink
Fix sensor ota update percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis960 committed Sep 11, 2024
1 parent bd78ed4 commit 83ed0eb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
16 changes: 7 additions & 9 deletions Firmware/frontend/src/pages/update-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ export class UpdatePage extends BasePage {
this.firmwareUpdateProgress = 0;
while (this.firmwareUpdateProgress !== null) {
this.firmwareUpdateProgress = await getUpdatePercentage();
if (
this.firmwareUpdateProgress === 100 ||
this.firmwareUpdateProgress === -1
) {
if (this.firmwareUpdateProgress === -1) {
this.infoText = "Es wurde noch kein Update gestartet";
} else if (this.firmwareUpdateProgress === 100) {
this.infoText = "Der Sensor wurde erfolgreich aktualisiert";
this.firmwareUpdateProgress = null;
return;
}
if (this.firmwareUpdateProgress < 100) {
} else if (this.firmwareUpdateProgress < 100) {
await new Promise((resolve) => setTimeout(resolve, 200));
}
if (this.firmwareUpdateProgress > 80) {
this.infoText = "Der Sensor wird jetzt neu gestartet";
if (this.firmwareUpdateProgress > 80) {
this.infoText = "Der Sensor wird jetzt neu gestartet";
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion Firmware/main/configuration_mode_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ esp_err_t post_api_update_firmware_handler(httpd_req_t *req)
}

plantstore_setFirmwareUpdateUrl(url);
ota_update_percentage = 0;

const char resp[] = "OK";
httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN);
Expand Down Expand Up @@ -893,7 +894,7 @@ void register_uri_handlers(httpd_handle_t server)
httpd_register_uri_handler(server, &get);
}

httpd_handle_t start_webserver(void)
httpd_handle_t start_webserver(bool resetReasonOta)
{
ESP_LOGI("HTTP", "Starting HTTP server");
/* Empty handle to esp_http_server */
Expand All @@ -904,6 +905,12 @@ httpd_handle_t start_webserver(void)
config.uri_match_fn = httpd_uri_match_wildcard;
config.max_uri_handlers = 50;

if (resetReasonOta)
{
ESP_LOGI("OTA", "Reset reason is OTA, so OTA finished successfully");
ota_update_percentage = 100;
}

/* Start the httpd server */
ESP_ERROR_CHECK(httpd_start(&server, &config));
register_uri_handlers(server);
Expand Down
2 changes: 1 addition & 1 deletion Firmware/main/configuration_mode_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
#include "esp_http_server.h"

/* Function for starting the webserver */
httpd_handle_t start_webserver(void);
httpd_handle_t start_webserver(bool resetReasonOta);
/* Function for stopping the webserver */
void stop_webserver(httpd_handle_t server);
6 changes: 3 additions & 3 deletions Firmware/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void start_deep_sleep()
esp_deep_sleep(sleepTime);
}

void configuration_mode(bool isConfigured)
void configuration_mode(bool isConfigured, bool resetReasonOta)
{
sensors_playStartupSound();
plantfi_setEnableNatAndDnsOnConnect(true);
Expand All @@ -39,7 +39,7 @@ void configuration_mode(bool isConfigured)
plantfi_configureAp("Blumy", "", 4, &userConnectedToAp);

ESP_LOGI("MODE", "Starting webserver");
httpd_handle_t webserver = start_webserver();
httpd_handle_t webserver = start_webserver(resetReasonOta);
plantfi_configureStaFromPlantstore();

bool wasBootButtonPressed = false;
Expand Down Expand Up @@ -135,7 +135,7 @@ void app_main()

if (isManualReset || !isConfigured)
{
configuration_mode(isConfigured);
configuration_mode(isConfigured, resetReasonOta);
}
else
{
Expand Down

0 comments on commit 83ed0eb

Please sign in to comment.