[esp-eye] Station mode wifi disconnected

piter5
Posts: 2
Joined: Fri Jul 05, 2024 2:18 am

[esp-eye] Station mode wifi disconnected

Postby piter5 » Thu Sep 05, 2024 1:53 am

IDF version.
v4.4.0

Operating System
Windows

build project
VS Code IDE



  1.  
  2. uint8_t eth_mac[6];
  3. char mkSsid[32];
  4. char SetPwd[32];
  5.  
  6. memset(SetPwd, 0, sizeof(SetPwd));
  7.  
  8. ESP_ERROR_CHECK(esp_netif_init());
  9. ESP_ERROR_CHECK(esp_event_loop_create_default());
  10. esp_netif_create_default_wifi_ap();
  11.  
  12. wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  13. ESP_ERROR_CHECK(esp_wifi_init(&cfg));
  14.  
  15. setDns();
  16. ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA)); //WIFI_MODE_AP
  17. ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &dwd_event_handler, NULL));
  18. ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &dwd_event_handler, NULL));
  19.  
  20.  
  21. esp_wifi_get_mac(ESP_IF_WIFI_AP, eth_mac);
  22. if(pSysinfo->DeviceMeasureType == DWD_TYPE_THREE_100A)
  23. {
  24.     sprintf(mkSsid, DWD_SSID_PREPIX_3P100A"%02x%02x%02x", eth_mac[3], eth_mac[4], eth_mac[5]);
  25. }else if(pSysinfo->DeviceMeasureType == DWD_TYPE_THREE_400A)
  26. {
  27.     sprintf(mkSsid, DWD_SSID_PREPIX_3P400A"%02x%02x%02x", eth_mac[3], eth_mac[4], eth_mac[5]);
  28. }else if(pSysinfo->DeviceMeasureType == DWD_TYPE_THREE_800A)
  29. {
  30.     sprintf(mkSsid, DWD_SSID_PREPIX_3P800A"%02x%02x%02x", eth_mac[3], eth_mac[4], eth_mac[5]);
  31. }else
  32. {
  33.     sprintf(mkSsid, DWD_SSID_PREPIX_1P"%02x%02x%02x", eth_mac[3], eth_mac[4], eth_mac[5]);
  34. }
  35. sprintf(pSysinfo->mac_st, "%02x%02x%02x%02x%02x%02x", eth_mac[0], eth_mac[1], eth_mac[2], eth_mac[3], eth_mac[4], eth_mac[5]);
  36.  
  37. wifi_config_t wifi_config = {
  38.     .ap = {
  39.         .max_connection = DWD_MAX_STA_CONN,
  40.         //.authmode = WIFI_AUTH_WPA_WPA2_PSK,
  41.         //.ssid_hidden = false,
  42.         .beacon_interval = 100
  43.     },
  44. };
  45.  
  46. if (dwd_wifi_events == NULL) {
  47.     dwd_wifi_events = xEventGroupCreate();
  48. }
  49.  
  50. memset(&(wifi_config.ap.ssid[0]), 0, sizeof(wifi_config.ap.ssid));
  51. memset(&(wifi_config.ap.password[0]), 0, sizeof(wifi_config.ap.password));
  52.  
  53. wifi_config.ap.ssid_len = sprintf((char *)&wifi_config.ap.ssid, "%s", mkSsid);
  54.  
  55. if (strlen(SetPwd) == 0)
  56. {
  57.     wifi_config.ap.authmode = WIFI_AUTH_OPEN;
  58.     ESP_LOGI(TAG, "wifi_init_softap finished. SSID[%d]:%s", wifi_config.ap.ssid_len, mkSsid);
  59. }else
  60. {
  61.     wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK;
  62.     sprintf((char *)&wifi_config.ap.password, "%s", SetPwd);
  63.     ESP_LOGI(TAG, "wifi_init_softap finished. SSID:%s password:%s", mkSsid, SetPwd);
  64. }
  65.  
  66. ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config));
  67. ESP_ERROR_CHECK(esp_wifi_start());
  68.  
  69.  
  70. ESP_ERROR_CHECK(esp_wifi_set_protocol(ESP_IF_WIFI_AP, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N));
  71.  
  72.  
  73. start_webserver();
  74.  
  75.  
  76.  
  77.  
  78. Open a webpage in softap mode, enter nvs information there, save it, reboot it, and connect wifi in station mode, but the connection is successful and then disconnected right away.
  79. I'd really appreciate it if you could tell me how to solve it
  80.  

Who is online

Users browsing this forum: Google [Bot], ok-home and 64 guests