add BLE bonding
Some checks failed
ESP-IDF Build / build (esp32, latest) (push) Failing after 46s
ESP-IDF Build / build (esp32, release-v5.4) (push) Failing after 46s
ESP-IDF Build / build (esp32, release-v5.5) (push) Failing after 45s
ESP-IDF Build / build (esp32c3, latest) (push) Failing after 45s
ESP-IDF Build / build (esp32c3, release-v5.4) (push) Failing after 45s
ESP-IDF Build / build (esp32c3, release-v5.5) (push) Failing after 45s
ESP-IDF Build / build (esp32c5, latest) (push) Failing after 45s
ESP-IDF Build / build (esp32c5, release-v5.4) (push) Failing after 45s
ESP-IDF Build / build (esp32c5, release-v5.5) (push) Failing after 45s
ESP-IDF Build / build (esp32c6, latest) (push) Failing after 45s
ESP-IDF Build / build (esp32c6, release-v5.4) (push) Failing after 45s
ESP-IDF Build / build (esp32c6, release-v5.5) (push) Failing after 45s
ESP-IDF Build / build (esp32h2, latest) (push) Failing after 46s
ESP-IDF Build / build (esp32h2, release-v5.4) (push) Failing after 45s
ESP-IDF Build / build (esp32h2, release-v5.5) (push) Failing after 45s
ESP-IDF Build / build (esp32p4, latest) (push) Failing after 45s
ESP-IDF Build / build (esp32p4, release-v5.4) (push) Failing after 45s
ESP-IDF Build / build (esp32p4, release-v5.5) (push) Failing after 52s
ESP-IDF Build / build (esp32s3, latest) (push) Failing after 56s
ESP-IDF Build / build (esp32s3, release-v5.4) (push) Failing after 46s
ESP-IDF Build / build (esp32s3, release-v5.5) (push) Failing after 45s
Some checks failed
ESP-IDF Build / build (esp32, latest) (push) Failing after 46s
ESP-IDF Build / build (esp32, release-v5.4) (push) Failing after 46s
ESP-IDF Build / build (esp32, release-v5.5) (push) Failing after 45s
ESP-IDF Build / build (esp32c3, latest) (push) Failing after 45s
ESP-IDF Build / build (esp32c3, release-v5.4) (push) Failing after 45s
ESP-IDF Build / build (esp32c3, release-v5.5) (push) Failing after 45s
ESP-IDF Build / build (esp32c5, latest) (push) Failing after 45s
ESP-IDF Build / build (esp32c5, release-v5.4) (push) Failing after 45s
ESP-IDF Build / build (esp32c5, release-v5.5) (push) Failing after 45s
ESP-IDF Build / build (esp32c6, latest) (push) Failing after 45s
ESP-IDF Build / build (esp32c6, release-v5.4) (push) Failing after 45s
ESP-IDF Build / build (esp32c6, release-v5.5) (push) Failing after 45s
ESP-IDF Build / build (esp32h2, latest) (push) Failing after 46s
ESP-IDF Build / build (esp32h2, release-v5.4) (push) Failing after 45s
ESP-IDF Build / build (esp32h2, release-v5.5) (push) Failing after 45s
ESP-IDF Build / build (esp32p4, latest) (push) Failing after 45s
ESP-IDF Build / build (esp32p4, release-v5.4) (push) Failing after 45s
ESP-IDF Build / build (esp32p4, release-v5.5) (push) Failing after 52s
ESP-IDF Build / build (esp32s3, latest) (push) Failing after 56s
ESP-IDF Build / build (esp32s3, release-v5.4) (push) Failing after 46s
ESP-IDF Build / build (esp32s3, release-v5.5) (push) Failing after 45s
Signed-off-by: Peter Siegmund <mars3142@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
typedef enum
|
||||
{
|
||||
VALUE_TYPE_STRING,
|
||||
VALUE_TYPE_INT8,
|
||||
VALUE_TYPE_INT32,
|
||||
} persistence_value_type_t;
|
||||
|
||||
|
@@ -10,6 +10,149 @@ static const char *TAG = "persistence";
|
||||
static nvs_handle_t persistence_handle;
|
||||
static SemaphoreHandle_t persistence_mutex;
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char *nvs_type_to_str(nvs_type_t type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case NVS_TYPE_U8:
|
||||
return "U8";
|
||||
case NVS_TYPE_I8:
|
||||
return "I8";
|
||||
case NVS_TYPE_U16:
|
||||
return "U16";
|
||||
case NVS_TYPE_I16:
|
||||
return "I16";
|
||||
case NVS_TYPE_U32:
|
||||
return "U32";
|
||||
case NVS_TYPE_I32:
|
||||
return "I32";
|
||||
case NVS_TYPE_U64:
|
||||
return "U64";
|
||||
case NVS_TYPE_I64:
|
||||
return "I64";
|
||||
case NVS_TYPE_STR:
|
||||
return "STR";
|
||||
case NVS_TYPE_BLOB:
|
||||
return "BLOB";
|
||||
case NVS_TYPE_ANY:
|
||||
return "ANY";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
void display_nvs_value(const char *namespace_name, const char *key, nvs_type_t type)
|
||||
{
|
||||
nvs_handle_t handle;
|
||||
esp_err_t err = nvs_open(namespace_name, NVS_READONLY, &handle);
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case NVS_TYPE_I8: {
|
||||
int8_t value;
|
||||
if (nvs_get_i8(handle, key, &value) == ESP_OK)
|
||||
{
|
||||
ESP_LOGI(TAG, " -> Value (I8): %d", value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NVS_TYPE_I32: {
|
||||
int32_t value;
|
||||
if (nvs_get_i32(handle, key, &value) == ESP_OK)
|
||||
{
|
||||
ESP_LOGI(TAG, " -> Value (I32): %d", value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NVS_TYPE_STR: {
|
||||
size_t length = 0;
|
||||
nvs_get_str(handle, key, NULL, &length);
|
||||
if (length > 0)
|
||||
{
|
||||
char *value = malloc(length);
|
||||
if (nvs_get_str(handle, key, value, &length) == ESP_OK)
|
||||
{
|
||||
ESP_LOGI(TAG, " -> Value (STR): %s", value);
|
||||
}
|
||||
free(value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NVS_TYPE_BLOB: {
|
||||
size_t length = 0;
|
||||
nvs_get_blob(handle, key, NULL, &length);
|
||||
if (length > 0)
|
||||
{
|
||||
ESP_LOGI(TAG, " -> Value (BLOB): %d bytes", length);
|
||||
|
||||
// Optional: Erste Bytes als Hex anzeigen
|
||||
uint8_t *blob = malloc(length);
|
||||
if (nvs_get_blob(handle, key, blob, &length) == ESP_OK)
|
||||
{
|
||||
ESP_LOG_BUFFER_HEX_LEVEL(TAG, blob, MIN(length, 32), ESP_LOG_INFO);
|
||||
}
|
||||
free(blob);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
nvs_close(handle);
|
||||
}
|
||||
|
||||
static void list_all_nvs_entries(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "========== NVS ENTRIES ==========");
|
||||
|
||||
nvs_iterator_t it = NULL;
|
||||
esp_err_t err;
|
||||
|
||||
// Iterator für alle Namespaces und Keys erstellen
|
||||
err = nvs_entry_find(NVS_DEFAULT_PART_NAME, NULL, NVS_TYPE_ANY, &it);
|
||||
|
||||
while (err == ESP_OK)
|
||||
{
|
||||
nvs_entry_info_t info;
|
||||
nvs_entry_info(it, &info);
|
||||
|
||||
ESP_LOGI(TAG, "Namespace: %-16s | Key: %-16s | Type: %s", info.namespace_name, info.key,
|
||||
nvs_type_to_str(info.type));
|
||||
|
||||
// Optional: Wert anzeigen
|
||||
display_nvs_value(info.namespace_name, info.key, info.type);
|
||||
|
||||
err = nvs_entry_next(&it);
|
||||
}
|
||||
|
||||
nvs_release_iterator(it);
|
||||
ESP_LOGI(TAG, "==================================");
|
||||
}
|
||||
|
||||
static void check_nvs_stats(void)
|
||||
{
|
||||
nvs_stats_t nvs_stats;
|
||||
esp_err_t err = nvs_get_stats(NULL, &nvs_stats);
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
ESP_LOGI(TAG, "NVS: Used entries = %d, Free entries = %d, Total entries = %d", nvs_stats.used_entries,
|
||||
nvs_stats.free_entries, nvs_stats.total_entries);
|
||||
|
||||
size_t used_kb = (nvs_stats.used_entries * 32) / 1024; // Grobe Schätzung
|
||||
size_t free_kb = (nvs_stats.free_entries * 32) / 1024;
|
||||
ESP_LOGI(TAG, "NVS: ~%d KB used, ~%d KB free", used_kb, free_kb);
|
||||
}
|
||||
}
|
||||
|
||||
void persistence_init(const char *namespace_name)
|
||||
{
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
@@ -20,6 +163,9 @@ void persistence_init(const char *namespace_name)
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
list_all_nvs_entries();
|
||||
check_nvs_stats();
|
||||
|
||||
ESP_ERROR_CHECK(nvs_open(namespace_name, NVS_READWRITE, &persistence_handle));
|
||||
|
||||
persistence_mutex = xSemaphoreCreateMutex();
|
||||
@@ -43,6 +189,10 @@ void persistence_save(persistence_value_type_t value_type, const char *key, cons
|
||||
err = nvs_set_str(persistence_handle, key, (char *)value);
|
||||
break;
|
||||
|
||||
case VALUE_TYPE_INT8:
|
||||
err = nvs_set_i8(persistence_handle, key, *(int8_t *)value);
|
||||
break;
|
||||
|
||||
case VALUE_TYPE_INT32:
|
||||
err = nvs_set_i32(persistence_handle, key, *(int32_t *)value);
|
||||
break;
|
||||
@@ -80,6 +230,10 @@ void *persistence_load(persistence_value_type_t value_type, const char *key, voi
|
||||
err = nvs_get_str(persistence_handle, key, (char *)out, NULL);
|
||||
break;
|
||||
|
||||
case VALUE_TYPE_INT8:
|
||||
err = nvs_get_i8(persistence_handle, key, (int8_t *)out);
|
||||
break;
|
||||
|
||||
case VALUE_TYPE_INT32:
|
||||
err = nvs_get_i32(persistence_handle, key, (int32_t *)out);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user