Hi Ritesh,
Thanks for you reply! I still working with this issue, but no idea yet
Yeah, you are right, My ESP32 device is working on AP mode, and at the booting time, I've set the reset the IP address and the gateway.
here is the code that I setting the Ip address and the gateway:
Code: Select all
tcpip_adapter_ip_info_t info;
memset(&info, 0, sizeof(info));
IP4_ADDR(&info.ip, 192, 168, 1, 1);
IP4_ADDR(&info.gw, 192, 168, 1, 1);//ESP acts as router, so gw addr will be its own addr
IP4_ADDR(&info.netmask, 255, 255, 255, 0);
ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info));
// start the DHCP server
ESP_ERROR_CHECK(tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP));
here is the code that initialize the AP of WIFI:
Code: Select all
main()
{
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
// OTA app partition table has a smaller NVS partition size than the non-OTA
// partition table. This size mismatch may cause NVS initialization to fail.
// If this happens, we erase NVS partition and initialize NVS again.
ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init();
}
ESP_ERROR_CHECK( err );
tcpip_adapter_init();
WIFIAP::sharedInstance()->start(ssid, password);
....
}
// here is the implementation of startAPMode
void WIFIAP::start(string ssid, string pasword)
{
wifi_config_t wifi_config;
memset(&wifi_config, 0, sizeof(wifi_config_t));
strcpy((char*)wifi_config.ap.ssid, ssid.c_str());
wifi_config.ap.ssid_len = ssid.size();
wifi_config.ap.max_connection = 1;
if (pasword.size() == 0) {
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
} else {
strcpy((char*)wifi_config.ap.password, pasword.c_str());
wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK;
}
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_LOGI(TAG, "initialize done. ssid: %s", wifi_config.sta.ssid);
}