Introduction

This page is part of the Lifecycle Management with Edge Impulse tutorial series. If you haven’t read the introduction yet, we recommend you to do so here. If you want to implement an Over-The-Air (OTA) model update, you’ll likely need to change the way the model is loaded into the application and how it’s stored on the device. One common approach is to store the model in a file on the device’s file system or in a dedicated memory partition, so it can be replaced without modifying the application itself. Here are general steps to follow: Store Model in File or Partition: Instead of embedding the model directly in the application code, store it in a separate file or partition on the device’s memory. This allows the model to be updated independently of the application. Modify Loading Code: Modify the application code to load the model from the file or partition instead of using the statically embedded model. Implement OTA Update Mechanism: Implement a mechanism to receive the new model wirelessly, via Wi-Fi, Bluetooth, or another wireless protocol, and store it in the file or partition. Restart or Reload Model: After the new model is stored, either restart the application or implement a mechanism to unload the old model and load the new one. Below is a conceptual example, not complete code, demonstrating the changes you might need to make:
#include <FileSystem.h>  // Include file system or similar library to read models from memory

// ... (rest of the includes and setup code)

int main() {
    // ... (rest of the initialization code)

    // Load model from file or memory partition instead of using a statically embedded model
    Model model = loadModelFromFile("/path/to/model/file");

    // Construct the signal
    signal_t signal;
    signal.total_length = 300;
    signal.get_data = &raw_feature_get_data;

    // Check if a new model is available via OTA
    if (isOTAUpdateAvailable()) {
        // Receive and store the new model in the file or memory partition
        receiveAndStoreNewModel("/path/to/model/file");

        // Optionally, restart the application or reload the model
        model = loadModelFromFile("/path/to/model/file");
    }

    // Use the loaded model for inference
    runClassifier(&model, &signal);

    // ... (rest of the application code)
}
Note that this is a simplified example and may not be directly usable in your application without modification. You’ll need to handle various details, such as error handling, ensuring the integrity and authenticity of the updated model, and dealing with the potential failure of the OTA update process. Remember, security is a crucial aspect of OTA updates. Ensure that only authorized updates are accepted, and consider using encryption and signatures to protect the update data. Also, testing is essential to ensure that the OTA mechanism works reliably and doesn’t brick the device or introduce vulnerabilities.