Perform OTA Update

The following steps show you how to OTA (over-the-air) update the Ayla agent and/or host app running on your devices.

  1. Sign in to your Ayla Cloud account using the Sign In API. The API returns access_token and refresh_token.
  2. Open the Integrated Agent: ESP32 page in another dedicated tab, follow the instructions on the page to establish an ESP32 development environment, and then connect one or more devices to the Ayla Cloud.
  3. In your Docker shell, run the following command:
cd /root/esp/esp-idf-v4.1/examples/ayla_demo/.
  1. Open main/demo_ledevb.c, and set the following constants to values of your choice:
#define BUILD_PROGNAME "esp32"
#define BUILD_VERSION "1.00"
  1. Run make and make flash to update the firmware on your device.
  2. Use the Ayla API Reference to verify your device's version property value in the cloud. Example: esp32 1.00 Mar 26 2020 16:38:39
  3. Increment BUILD_VERSION in demo_ledevb.c. Example:
#define BUILD_VERSION "1.01"
  1. Run make, but do not flash the image to the device. Here is the location of the new image file:
/root/esp/esp-idf-v4.1/examples/ayla_demo/build/ayla_demo.bin
  1. In a host terminal, copy the image file from the docker container to your host computer:
$ docker cp ada16:/root/esp/esp-idf-v4.1/examples/ayla_demo/build/ayla_demo.bin .
  1. Rename the image file to indicate the version:
$ mv ayla_demo.bin esp32_101.bin
  1. In the Ayla API Reference, run the Create Image Record API to create an image record using a request data object similar to the following:
{
   "description": "esp32_101",
   "model": "ledevb",
   "version": "esp32_101"
}

Note the model and version values in the response data:

{
   ...
   "model": "ledevb",
   "version": "esp32_101",
   ...
 }

📘

Best Practices

  • Ensure that all Devices configured with a specific Device Model run compatible firmware so that there's backward compatibility.
  • Deploying an incompatible image to a device may render it inoperable.
  1. Run the Upload Image API to upload your image file, and associate it with the image record.
  2. Run the Get Image Record API to verify your work. The response data object reflects the size of the uploaded file.
{
   ...
   "file_size": 1205232,
   "in_use":false
   "model": "ledevb",
    ...
   "version": "esp32_101",
   ...
}
  1. Run the Create Filter API to target the ESP32 device(s) you want to upgrade. ICC filters provide various ways of selecting device sets. The following request data object is one example:
{
   "name": "My ESP32 Devices",
   "dsns": {
     "match": [
       "AC000W000000001",
       "AC000W000000002"
     ]
   },
   "oem_model": "ledevb"
 }

Note the value of the filter id field (e.g. 6899) in the response data object.

  1. Run the Get Filter API to verify that the filter was created.
    16. Run the Create Job API with a request data object similar to the following:
{
   "name": "Upgrade ESP32 devices to esp32_101",
   "type_id": "OTA",
   "filter_id": 6899,
   "exec_method": "ONE_TIME",
   "retries": 0
 }

Note the value of the job id field (e.g. 5416) in the response data object.

  1. Run the Get Job API to verify job information. Note status = CREATED.
    18. Run the Set OTA Action API with a request data object similar to the following to associate an OTA action with the job:
{
   "type": "host",
   "ayla_model": "ledevb",
   "version": "esp32_101"
 }
  1. Run Start Job.