Giter VIP home page Giter VIP logo

ninux_esp32_ota's Introduction

ninux_esp32_ota component

how to use it

example:

EventGroupHandle_t wifi_event_group;
const int CONNECTED_BIT = BIT0;
#include "ninux_esp32_ota.h"
...
static esp_err_t event_handler(void *ctx, system_event_t *event)
{
    switch (event->event_id) {
    case SYSTEM_EVENT_STA_START:
        esp_wifi_connect();
        break;
    case SYSTEM_EVENT_STA_GOT_IP:
        xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
        break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
        /* This is a workaround as ESP32 WiFi libs don't currently
           auto-reassociate. */
        esp_wifi_connect();
        xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
        break;
    default:
        break;
    }
    return ESP_OK;
}
...   
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
    // 1.OTA app partition table has a smaller NVS partition size than the non-OTA
    // partition table. This size mismatch may cause NVS initialization to fail.
    // 2.NVS partition contains data in new format and cannot be recognized by this version of code.
    // If this happens, we erase NVS partition and initialize NVS again.
    ESP_ERROR_CHECK(nvs_flash_erase());
    err = nvs_flash_init();
}
ESP_ERROR_CHECK( err );
...
tcpip_adapter_init();
initialise_wifi();
...
//HERE a check can run
// esp_ota_mark_app_valid_cancel_rollback();
// or 
//esp_ota_mark_app_invalid_rollback_and_reboot();
// for firmware validation
...
ninux_esp32_ota();
...

in initialise_wifi usually there is this line: ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );

procedure

Generate self-signed certificate and key:

NOTE: Common Name of server certificate should be host-name of your server.

openssl req -x509 -newkey rsa:2048 -keyout ca_key.pem -out ca_cert.pem -days 365

  • openssl configuration may require you to enter a passphrase for the key.
  • When prompted for the Common Name (CN), enter the name of the server that the ESP32 will connect to. For this local example, it is probably the IP address. The HTTPS client will make sure that the CN matches the address given in the HTTPS URL (see Step 3).

Copy the certificate to server_certs directory inside OTA example directory:

cp ca_cert.pem /path/to/ota/example/server_certs/

Start the HTTPS server:

openssl s_server -WWW -key ca_key.pem -cert ca_cert.pem -port 8070

ninux_esp32_ota's People

Contributors

ninnux avatar

Stargazers

Gianpaolo Macario avatar

Watchers

Gianpaolo Macario avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.