diff --git a/.gitignore b/.gitignore index d974be8..63bd0d8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,10 @@ build/ tmp/ .history/ sdkconfig.old +sdkconfig .idea/ dependencies.lock +package-lock.json **/priv_note.md _priv_tools/ project_components/wifi_manager/wifi_configuration.h diff --git a/project_components/html/index.html.gz b/project_components/html/index.html.gz index f2ba79e..da98595 100644 Binary files a/project_components/html/index.html.gz and b/project_components/html/index.html.gz differ diff --git a/project_components/html/ws.sharedworker.js.gz b/project_components/html/ws.sharedworker.js.gz index c53f1ab..7a352ed 100644 Binary files a/project_components/html/ws.sharedworker.js.gz and b/project_components/html/ws.sharedworker.js.gz differ diff --git a/project_components/wifi_manager/wifi_event_handler.c b/project_components/wifi_manager/wifi_event_handler.c index 61f3494..1ec152a 100644 --- a/project_components/wifi_manager/wifi_event_handler.c +++ b/project_components/wifi_manager/wifi_event_handler.c @@ -9,6 +9,8 @@ #define TAG __FILE_NAME__ +void event_on_connected(ip_event_got_ip_t *event); + void ip_event_handler(void *handler_arg __attribute__((unused)), esp_event_base_t event_base __attribute__((unused)), int32_t event_id, @@ -19,6 +21,7 @@ void ip_event_handler(void *handler_arg __attribute__((unused)), ip_event_got_ip_t *event = event_data; printf("STA GOT IP : %s\n", ip4addr_ntoa((const ip4_addr_t *) &event->ip_info.ip)); + event_on_connected(event); break; } case IP_EVENT_STA_LOST_IP: @@ -130,8 +133,6 @@ int wifi_event_trigger_scan(uint8_t channel, wifi_event_scan_done_cb cb, uint16_ static void reconnect_after_disco(); -void event_on_connected(wifi_event_sta_connected_t *event); - void wifi_event_handler(void *handler_arg __attribute__((unused)), esp_event_base_t event_base __attribute__((unused)), int32_t event_id, @@ -163,7 +164,6 @@ void wifi_event_handler(void *handler_arg __attribute__((unused)), tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_STA); #endif event_ctx.is_connected = 1; - event_on_connected(event); break; } case WIFI_EVENT_STA_DISCONNECTED: { @@ -219,7 +219,7 @@ int wifi_event_trigger_connect(uint8_t attempt, wifi_event_connect_done_cb cb, v return err; } -void event_on_connected(wifi_event_sta_connected_t *event) +void event_on_connected(ip_event_got_ip_t *event) { if (event_ctx.conn.cb) { event_ctx.conn.cb(event_ctx.conn.arg, event); diff --git a/project_components/wifi_manager/wifi_event_handler.h b/project_components/wifi_manager/wifi_event_handler.h index c9aa1fd..52f0a23 100644 --- a/project_components/wifi_manager/wifi_event_handler.h +++ b/project_components/wifi_manager/wifi_event_handler.h @@ -4,6 +4,7 @@ #include #include #include +#include void ip_event_handler(void *handler_arg, esp_event_base_t event_base, int32_t event_id, void *event_data); @@ -18,7 +19,7 @@ void wifi_event_set_disco_handler(void (*disconn_handler)(void)); * @brief * @param connect_status 0: SUCCESS, OTHER: ERROR */ -typedef void (*wifi_event_connect_done_cb)(void *arg, wifi_event_sta_connected_t *event); +typedef void (*wifi_event_connect_done_cb)(void *arg, ip_event_got_ip_t *event); int wifi_event_trigger_connect(uint8_t attempt, wifi_event_connect_done_cb cb, void *arg); diff --git a/project_components/wifi_manager/wifi_manager.c b/project_components/wifi_manager/wifi_manager.c index 14b282b..bbeaa1a 100644 --- a/project_components/wifi_manager/wifi_manager.c +++ b/project_components/wifi_manager/wifi_manager.c @@ -30,7 +30,7 @@ typedef struct wifi_ctx_t { uint8_t max_ap; } scan; struct { - wifi_event_sta_connected_t *event; + ip_event_got_ip_t *event; uint8_t need_unlock; /* used when trigger connection from wifi_manager instead of wifi_api */ } conn; }; @@ -84,6 +84,7 @@ void wifi_manager_init(void) } if (set_default_sta_cred() == 0) { + ESP_LOGI(TAG, "STA connect to saved cred"); do_connect = 1; ctx.do_fast_connect = 1; } @@ -214,7 +215,7 @@ void *wifi_manager_get_sta_netif() } -static void try_connect_done(void *arg, wifi_event_sta_connected_t *event) +static void try_connect_done(void *arg, ip_event_got_ip_t *event) { ctx.conn.event = event; if (ctx.task) { diff --git a/project_components/wifi_manager/wifi_storage.c b/project_components/wifi_manager/wifi_storage.c index 2cfd0b3..c6136b9 100644 --- a/project_components/wifi_manager/wifi_storage.c +++ b/project_components/wifi_manager/wifi_storage.c @@ -4,7 +4,7 @@ #include -#define NVS_NAMESPACE "wifi" +#define NVS_NAMESPACE "wt_wifi" int wifi_data_get_last_conn_cred(wifi_credential_t *ap_credential) { @@ -67,7 +67,7 @@ int wifi_save_ap_credential(wifi_credential_t *ap_credential) } } - err |= wt_nvs_set(handle, KEY_WIFI_STA_LAST_AP_CRED, ap_credential, sizeof(wifi_credential_t)); + err = wt_nvs_set(handle, KEY_WIFI_STA_LAST_AP_CRED, ap_credential, sizeof(wifi_credential_t)); if (err) { return err; } diff --git a/project_components/wt_storage/wt_nvs.c b/project_components/wt_storage/wt_nvs.c index ac344ab..26fdc4b 100644 --- a/project_components/wt_storage/wt_nvs.c +++ b/project_components/wt_storage/wt_nvs.c @@ -2,6 +2,8 @@ #include +#define WT_PARTITION_NAME "wt_nvs" + void wt_nvs_init() { // Initialize default NVS @@ -13,11 +15,20 @@ void wt_nvs_init() err = nvs_flash_init(); } ESP_ERROR_CHECK(err); + + err = nvs_flash_init_partition(WT_PARTITION_NAME); + if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { + // NVS partition was truncated and needs to be erased + // Retry nvs_flash_init + ESP_ERROR_CHECK(nvs_flash_erase()); + err = nvs_flash_init_partition(WT_PARTITION_NAME); + } + ESP_ERROR_CHECK(err); } int wt_nvs_open(const char* namespace, nvs_handle_t *out_handle) { - return nvs_open(namespace, NVS_READWRITE, out_handle); + return nvs_open_from_partition(WT_PARTITION_NAME, namespace, NVS_READWRITE, out_handle); } void wt_nvs_close(nvs_handle_t handle)