lexus2k / esp_ota_upgrade

Improved ESP OTA Upgrade component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ESP OTA enhanced upgrade

Improved ESP OTA Upgrade component

How to use

How to add FW upgrade function to your web-server on the IoT device

image

static void on_upgrade_start(void)
{
    // Here you can do anything before upgrade process is started
}

static void on_upgrade_end(bool success)
{
    if ( success )
    {
    }
    else
    {
    }
}

static bool before_upgrade_check(httpd_req_t *req)
{
    // Do, whatever you need to do to make sure that sender is allowed to upgrade IoT device
    uint8_t authenticated = validate_session(req, "POST"); // This is an example function
    if ( !authenticated)
    {
        // Do, whatever you want to do in case Upgrade is cancelled
        redirect_to_login_page(req, false);
        return false;
    }
    return true;
}


...
    // Registers /fwupdate URI
    register_httpd_ota_handler(server, before_upgrade_check, on_upgrade_start, on_upgrade_end );
...

Initiate self-upgrade by the device itself

static void on_upgrade_start(void)
{
    // Here you can do anything before upgrade process is started
}

static void on_upgrade_end(bool success)
{
    if ( success )
    {
    }
    else
    {
    }
}

bool on_validate_version(const char * new_ver)
{
    // Validate here the version
    return true;
}

...
    http_client_ota_upgrade( "https://path/to/version/file.txt", // Can be NULL if you don't have version file with the name
                             "https://path/to/new/firmware.bin",
                              on_validate_version,
                              on_upgrade_start,
                              on_upgrade_end );
...

About

Improved ESP OTA Upgrade component

License:MIT License


Languages

Language:CSS 50.3%Language:C 38.1%Language:HTML 11.0%Language:CMake 0.5%Language:Makefile 0.2%