internet unavailable when connected to AP(Wi-Fi) of ESP32 DevKit,

jjmin.liang
Posts: 10
Joined: Sat Feb 16, 2019 1:24 pm

internet unavailable when connected to AP(Wi-Fi) of ESP32 DevKit,

Postby jjmin.liang » Sat Feb 23, 2019 8:39 am

Hi,

I'm writing a program that working with AP mode on ESP32 DevKit, but when my iOS device connected to the AP that created by ESP32, my iOS can't access internet. but when I use other type of AP(e.g the AP of GoPro camera), even I connected them, I still can use my Cellular network to access internet.

Is there some setting I missed in esp32? I want to keep internet available when connected to the AP on ESP32.

Thanks!


jjmin.liang
Posts: 10
Joined: Sat Feb 16, 2019 1:24 pm

Re: internet unavailable when connected to AP(Wi-Fi) of ESP32 DevKit,

Postby jjmin.liang » Sat Feb 23, 2019 4:22 pm

@WiFive

Thanks for your reply, I have read the link you provide for serval times, and do some search for "clear gateway address" and other similarly, but still no idea how to do that..

the following is the public function in dhcpserver.h, which one can I use to clear gateway address?

Code: Select all

void dhcps_start(struct netif *netif, ip4_addr_t ip);
void dhcps_stop(struct netif *netif);
void *dhcps_option_info(u8_t op_id, u32_t opt_len);
void dhcps_set_option_info(u8_t op_id, void *opt_info, u32_t opt_len);
bool dhcp_search_ip_on_mac(u8_t *mac, ip4_addr_t *ip);
void dhcps_dns_setserver(const ip_addr_t *dnsserver);
ip4_addr_t dhcps_dns_getserver();
void dhcps_set_new_lease_cb(dhcps_cb_t cb);

jjmin.liang
Posts: 10
Joined: Sat Feb 16, 2019 1:24 pm

Re: internet unavailable when connected to AP(Wi-Fi) of ESP32 DevKit,

Postby jjmin.liang » Sat Feb 23, 2019 4:39 pm

after the tcpip_adapter_init called, I've set a static ip to my AP:

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));
Do I need call these code again while SYSTEM_EVENT_AP_START received?

jjmin.liang
Posts: 10
Joined: Sat Feb 16, 2019 1:24 pm

Re: internet unavailable when connected to AP(Wi-Fi) of ESP32 DevKit,

Postby jjmin.liang » Sat Feb 23, 2019 5:10 pm

ah..call the tcpip_adapter_set_ip_info again in the SYSTEM_EVENT_AP_START is not work, connect the AP, and after 10-15 seconds, the internet on my iOS device is not unavailable.

jjmin.liang
Posts: 10
Joined: Sat Feb 16, 2019 1:24 pm

Re: internet unavailable when connected to AP(Wi-Fi) of ESP32 DevKit,

Postby jjmin.liang » Mon Feb 25, 2019 8:28 am

hello, does any body have idea?

phatpaul
Posts: 109
Joined: Fri Aug 24, 2018 1:14 pm

Re: internet unavailable when connected to AP(Wi-Fi) of ESP32 DevKit,

Postby phatpaul » Tue Feb 26, 2019 4:34 pm

Interesting about the Garmin device. What device is it? Does it prevent hijacking the internet connection on both iOS and Android?

Here's what I have after struggling with this as well. It seems to work for iOS, but not always working in Android.

this is in main() before initializing WiFi:

Code: Select all

	tcpip_adapter_init();
	{
		tcpip_adapter_ip_info_t info = {0};
		tcpip_adapter_dns_info_t dns_info = {0};
		IP_ADDR4(&dns_info.ip, 0, 0, 0, 0);
		IP4_ADDR(&info.ip, 192, 168, 4, 1);
		IP4_ADDR(&info.gw, 0, 0, 0, 0);
		IP4_ADDR(&info.netmask, 255, 255, 255, 0);

		ESP_ERROR_CHECK(tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_AP));
		ESP_ERROR_CHECK(tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_AP, &info));
		dhcps_dns_setserver(&(dns_info.ip));
		uint8_t opt_val = 0; // don't supply a dns server via dhcps
		//ESP_ERROR_CHECK(tcpip_adapter_dhcps_option(TCPIP_ADAPTER_OP_SET, TCPIP_ADAPTER_DOMAIN_NAME_SERVER, &opt_val, 1));  // don't supply a dns server via dhcps
		ESP_ERROR_CHECK(tcpip_adapter_dhcps_option(TCPIP_ADAPTER_OP_SET, TCPIP_ADAPTER_ROUTER_SOLICITATION_ADDRESS, &opt_val, 1));  // don't supply a gateway (router) via dhcps option 3
		ESP_ERROR_CHECK(tcpip_adapter_dhcps_start(TCPIP_ADAPTER_IF_AP));
	}
Hope it helps.

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: internet unavailable when connected to AP(Wi-Fi) of ESP32 DevKit,

Postby Ritesh » Tue Feb 26, 2019 6:54 pm

Hi jjmin,

Would you please let me know like how you are using ESP32 device? I think you are using ESP32 device into AP mode and you are trying to connect your IoS device with that ESP32.

Let me correct if I am wrong at any point.

So, I just want to know that ESP32 device is configired as AP or AP+STA mode? So that I can help you to resolve your issue.
Regards,
Ritesh Prajapati

jjmin.liang
Posts: 10
Joined: Sat Feb 16, 2019 1:24 pm

Re: internet unavailable when connected to AP(Wi-Fi) of ESP32 DevKit,

Postby jjmin.liang » Thu Feb 28, 2019 4:06 am

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);
}

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: internet unavailable when connected to AP(Wi-Fi) of ESP32 DevKit,

Postby Ritesh » Thu Feb 28, 2019 8:32 am

jjmin.liang wrote:
Thu Feb 28, 2019 4:06 am
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);
}
Hi,

Yes. obviously you can not access internet from ESP32 device if it is working into AP mode as you are doing one kind of offline communication with it.

So, If you connect your mobile device or any iOS mobile device with ESP32 which is configured and up with AP mode then it will only be able to communicate your mobile device with ESP32 device only. You can not access internet with that scenario.

So, you might need to create one kind of bridge or AP+STA mode to do it like that way but still need to look like how we can achieve with that.

SDK Developer can suggest here to achieve what you want with ESP32 Device.
Regards,
Ritesh Prajapati

Who is online

Users browsing this forum: Bing [Bot], limitless23 and 80 guests