Question on OTA callback (ota_cb_func)

ytan86
Posts: 9
Joined: Thu Aug 15, 2019 3:02 am

Question on OTA callback (ota_cb_func)

Postby ytan86 » Sun Aug 16, 2020 11:03 am

Hi,

I'm trying to add callback to the OTA function in the switch example:
  1.    
  2. /* Enable OTA */
  3.     esp_rmaker_ota_config_t ota_config = {
  4.         .ota_cb = &ota_cb_func,
  5.         .server_cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT,
  6.     };

And my callback function:
  1. esp_err_t ota_cb_func(esp_rmaker_ota_handle_t handle, esp_rmaker_ota_data_t *ota_data)
  2. {
  3.     ota_status_t status = OTA_STATUS_IN_PROGRESS;
  4.     char info[1024]="test";
  5.    
  6.     ESP_LOGW(TAG, "OTA URL: %s\r\n", ota_data->url);
  7.     ESP_LOGW(TAG, "OTA Filesize: %d\r\n", ota_data->filesize);
  8.     ESP_LOGW(TAG, "OTA Status: %d\r\n", status);
  9.  
  10.     esp_err_t err = esp_rmaker_ota_report_status(handle, status, info); // reports to OTA server
  11.  
  12.     return err;
  13. }

Admittedly, there is very little information documented. I'm really just stabbing in the dark.

When I tried to update OTA, clearly it wouldn't work:
  1. I (5314) app_wifi: Connected with IP Address:192.168.43.42
  2. I (5314) esp_netif_handlers: sta ip: 192.168.43.42, mask: 255.255.255.0, gw: 192.168.43.70
  3. I (5314) esp_rmaker_mqtt: Connecting to a1p72mufdu6064-ats.iot.us-east-1.amazonaws.com
  4. I (5324) esp_rmaker_mqtt: Waiting for MQTT connection. This may take time.
  5. I (10204) esp_rmaker_mqtt: MQTT Connected
  6. I (10204) esp_rmaker_node_config: Reporting Node Configuration
  7. I (10214) esp_rmaker_param: Reporting params: {"Switch":{"name":"Switch","power":true},"ota":{"status":"","info":"","url":""}}
  8. I (75124) esp_rmaker_param: Received params: {"ota": {"url": "https://esp-rainmaker-ota-315787942180-prod.s3.amazonaws.com/users/c92eda40-6e1d-4762-8f70-a23bc0eb3d5c/firmwareimages/Oba-4qSGR/c%3A%5Cmsys32%5Chome%5Cy.tan%5Cesp%5Cesp-rainmaker%5Ccli%5C..%5Cexamples%5Cswitch%5Cswitch_ota.bin?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAUTBTNTESLTL6K3EK%2F20200816%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200816T105153Z&X-Amz-Expires=86400&X-Amz-Security-Token=FwoGZXIvYXdzEAwaDHzxdypQ84o7NS1gfyK3Afi%2BWy8BFmPXnW%2BHwQyLffp2qHQITsMnT%2BVtWdzTXOr6UC8sh3k64Dcxc3dBBv3i%2Fq%2FNT7tr8QxjxLzh%2FFQzxnOh1AQij7XBH0Var7Qio9iPSnpofvBupA1TnNRoJ9LRrFUqhHHKIsc7G6Z8zvpSMPxFPNz0bOFiu6i8dbqi2Pxkx7ipqt1l7jrdWAGbxB0gUM%2BIa2%2F7Ac4xHt9wt4fvfFmlCCzFoDlSAVmOTs%2FOBCUH5B%2FQa92DWyjJn%2BT5BTIt7%2Fh%2BBsFyt4x%2FkHJJIwlmq21hSkjne7JS%2Fb5T09QiL7ZwI8x5HAGPkCKsUaMI&X-Amz-SignedHeaders=host&X-Amz-Signature=1d5e54dd6b9877cbf11dc75aa64a0c8b8705ba6bbbf8dab00f153522253a60d9"}}
  9. I (75204) esp_rmaker_ota_using_params: Received value = https://esp-rainmaker-ota-315787942180-prod.s3.amazonaws.com/users/c92eda40-6e1d-4762-8f70-a23bc0eb3d5c/firmwareimages/Oba-4qSGR/c%3A%5Cmsys32%5Chome%5Cy.tan%5Cesp%5Cesp-rainmaker%5Ccli%5C..%5Cexamples%5Cswitch%5Cswitch_ota.bin?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAUTBTNTESLTL6K3EK%2F20200816%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200816T105153Z&X-Amz-Expires=86400&X-Amz-Security-Token=FwoGZXIvYXdzEAwaDHzxdypQ84o7NS1gfyK3Afi%2BWy8BFmPXnW%2BHwQyLffp2qHQITsMnT%2BVtWdzTXOr6UC8sh3k64Dcxc3dBBv3i%2Fq%2FNT7tr8QxjxLzh%2FFQzxnOh1AQij7XBH0Var7Qio9iPSnpofvBupA1TnNRoJ9LRrFUqhHHKIsc7G6Z8zvpSMPxFPNz0bOFiu6i8dbqi2Pxkx7ipqt1l7jrdWAGbxB0gUM%2BIa2%2F7Ac4xHt9wt4fvfFmlCCzFoDlSAVmOTs%2FOBCUH5B%2FQa92DWyjJn%2BT5BTIt7%2Fh%2BBsFyt4x%2FkHJJIwlmq21hSkjne7JS%2Fb5T09QiL7ZwI8x5HAGPkCKsUaMI&X-Amz-SignedHeaders=host&X-Amz-Signature=1d5e54dd6b9877cbf11dc75aa64a0c8b8705ba6bbbf8dab00f153522253a60d9 for ota - url
  10. W (76224) app_main: OTA URL: https://esp-rainmaker-ota-315787942180-prod.s3.amazonaws.com/users/c92eda40-6e1d-4762-8f70-a23bc0eb3d5c/firmwareimages/Oba-4qSGR/c%3A%5Cmsys32%5Chome%5Cy.tan%5Cesp%5Cesp-rainmaker%5Ccli%5C..%5Cexamples%5Cswitch%5Cswitch_ota.bin?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAUTBTNTESLTL6K3EK%2F20200816%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200816T105153Z&X-Amz-Expires=86400&X-Amz-Security-Token=FwoGZXIvYXdzEAwaDHzxdypQ84o7NS1gfyK3Afi%2BWy8BFmPXnW%2BHwQyLffp2qHQITsMnT%2BVtWdzTXOr6UC8sh3k64Dcxc3dBBv3i%2Fq%2FNT7tr8QxjxLzh%2FFQzxnOh1AQij7XBH0Var7Qio9iPSnpofvBupA1TnNRoJ9LRrFUqhHHKIsc7G6Z8zvpSMPxFPNz0bOFiu6i8dbqi2Pxkx7ipqt1l7jrdWAGbxB0gUM%2BIa2%2F7Ac4xHt9wt4fvfFmlCCzFoDlSAVmOTs%2FOBCUH5B%2FQa92DWyjJn%2BT5BTIt7%2Fh%2BBsFyt4x%2FkHJJIwlmq21hSkjne7JS%2Fb5T09QiL7ZwI8x5HAGPkCKsUaMI&X-Amz-SignedHeaders=host&X-Amz-Signature=1d5e54dd6b9877cbf11dc75aa64a0c8b8705ba6bbbf8dab00f153522253a60d9
  11.  
  12. W (76294) app_main: OTA Filesize: 0
  13.  
  14. W (76294) app_main: OTA Status: 1
  15.  
  16. I (76304) esp_rmaker_param: Reporting params: {"ota":{"info":"test"}}
  17. I (76314) esp_rmaker_param: Reporting params: {"ota":{"status":"in-progress"}}
Is there an example callback implementation, or some additional documentation? I'd appreciate it if you can point me to the relevant information.

ESP_Piyush
Posts: 310
Joined: Wed Feb 20, 2019 7:02 am

Re: Question on OTA callback (ota_cb_func)

Postby ESP_Piyush » Mon Aug 17, 2020 7:29 am

Hello,

As per the documentation of esp_rmaker_ota_config_t, the callback can be left NULL if you want to use the default. The default callback can be found here. If you want to use your own callback, here is simpler example:
  1. esp_rmaker_ota_cb(esp_rmaker_ota_handle_t ota_handle, esp_rmaker_ota_data_t *ota_data)
  2. {
  3.     esp_rmaker_ota_report_status(ota_handle, OTA_STATUS_IN_PROGRESS, "Starting OTA Upgrade");
  4.     esp_http_client_config_t config = {
  5.         .url = ota_data->url,
  6.         .cert_pem = ota_data->server_cert
  7.         .buffer_size = 1024,
  8.         .buffer_size_tx = 1024
  9.     };
  10.     esp_err_t ret = esp_https_ota(&config);
  11.     if (ret == ESP_OK) {
  12.         esp_rmaker_ota_report_status(ota_handle, OTA_STATUS_SUCCESS, "OTA Upgrade finished successfully");
  13.         esp_rmaker_reboot(10);
  14.         return ESP_OK;
  15.     } else {
  16.         esp_rmaker_ota_report_status(ota_handle, OTA_STATUS_FAILED, "OTA Upgrade failed");
  17.     }
  18.     return ESP_FAIL;
  19. }
Regards,
Piyush

ytan86
Posts: 9
Joined: Thu Aug 15, 2019 3:02 am

Re: Question on OTA callback (ota_cb_func)

Postby ytan86 » Thu Aug 20, 2020 9:33 am

Thanks, your simplified exampled worked!

Who is online

Users browsing this forum: No registered users and 31 guests