[已解决]关于 nvs blob 的读写问题

hynemanKan
Posts: 1
Joined: Mon Jun 21, 2021 6:26 am

[已解决]关于 nvs blob 的读写问题

Postby hynemanKan » Mon Jun 28, 2021 9:00 am

esp-idf 版本:V4.3
改自smart_config示例,reboot后尝试读取保存的ssid、password、bssid时报错,通过prinf deubg 发现ssid可以成功读之后就报错了。
代码:
  1.   /* Esptouch example
  2.    This example code is in the Public Domain (or CC0 licensed, at your option.)
  3.    Unless required by applicable law or agreed to in writing, this
  4.    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5.    CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7.  
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include "freertos/FreeRTOS.h"
  11. #include "freertos/task.h"
  12. #include "freertos/event_groups.h"
  13. #include "esp_wifi.h"
  14. #include "esp_wpa2.h"
  15. #include "esp_event.h"
  16. #include "esp_log.h"
  17. #include "esp_system.h"
  18. #include "nvs_flash.h"
  19. #include "esp_netif.h"
  20. #include "esp_smartconfig.h"
  21.  
  22. #define STORAGE_NAMESPACE "WIFI_CONF"
  23.  
  24. /* FreeRTOS event group to signal when we are connected & ready to make a request */
  25. static EventGroupHandle_t s_wifi_event_group;
  26.  
  27. /* The event group allows multiple bits for each event,
  28.    but we only care about one event - are we connected
  29.    to the AP with an IP? */
  30. static const int CONNECTED_BIT = BIT0;
  31. static const int ESPTOUCH_DONE_BIT = BIT1;
  32. static const char *TAG = "smartconfig_example";
  33. size_t ssid_size=33,passwd_size=65,bssid_size=8;
  34. static void smartconfig_example_task(void * parm);
  35.  
  36. static void event_handler(void* arg, esp_event_base_t event_base,
  37.                                 int32_t event_id, void* event_data)
  38. {
  39.     if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
  40.         xTaskCreate(smartconfig_example_task, "smartconfig_example_task", 4096, NULL, 3, NULL);
  41.     } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
  42.         esp_wifi_connect();
  43.         xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
  44.     } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
  45.         xEventGroupSetBits(s_wifi_event_group, CONNECTED_BIT);
  46.     } else if (event_base == SC_EVENT && event_id == SC_EVENT_SCAN_DONE) {
  47.         ESP_LOGI(TAG, "Scan done");
  48.     } else if (event_base == SC_EVENT && event_id == SC_EVENT_FOUND_CHANNEL) {
  49.         ESP_LOGI(TAG, "Found channel");
  50.     } else if (event_base == SC_EVENT && event_id == SC_EVENT_GOT_SSID_PSWD) {
  51.         ESP_LOGI(TAG, "Got SSID and password");
  52.  
  53.         smartconfig_event_got_ssid_pswd_t *evt = (smartconfig_event_got_ssid_pswd_t *)event_data;
  54.         wifi_config_t wifi_config;
  55.         uint8_t ssid[33] = { 0 };
  56.         uint8_t password[65] = { 0 };
  57.         uint8_t bssid[8] = { 0 };
  58.         uint8_t rvd_data[33] = { 0 };
  59.         bzero(&wifi_config, sizeof(wifi_config_t));
  60.         memcpy(wifi_config.sta.ssid, evt->ssid, sizeof(wifi_config.sta.ssid));
  61.         memcpy(wifi_config.sta.password, evt->password, sizeof(wifi_config.sta.password));
  62.         wifi_config.sta.bssid_set = evt->bssid_set;
  63.         if (wifi_config.sta.bssid_set == true) {
  64.             memcpy(wifi_config.sta.bssid, evt->bssid, sizeof(wifi_config.sta.bssid));
  65.         }
  66.         memcpy(bssid, evt->bssid, sizeof(evt->bssid));
  67.         memcpy(ssid, evt->ssid, sizeof(evt->ssid));
  68.         memcpy(password, evt->password, sizeof(evt->password));
  69.         printf("ssid:%d\tpassword:%d\tbssid:%d\n",sizeof(evt->ssid),sizeof(evt->password),sizeof(evt->bssid));
  70.         ESP_LOGI(TAG, "SSID:%s", ssid);
  71.         ESP_LOGI(TAG, "PASSWORD:%s", password);
  72.         nvs_handle_t my_handle;
  73.         nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &my_handle);
  74.         nvs_set_u8(my_handle,"SSID_LEN",sizeof(evt->ssid));
  75.         nvs_set_u8(my_handle,"PASSWORD_LEN",sizeof(evt->password));
  76.         nvs_set_u8(my_handle,"BSSID_LEN",sizeof(evt->bssid));
  77.         nvs_set_blob(my_handle,"SSID",evt->ssid,sizeof(evt->ssid));
  78.         nvs_set_blob(my_handle,"PASSWORD",evt->password,sizeof(evt->password));
  79.         nvs_set_blob(my_handle,"BSSID",evt->bssid,sizeof(evt->bssid));
  80.         nvs_commit(my_handle);
  81.         nvs_close(my_handle);
  82.         if (evt->type == SC_TYPE_ESPTOUCH_V2) {
  83.             ESP_ERROR_CHECK( esp_smartconfig_get_rvd_data(rvd_data, sizeof(rvd_data)) );
  84.             ESP_LOGI(TAG, "RVD_DATA:");
  85.             for (int i=0; i<33; i++) {
  86.                 printf("%02x ", rvd_data[i]);
  87.             }
  88.             printf("\n");
  89.         }
  90.  
  91.         ESP_ERROR_CHECK( esp_wifi_disconnect() );
  92.         ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
  93.         esp_wifi_connect();
  94.     } else if (event_base == SC_EVENT && event_id == SC_EVENT_SEND_ACK_DONE) {
  95.         xEventGroupSetBits(s_wifi_event_group, ESPTOUCH_DONE_BIT);
  96.     }
  97. }
  98.  
  99.  
  100. static void initialise_wifi(void)
  101. {
  102.     ESP_ERROR_CHECK(esp_netif_init());
  103.     s_wifi_event_group = xEventGroupCreate();
  104.     ESP_ERROR_CHECK(esp_event_loop_create_default());
  105.     esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
  106.     assert(sta_netif);
  107.  
  108.     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  109.     ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
  110.  
  111.     ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) );
  112.     ESP_ERROR_CHECK( esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL) );
  113.     ESP_ERROR_CHECK( esp_event_handler_register(SC_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) );
  114.  
  115.     ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
  116.     ESP_ERROR_CHECK( esp_wifi_start() );
  117. }
  118.  
  119. static void smartconfig_example_task(void * parm)
  120. {
  121.     EventBits_t uxBits;
  122.     ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH) );
  123.     smartconfig_start_config_t cfg = SMARTCONFIG_START_CONFIG_DEFAULT();
  124.     ESP_ERROR_CHECK( esp_smartconfig_start(&cfg) );
  125.     while (1) {
  126.         uxBits = xEventGroupWaitBits(s_wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT, true, false, portMAX_DELAY);
  127.         if(uxBits & CONNECTED_BIT) {
  128.             ESP_LOGI(TAG, "WiFi Connected to ap");
  129.         }
  130.         if(uxBits & ESPTOUCH_DONE_BIT) {
  131.             ESP_LOGI(TAG, "smartconfig over");
  132.             esp_smartconfig_stop();
  133.             vTaskDelete(NULL);
  134.         }
  135.     }
  136. }
  137.  
  138. void app_main(void)
  139. {
  140.     ESP_ERROR_CHECK( nvs_flash_init() );
  141.     nvs_handle_t my_handle;
  142.     uint8_t ssidLen=0,passwordLen=0,bssidLen=0;
  143.     printf("start\n");
  144.     esp_err_t err1,err2,err3;
  145.     nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &my_handle);
  146.     printf("open\n");
  147.     err1 = nvs_get_u8(my_handle,"SSID_LEN",&ssidLen);
  148.     err2 = nvs_get_u8(my_handle,"PASSWORD_LEN",&passwordLen);
  149.     err3 = nvs_get_u8(my_handle,"BSSID_LEN",&bssidLen);
  150.     printf("%d\t%d\t%d\n",ssidLen,passwordLen,bssidLen);
  151.     if(err1 == ESP_OK && err2 == ESP_OK && err3 == ESP_OK){
  152.         uint8_t* ssid=malloc(ssidLen);
  153.         nvs_get_blob(my_handle,"SSID",ssid,&ssidLen);
  154.         uint8_t* password=malloc(passwordLen);
  155.         nvs_get_blob(my_handle,"PASSWORD",password,&passwordLen);
  156.         uint8_t* bssid=malloc(bssidLen);
  157.         nvs_get_blob(my_handle,"BSSID",bssid,&bssidLen);
  158.         printf("read finish\n");
  159.         nvs_commit(my_handle);
  160.         nvs_close(my_handle);
  161.         vTaskDelay(1000/ portTICK_PERIOD_MS);
  162.         wifi_config_t wifi_config;
  163.         memcpy(wifi_config.sta.ssid, ssid, ssidLen);
  164.         printf("1\n");
  165.         memcpy(wifi_config.sta.password, password, passwordLen);
  166.         printf("1\n");
  167.         memcpy(wifi_config.sta.bssid, bssid, bssidLen);
  168.         printf("1\n");
  169.         esp_wifi_set_config(WIFI_IF_STA, &wifi_config);
  170.     }else{
  171.         printf("err1:%s\terr2:%s\terr3:%s\n",esp_err_to_name(err1),esp_err_to_name(err2),esp_err_to_name(err3));
  172.         nvs_commit(my_handle);
  173.         nvs_close(my_handle);
  174.         initialise_wifi();
  175.     }
  176. }
log:
  1. ESP-ROM:esp32s2-rc4-20191025
  2. Build:Oct 25 2019
  3. rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
  4. SPIWP:0xee
  5. mode:DIO, clock div:1
  6. load:0x3ffe6100,len:0x1820
  7. load:0x4004c000,len:0x9e8
  8. load:0x40050000,len:0x2b70
  9. SHA-256 comparison failed:
  10. Calculated: 0bd0e2d0d51814779bd45c31e7ba7f878e91b119708a62bd71f9edfca00a948f
  11. Expected: 38198821cae9ebb0df857e77da8b30e97263995b3a399610ede168c82c6a8570  
  12. Attempting to boot anyway...
  13. entry 0x4004c1ec
  14. I (40) boot: ESP-IDF v4.3 2nd stage bootloader
  15. I (40) boot: compile time 15:06:22
  16. I (40) boot: chip revision: 0    
  17. I (42) boot.esp32s2: SPI Speed      : 80MHz
  18. I (47) boot.esp32s2: SPI Mode       : DIO
  19. I (52) boot.esp32s2: SPI Flash Size : 4MB
  20. I (56) boot: Enabling RNG early entropy source...
  21. I (62) boot: Partition Table:
  22. I (65) boot: ## Label            Usage          Type ST Offset   Length
  23. I (73) boot:  0 nvs              WiFi data        01 02 00009000 00006000
  24. I (80) boot:  1 phy_init         RF data          01 01 0000f000 00001000
  25. I (87) boot:  2 factory          factory app      00 00 00010000 00100000
  26. I (95) boot: End of partition table
  27. I (99) esp_image: segment 0: paddr=00010020 vaddr=3f000020 size=17c40h ( 97344) map
  28. I (129) esp_image: segment 1: paddr=00027c68 vaddr=3ffc6400 size=03e74h ( 15988) load
  29. I (133) esp_image: segment 2: paddr=0002bae4 vaddr=40022000 size=04534h ( 17716) load
  30. I (139) esp_image: segment 3: paddr=00030020 vaddr=40080020 size=76074h (483444) map
  31. I (247) esp_image: segment 4: paddr=000a609c vaddr=40026534 size=0fec0h ( 65216) load
  32. I (264) esp_image: segment 5: paddr=000b5f64 vaddr=50000000 size=00010h (    16) load
  33. I (275) boot: Loaded app from partition at offset 0x10000
  34. I (276) boot: Disabling RNG early entropy source...
  35. I (287) ca�f�~��^.�Սѥ���cache        : size 8KB, 4Ways, cache line size 32Byte
  36. I (287) cpu_start: Pro cpu up.
  37. I (301) cpu_start: Pro cpu start user code
  38. I (301) cpu_start: cpu freq: 160000000
  39. I (301) cpu_start: Application information:
  40. I (306) cpu_start: Project name:     main
  41. I (310) cpu_start: App version:      4ddd2b4-dirty
  42. I (316) cpu_start: Compile time:     Jun 27 2021 15:04:20
  43. I (322) cpu_start: ELF file SHA256:  acd0d70b5b69b0de...
  44. I (328) cpu_start: ESP-IDF:          v4.3
  45. I (333) heap_init: Initializing. RAM available for dynamic allocation:
  46. I (340) heap_init: At 3FF9E000 len 00002000 (8 KiB): RTCRAM
  47. I (346) heap_init: At 3FFCEB38 len 0002D4C8 (181 KiB): DRAM
  48. I (352) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
  49. I (359) spi_flash: detected chip: generic
  50. I (363) spi_flash: flash io: dio
  51. I (371) cpu_start: Starting scheduler on PRO CPU.
  52. start
  53. open
  54. 32      64      6
  55. read finish
  56. 1
  57. Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
  58.  
  59. Core  0 register dump:
  60. PC      : 0x4001abc4  PS      : 0x00060f30  A0      : 0x80086344  A1      : 0x3ffd0110
  61. A2      : 0x3ffd0148  A3      : 0x00000000  A4      : 0x00000040  A5      : 0x3ffd0148  
  62. A6      : 0x00000000  A7      : 0x00000004  A8      : 0x00000040  A9      : 0x3ffd00c0
  63. A10     : 0x0000000a  A11     : 0x3ff9e894  A12     : 0x3ffca6cc  A13     : 0x00000000
  64. A14     : 0x00000000  A15     : 0x3ffcffd0  SAR     : 0x0000001f  EXCCAUSE: 0x0000001c
  65. EXCVADDR: 0x00000000  LBEG    : 0x3ffca6cc  LEND    : 0x00000000  LCOUNT  : 0x400243a9
  66. 0x400243a9: _xt_user_exc at C:/Users/Hyenamn/esp-idf/components/freertos/port/xtensa/xtensa_vectors.S:627
  67.  
  68.  
  69. Backtrace:0x4001abc1:0x3ffd0110 0x40086341:0x3ffd0120 0x400f5d93:0x3ffd01d0 0x4002cfad:0x3ffd01f0
  70. 0x40086341: app_main at C:\Users\Hyenamn\Desktop\projects\esp32_vfd_clock\build/../main/main.c:176
  71.  
  72. 0x400f5d93: main_task at C:/Users/Hyenamn/esp-idf/components/freertos/port/port_common.c:133 (discriminator 2)
  73.  
  74. 0x4002cfad: vPortTaskWrapper at C:/Users/Hyenamn/esp-idf/components/freertos/port/xtensa/port.c:168
  75.  
  76.  
  77.  
  78. ELF file SHA256: acd0d70b5b69b0de
Last edited by hynemanKan on Tue Jun 29, 2021 11:39 am, edited 1 time in total.

ChenWen
Posts: 16
Joined: Tue Jun 29, 2021 6:29 am

Re: 关于 nvs blob 的读写问题

Postby ChenWen » Tue Jun 29, 2021 6:44 am

smart_config demo 中配网连上 AP 之后会默认会保存 WiFi 配置信息到 NVS 里面, 不需要额外保存, 你可以通过调用 esp_wifi_get_config 来获取保存的 WiFi 配置信息,可参考:
  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/task.h"
  5. #include "freertos/event_groups.h"
  6. #include "esp_wifi.h"
  7. #include "esp_wpa2.h"
  8. #include "esp_event.h"
  9. #include "esp_log.h"
  10. #include "esp_system.h"
  11. #include "nvs_flash.h"
  12. #include "esp_netif.h"
  13. #include "esp_smartconfig.h"
  14.  
  15. /* FreeRTOS event group to signal when we are connected & ready to make a request */
  16. static EventGroupHandle_t s_wifi_event_group;
  17.  
  18. /* The event group allows multiple bits for each event,
  19.    but we only care about one event - are we connected
  20.    to the AP with an IP? */
  21. static const int CONNECTED_BIT = BIT0;
  22. static const int ESPTOUCH_DONE_BIT = BIT1;
  23. static const char *TAG = "smartconfig_example";
  24.  
  25. static void smartconfig_example_task(void * parm);
  26. bool g_provisioned = false;
  27.  
  28. static void event_handler(void* arg, esp_event_base_t event_base,
  29.                                 int32_t event_id, void* event_data)
  30. {
  31.     if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
  32.         if (g_provisioned == false) {
  33.             xTaskCreate(smartconfig_example_task, "smartconfig_example_task", 4096, NULL, 3, NULL);
  34.         } else {
  35.             esp_wifi_connect();
  36.         }
  37.     } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
  38.         esp_wifi_connect();
  39.         xEventGroupClearBits(s_wifi_event_group, CONNECTED_BIT);
  40.     } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
  41.         xEventGroupSetBits(s_wifi_event_group, CONNECTED_BIT);
  42.     } else if (event_base == SC_EVENT && event_id == SC_EVENT_SCAN_DONE) {
  43.         ESP_LOGI(TAG, "Scan done");
  44.     } else if (event_base == SC_EVENT && event_id == SC_EVENT_FOUND_CHANNEL) {
  45.         ESP_LOGI(TAG, "Found channel");
  46.     } else if (event_base == SC_EVENT && event_id == SC_EVENT_GOT_SSID_PSWD) {
  47.         ESP_LOGI(TAG, "Got SSID and password");
  48.  
  49.         smartconfig_event_got_ssid_pswd_t *evt = (smartconfig_event_got_ssid_pswd_t *)event_data;
  50.         wifi_config_t wifi_config;
  51.         uint8_t ssid[33] = { 0 };
  52.         uint8_t password[65] = { 0 };
  53.         uint8_t rvd_data[33] = { 0 };
  54.  
  55.         bzero(&wifi_config, sizeof(wifi_config_t));
  56.         memcpy(wifi_config.sta.ssid, evt->ssid, sizeof(wifi_config.sta.ssid));
  57.         memcpy(wifi_config.sta.password, evt->password, sizeof(wifi_config.sta.password));
  58.         wifi_config.sta.bssid_set = evt->bssid_set;
  59.         if (wifi_config.sta.bssid_set == true) {
  60.             memcpy(wifi_config.sta.bssid, evt->bssid, sizeof(wifi_config.sta.bssid));
  61.         }
  62.  
  63.         memcpy(ssid, evt->ssid, sizeof(evt->ssid));
  64.         memcpy(password, evt->password, sizeof(evt->password));
  65.         ESP_LOGI(TAG, "SSID:%s", ssid);
  66.         ESP_LOGI(TAG, "PASSWORD:%s", password);
  67.         if (evt->type == SC_TYPE_ESPTOUCH_V2) {
  68.             ESP_ERROR_CHECK( esp_smartconfig_get_rvd_data(rvd_data, sizeof(rvd_data)) );
  69.             ESP_LOGI(TAG, "RVD_DATA:");
  70.             for (int i=0; i<33; i++) {
  71.                 printf("%02x ", rvd_data[i]);
  72.             }
  73.             printf("\n");
  74.         }
  75.  
  76.         ESP_ERROR_CHECK( esp_wifi_disconnect() );
  77.         ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
  78.         esp_wifi_connect();
  79.     } else if (event_base == SC_EVENT && event_id == SC_EVENT_SEND_ACK_DONE) {
  80.         xEventGroupSetBits(s_wifi_event_group, ESPTOUCH_DONE_BIT);
  81.     }
  82. }
  83.  
  84. esp_err_t esp_wifi_is_provisioned(bool *provisioned)
  85. {
  86.     *provisioned = false;
  87.  
  88. #ifdef CONFIG_EXAMPLE_RESET_PROVISIONED
  89.     esp_wifi_restore();
  90.     return ESP_OK;
  91. #endif
  92.  
  93.     /* Get WiFi Station configuration */
  94.     wifi_config_t wifi_cfg;
  95.     if (esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK) {
  96.         return ESP_FAIL;
  97.     }
  98.  
  99.     if (strlen((const char*) wifi_cfg.sta.ssid)) {
  100.         *provisioned = true;
  101.         ESP_LOGI(TAG, "Found ssid %s",     (const char*) wifi_cfg.sta.ssid);
  102.         ESP_LOGI(TAG, "Found password %s", (const char*) wifi_cfg.sta.password);
  103.     }
  104.     return ESP_OK;
  105. }
  106.  
  107. static void initialise_wifi(void)
  108. {
  109.     ESP_ERROR_CHECK(esp_netif_init());
  110.     s_wifi_event_group = xEventGroupCreate();
  111.     ESP_ERROR_CHECK(esp_event_loop_create_default());
  112.     esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
  113.     assert(sta_netif);
  114.  
  115.     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  116.     ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
  117.  
  118.     ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) );
  119.     ESP_ERROR_CHECK( esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL) );
  120.     ESP_ERROR_CHECK( esp_event_handler_register(SC_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) );
  121.  
  122.     ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
  123.  
  124.     /* Check if device is provisioned */
  125.     if (esp_wifi_is_provisioned(&g_provisioned) != ESP_OK) {
  126.         ESP_LOGE(TAG, "Error getting device provisioning state");
  127.         return;
  128.     }
  129.  
  130.     ESP_ERROR_CHECK( esp_wifi_start() );
  131. }
  132.  
  133. static void smartconfig_example_task(void * parm)
  134. {
  135.     EventBits_t uxBits;
  136.     ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH) );
  137.     smartconfig_start_config_t cfg = SMARTCONFIG_START_CONFIG_DEFAULT();
  138.     ESP_ERROR_CHECK( esp_smartconfig_start(&cfg) );
  139.     while (1) {
  140.         uxBits = xEventGroupWaitBits(s_wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT, true, false, portMAX_DELAY);
  141.         if(uxBits & CONNECTED_BIT) {
  142.             ESP_LOGI(TAG, "WiFi Connected to ap");
  143.         }
  144.         if(uxBits & ESPTOUCH_DONE_BIT) {
  145.             ESP_LOGI(TAG, "smartconfig over");
  146.             esp_smartconfig_stop();
  147.             vTaskDelete(NULL);
  148.         }
  149.     }
  150. }
  151.  
  152. void app_main(void)
  153. {
  154.     ESP_ERROR_CHECK( nvs_flash_init() );
  155.     initialise_wifi();
  156. }

Who is online

Users browsing this forum: No registered users and 174 guests