v4.4.0
Operating System
Windows
build project
VS Code IDE
- uint8_t eth_mac[6];
- char mkSsid[32];
- char SetPwd[32];
- memset(SetPwd, 0, sizeof(SetPwd));
- ESP_ERROR_CHECK(esp_netif_init());
- ESP_ERROR_CHECK(esp_event_loop_create_default());
- esp_netif_create_default_wifi_ap();
- wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
- ESP_ERROR_CHECK(esp_wifi_init(&cfg));
- setDns();
- ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA)); //WIFI_MODE_AP
- ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &dwd_event_handler, NULL));
- ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &dwd_event_handler, NULL));
- esp_wifi_get_mac(ESP_IF_WIFI_AP, eth_mac);
- if(pSysinfo->DeviceMeasureType == DWD_TYPE_THREE_100A)
- {
- sprintf(mkSsid, DWD_SSID_PREPIX_3P100A"%02x%02x%02x", eth_mac[3], eth_mac[4], eth_mac[5]);
- }else if(pSysinfo->DeviceMeasureType == DWD_TYPE_THREE_400A)
- {
- sprintf(mkSsid, DWD_SSID_PREPIX_3P400A"%02x%02x%02x", eth_mac[3], eth_mac[4], eth_mac[5]);
- }else if(pSysinfo->DeviceMeasureType == DWD_TYPE_THREE_800A)
- {
- sprintf(mkSsid, DWD_SSID_PREPIX_3P800A"%02x%02x%02x", eth_mac[3], eth_mac[4], eth_mac[5]);
- }else
- {
- sprintf(mkSsid, DWD_SSID_PREPIX_1P"%02x%02x%02x", eth_mac[3], eth_mac[4], eth_mac[5]);
- }
- 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]);
- wifi_config_t wifi_config = {
- .ap = {
- .max_connection = DWD_MAX_STA_CONN,
- //.authmode = WIFI_AUTH_WPA_WPA2_PSK,
- //.ssid_hidden = false,
- .beacon_interval = 100
- },
- };
- if (dwd_wifi_events == NULL) {
- dwd_wifi_events = xEventGroupCreate();
- }
- memset(&(wifi_config.ap.ssid[0]), 0, sizeof(wifi_config.ap.ssid));
- memset(&(wifi_config.ap.password[0]), 0, sizeof(wifi_config.ap.password));
- wifi_config.ap.ssid_len = sprintf((char *)&wifi_config.ap.ssid, "%s", mkSsid);
- if (strlen(SetPwd) == 0)
- {
- wifi_config.ap.authmode = WIFI_AUTH_OPEN;
- ESP_LOGI(TAG, "wifi_init_softap finished. SSID[%d]:%s", wifi_config.ap.ssid_len, mkSsid);
- }else
- {
- wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK;
- sprintf((char *)&wifi_config.ap.password, "%s", SetPwd);
- ESP_LOGI(TAG, "wifi_init_softap finished. SSID:%s password:%s", mkSsid, SetPwd);
- }
- ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config));
- ESP_ERROR_CHECK(esp_wifi_start());
- ESP_ERROR_CHECK(esp_wifi_set_protocol(ESP_IF_WIFI_AP, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N));
- start_webserver();
- 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.
- I'd really appreciate it if you could tell me how to solve it