Get OTA progress


I successfully performed an OTA.Update via GCP.

how can I receive the progress of the OTA.

I saw in console that I receive these messages:
“mgos_ota_core.c: 506 79.37% total, bootloader.bin 512 of 23152”

I added this listener but it only works when the OTA starts:

Event.addHandler (Event.OTA_TIME_CHANGED, function (ev, evdata, arg) {
print (‘OTA:’);
}, null);

I also tried this listener but it doesn’t work:
Event.addHandler (Event.OTA_STATUS, function (ev, evdata, arg) {
print (‘OTA_STATUS:’);
}, null);

Are there other listeners?
thank you very much


There is an error in api_events.js. Event Event.SYS + 3 is MGOS_EVENT_TIME_CHANGED

You can do something like this:


let ota_base_ev = Event.baseNumber('OTA');
let ota_status_ev = ota_base_ev + 1;

Event.addHandler(ota_status_ev, function (ev, evdata, arg) {
  print('OTA Status from js: ' + OTA.evdataOtaStatusMsg(evdata));
}, null);
1 Like

Thanks, i try your solution and work fine but OTA.evdataOtaStatusMsg(evdata) return only a string and not the percentual of OTA

[Feb 14 15:14:07.159] mgos_ota_core.c:506     99.79% total, partitions_mgos.bin 512 of 3072
[Feb 14 15:14:07.167] mgos_ota_core.c:938     Update state: 300
[Feb 14 15:14:07.176] OTA Status from js: Waiting for data

That’s what the builtin mJS API provides.

You can do something more verbose in C:

#include "mgos.h"
#include "mgos_ota.h"

static void ota_status_cb(int ev, void *ev_data, void *userdata) {
  const struct mgos_ota_status *status =
      (const struct mgos_ota_status *) ev_data;
  LOG(LL_INFO, ("is_committed=%d, commit_timeout=%d, partition=%d, msg: "
                "\"%s\", progress_percent=%d%",
                status->is_committed, status->commit_timeout, status->partition,
                status->msg, status->progress_percent));
  (void) ev;
  (void) userdata;

enum mgos_app_init_result mgos_app_init(void) {
  mgos_event_add_handler(MGOS_EVENT_OTA_STATUS, ota_status_cb, NULL);

1 Like

many thanks
i try this solution