In this tutorial, we'll guide you through deploying updated impulses over-the-air (OTA) to Arduino using Edge Impulse. We'll build on Arduino firmware update workflow, incorporating Edge Impulse's API to check for updates and download the latest build.
Let's get started!
Prerequisites:
Edge Impulse Account: If you haven't got one, sign up here.
Installation of required software as detailed in the tutorial
Preparation
Begin by setting up your device for OTA updates following Espressif's OTA firmware update workflow. Use the built binary from the C++ example and modify it to incorporate OTA functionality.
Steps to Deploy Impulse to ESP32
1. Copy the ESP OTA example and configure your wifi settings
Clone the example repository and adjust it according to your project and connectivity settings.
Modify the ESP OTA example server to check for updates to your project
import requestsimport jsonimport osAPI_KEY ='your-edge-impulse-api-key'PROJECT_ID ='your-project-id'MODEL_PATH ='path_to_your_local_model'defget_last_modification_date(): url =f'https://studio.edgeimpulse.com/v1/api/{PROJECT_ID}/last-modification-date' headers ={'x-api-key': API_KEY} response = requests.get(url, headers=headers)if response.status_code ==200: data = response.json()return data['lastModificationDate']else:print(f"Failed to get last modification date: {response.text}")returnNonedefdownload_model(): url =f'https://studio.edgeimpulse.com/v1/api/{PROJECT_ID}/deployment/download' headers ={'x-api-key': API_KEY} response = requests.get(url, headers=headers)if response.status_code ==200:withopen(MODEL_PATH, 'wb')as file: file.write(response.content)print("Model downloaded successfully.")else:print(f"Failed to download the model: {response.text}")# get the stored timestamp or hashstored_timestamp =None# replace this with logic to get the stored timestamp or hash# check for recent modificationslast_modification_date =get_last_modification_date()# compare and download if newerif last_modification_date and last_modification_date != stored_timestamp:print("New model available. Downloading...")download_model()# update the stored timestamp or hash stored_timestamp = last_modification_date# restart the device os.system('sudo reboot')
2. Modify the ESP OTA example to check for updates to your project
Modify the Edge Impulse C++ example for ESP32 to check for updates to your project and download the latest build.
We will need to add a few libraries to the project to facilitate the OTA update process. These are taken from the ESP32 OTA example and are already included in the example project.
Components
1. Non-Volatile Storage (NVS)
#include"nvs.h"#include"nvs_flash.h"
NVS is utilized to persistently store data like configuration settings, WiFi credentials, or firmware update times, ensuring retention across reboots.
2. HTTP Client
#include"esp_http_client.h"
This library facilitates HTTP requests to the server for checking and retrieving new firmware updates.
3. OTA Operations
#include"esp_ota_ops.h"#include"esp_https_ota.h"
These headers aid in executing OTA operations, including writing new firmware to the flash and switching boot partitions.
FreeRTOS ensures OTA updates are conducted in a separate task, preventing blockage of other tasks and maintaining system operations during the update.
3. Updating the Device
Compare the model's timestamp or hash with the stored version. If it's different or newer, call the download_model() function.
4. Monitoring and Repeating the Process
Monitor the device to ensure the new impulse performs as expected and repeat the update process as needed.
Conclusion
This tutorial provides a comprehensive guide for implementing OTA updates on Espressif ESP-EYE (ESP32) with Edge Impulse. Follow each step meticulously, ensuring all prerequisites and preparation steps are completed before proceeding to the deployment phase. Happy coding!
Note: Adjust the code snippets and steps to suit your specific requirements and always ensure to test thoroughly before deploying updates to live environments.