完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
typedef struct _wifi_conf wifi_conf_struct; struct _wifi_conf { char *ssid; char *password; }; typedef struct _wifi_conf_node_t wifi_conf_node_t; struct _wifi_conf_node_t { wifi_conf_struct item; wifi_conf_node_t *p; }; typedef struct _wifi_conf_link_t wifi_conf_link_t; struct _wifi_conf_link_t { wifi_conf_node_t *np; int length; }; NVS存储函数: esp_err_t nvs_write_data_to_flash_in_main(wifi_conf_link_t *wifi_conf_list_link) { //ESP_ERROR_CHECK(nvs_flash_erase()); nvs_handle handle; size_t wifi_conf_size = 0; int list_cont = wifi_conf_list_link->length; struct _wifi_conf_node_t *tmp = wifi_conf_list_link->np; struct _wifi_conf wifi_conf_list[list_cont]; int i = 0; while (i < list_cont) { wifi_conf_list wifi_conf_size = wifi_conf_size + sizeof(tmp->item); tmp = tmp->p; i++; } ESP_ERROR_CHECK(nvs_open(NVS_CUSTOMER, NVS_READWRITE, &handle)); ESP_ERROR_CHECK(nvs_set_i32(handle, DATA_KEY_2, list_cont)); ESP_ERROR_CHECK(nvs_set_blob(handle, DATA_KEY_1, wifi_conf_list, wifi_conf_size)); ESP_ERROR_CHECK(nvs_commit(handle)); // free(wifi_conf_list); // free(tmp); printf("NVS_WRITE:存储wifi信息完毕n"); nvs_close(handle); return ESP_OK; } NVS读取函数: struct _wifi_conf_link_t nvs_read_data_from_flash_in_main(void) { struct _wifi_conf_link_t wifi_conf_list_link_read = {NULL, 0}; nvs_handle handle; int32_t value = 0; esp_err_t err = nvs_open(NVS_CUSTOMER, NVS_READWRITE, &handle); if (err != ESP_OK) { printf("Error (%s) opening NVS handle!n", esp_err_to_name(err)); } else { printf("Donen"); // Read printf("Reading restart counter from NVS ... "); err = nvs_get_i32(handle, DATA_KEY_2, &value); switch (err) { case ESP_OK: printf("Donen"); printf("Restart counter = %dn", value); break; case ESP_ERR_NVS_NOT_FOUND: printf("The value is not initialized yet!n"); break; default: printf("Error (%s) reading!n", esp_err_to_name(err)); } } if (value == 0) { return wifi_conf_list_link_read; } struct _wifi_conf wifi_conf_list[value]; size_t required_size = 0; // value will default to 0, if not set yet in NVS nvs_get_blob(handle, DATA_KEY_1, NULL, &required_size); ESP_ERROR_CHECK(nvs_get_blob(handle, DATA_KEY_1, &wifi_conf_list, &required_size)); nvs_close(handle); for (int i = 0; i < value; i++) { wifi_conf_link_add(&wifi_conf_list_link_read, wifi_conf_list //printf("%srn",wifi_conf_list } return wifi_conf_list_link_read; } 问题来了: wifi_conf_struct tmp = {"yangyanghome24", "abcd1234"};//重点 wifi_conf_link_del_all(&m_wifi_conf_link_main); wifi_conf_link_add(&m_wifi_conf_link_main, tmp); nvs_write_data_to_flash(&m_wifi_conf_link_main); 重启后,NVS读取正常,但是: const char* pwd_selected_const = lv_textarea_get_text(textarea_pswd); int nLen = strlen(pwd_selected_const); char* pCh = (char*)malloc(sizeof(pwd_selected_const)); memcpy(pCh, pwd_selected_const, nLen + 1); wifi_conf_struct scan_seleced_wifi_conf = {"splite_ssid_",pCh};//重点 重启后,读取出现乱码!!求帮助,困扰好长时间了。 |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
1142 浏览 1 评论
578浏览 6评论
479浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
463浏览 5评论
464浏览 4评论
440浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 01:47 , Processed in 0.730988 second(s), Total 43, Slave 37 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号