feat: implement OTA updates over HTTP(S), initiated over MQTT
This commit is contained in:
@@ -5,10 +5,12 @@
|
||||
#include "esp_log.h"
|
||||
#include <string.h>
|
||||
|
||||
#define NS "anchor_cfg"
|
||||
#define KEY_PROV "provisioned"
|
||||
#define KEY_HOST "mqtt_host"
|
||||
#define KEY_PORT "mqtt_port"
|
||||
#define NS "anchor_cfg"
|
||||
#define KEY_PROV "provisioned"
|
||||
#define KEY_HOST "mqtt_host"
|
||||
#define KEY_PORT "mqtt_port"
|
||||
#define KEY_SCHEMA_VER "schema_ver"
|
||||
#define CURRENT_SCHEMA_VER 1
|
||||
|
||||
static const char *TAG = "config_store";
|
||||
|
||||
@@ -20,7 +22,22 @@ esp_err_t config_store_init(void)
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
return err;
|
||||
if (err != ESP_OK) return err;
|
||||
|
||||
nvs_handle_t h;
|
||||
err = nvs_open(NS, NVS_READWRITE, &h);
|
||||
if (err != ESP_OK) return err;
|
||||
|
||||
uint8_t schema_ver = 0;
|
||||
nvs_get_u8(h, KEY_SCHEMA_VER, &schema_ver);
|
||||
if (schema_ver < CURRENT_SCHEMA_VER) {
|
||||
/* Add migration steps here for future schema changes */
|
||||
nvs_set_u8(h, KEY_SCHEMA_VER, CURRENT_SCHEMA_VER);
|
||||
nvs_commit(h);
|
||||
ESP_LOGI(TAG, "NVS schema migrated %u -> %u", schema_ver, CURRENT_SCHEMA_VER);
|
||||
}
|
||||
nvs_close(h);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool config_store_is_provisioned(void)
|
||||
|
||||
Reference in New Issue
Block a user