Skip to content
Snippets Groups Projects
Commit 751093da authored by fxk8y's avatar fxk8y :spider:
Browse files

publish ota progress

parent 48d39c9c
No related branches found
No related tags found
1 merge request!1Feature/mqtt ota
......@@ -17,5 +17,6 @@
#define FIRMWARE_COMMAND_TOPIC DEVICE_NAMESPACE "command"
#define OTA_FIRMWARE_TOPIC DEVICE_NAMESPACE "ota/$firmware"
#define OTA_PROGRESS_TOPIC DEVICE_NAMESPACE "ota/progress"
#endif
\ No newline at end of file
#include "mqtt_ota.h"
#include "mqtt_common.h"
#include "esp_log.h"
#include "esp_system.h"
......@@ -63,14 +64,23 @@ void handle_ota_message(const multipart_message_t& message) {
}
int8_t last_pct = -1;
char pct_buffer[4];
void default_ota_event(ota_event_t event) {
switch(event.state) {
case start:
ESP_LOGI(TAG, "OTA Start");
last_pct = -1;
break;
case progress: {
float pct = ((float)event.bytes_written / (float)event.bytes_total) * 100;
ESP_LOGI(TAG, "OTA Progress %d%% (%d/%d KiB)", (int)pct, event.bytes_written / 1024, event.bytes_total / 1024);
int8_t pct = (int8_t)(((float)event.bytes_written / (float)event.bytes_total) * 100);
if (pct > last_pct) {
ESP_LOGI(TAG, "OTA Progress %d%% (%d/%d KiB)", pct, event.bytes_written / 1024, event.bytes_total / 1024);
snprintf(pct_buffer, sizeof(pct_buffer), "%d", pct);
publish_message(OTA_PROGRESS_TOPIC, pct_buffer);
last_pct = pct;
}
break;
}
case success:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment