优化了NVS使用,改为/platform_storage.c统一处理
This commit is contained in:
@@ -11,9 +11,11 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
#include "platform.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "ssid_manager.h"
|
||||
#include "wifi_manager.h"
|
||||
#include "wifi_storage_hooks.h"
|
||||
|
||||
static const char *TAG = "wifi_portal";
|
||||
|
||||
@@ -40,8 +42,29 @@ static wifi_portal_behavior_hooks_t s_behavior_hooks = {};
|
||||
|
||||
static esp_err_t apply_sta_stability_policy(void);
|
||||
|
||||
static void install_wifi_storage_hooks(void)
|
||||
{
|
||||
static bool s_installed;
|
||||
if (s_installed) {
|
||||
return;
|
||||
}
|
||||
|
||||
const wifi_storage_hooks_t hooks = {
|
||||
.set_string = platform_storage_set_string,
|
||||
.get_string = platform_storage_get_string,
|
||||
.set_u8 = platform_storage_set_u8,
|
||||
.get_u8 = platform_storage_get_u8,
|
||||
.set_i8 = platform_storage_set_i8,
|
||||
.get_i8 = platform_storage_get_i8,
|
||||
.erase = platform_storage_erase,
|
||||
};
|
||||
wifi_storage_set_hooks(&hooks);
|
||||
s_installed = true;
|
||||
}
|
||||
|
||||
static void log_saved_wifi_candidates(const char *context)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
const auto &ssid_list = SsidManager::GetInstance().GetSsidList();
|
||||
ESP_LOGI(TAG,
|
||||
"%s: %u saved Wi-Fi credential candidate(s)",
|
||||
@@ -141,6 +164,7 @@ static void wifi_manager_event_callback(WifiEvent event, const std::string &data
|
||||
|
||||
static esp_err_t ensure_wifi_manager_initialized(void)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
if (s_wifi_manager_initialized) {
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -162,6 +186,7 @@ static esp_err_t ensure_wifi_manager_initialized(void)
|
||||
|
||||
static void seed_default_credentials(const char *ssid, const char *password)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
auto &manager = SsidManager::GetInstance();
|
||||
const auto saved_count = manager.GetSsidList().size();
|
||||
|
||||
@@ -227,6 +252,7 @@ esp_err_t wifi_portal_init_defaults(const char *seed_ssid, const char *seed_pass
|
||||
|
||||
bool wifi_portal_has_saved_credentials(void)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
return !SsidManager::GetInstance().GetSsidList().empty();
|
||||
}
|
||||
|
||||
@@ -295,6 +321,7 @@ esp_err_t wifi_portal_connect_sta(int timeout_ms)
|
||||
|
||||
esp_err_t wifi_portal_save_credentials(const char *ssid, const char *password)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
ESP_RETURN_ON_ERROR(wifi_portal_lock(), TAG, "Failed to lock Wi-Fi portal");
|
||||
PortalUnlockGuard guard;
|
||||
|
||||
@@ -315,6 +342,7 @@ esp_err_t wifi_portal_save_credentials(const char *ssid, const char *password)
|
||||
|
||||
esp_err_t wifi_portal_clear_saved_credentials(void)
|
||||
{
|
||||
install_wifi_storage_hooks();
|
||||
ESP_RETURN_ON_ERROR(wifi_portal_lock(), TAG, "Failed to lock Wi-Fi portal");
|
||||
PortalUnlockGuard guard;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user