APSTA - works with Broadcom but not Intel Centrino WiFi [title changed]

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

APSTA - works with Broadcom but not Intel Centrino WiFi [title changed]

Postby jcsbanks » Thu Aug 30, 2018 10:01 pm

Read all the docs and previous posts on this. I enabled APSTA mode but could not consistently get a connection like I can in either AP or STA mode despite good signal strength. I wonder if it is something to do with IP addresses and wondered if there is a working example to investigate more so that I can for example ping the ESP32 from a device connected to its AP and also have the ESP32 access the LAN over WiFi or the internet. I see that the AP and STA have the same channel due to single radio.

In AP mode, if the connected Android device also shows 4G cellular signal (either due to enabling the option to stay connected to cellular when WiFi has no internet access or because I moved out of ESP32 range), I cannot ping the ESP32 or transfer TCP packets between Android and ESP32 after reconnecting. If I connect to my home WiFi (with internet access) then 4G will be lost, then reconnect to the ESP32 then I can ping and TCP the ESP32.

Sorry if the above sounds vague, been thinking about it for a week and looking for pointers to investigate further. I want to stick with WiFi instead of Bluetooth for performance, but would like to keep cellular data on the phone and also let the ESP32 access the internet over WiFi intermittently. The use case is in a vehicle so it moves in and out of WiFi regularly, but I want a cell phone to stay connected to it.
Last edited by jcsbanks on Fri Aug 31, 2018 12:33 pm, edited 1 time in total.

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: APSTA mode, IP addresses, Android reconnection

Postby boarchuz » Fri Aug 31, 2018 6:36 am

If I'm understanding correctly, isn't this an issue with the Android OS? (Though I'd expect the exact same behaviour in both AP and APSTA if that was the case.)

Do any of the suggestions in this thread help? https://androidforums.com/threads/conne ... t.1014094/

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: APSTA mode, IP addresses, Android reconnection

Postby jcsbanks » Fri Aug 31, 2018 8:58 am

Thanks, the second part is Android specific, and I am looking through that link, thanks.

APSTA mode gave problems on Windows too where the networks were found but most of the time Windows would not connect to the AP (WiFi icon flashing, complaints of incorrect password) and the STA did not transfer data. It was difficult to even start diagnosing as it was inconsistent and varied between two PCs. I will try to be more specific, but it was very slippery so I just abandoned it and went back to using the ESP32 in AP or STA which "just works".

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: APSTA mode, IP addresses, Android reconnection

Postby jcsbanks » Fri Aug 31, 2018 10:16 am

Here is the WiFi code I'm using. In this form, I can see in the serial output from the ESP32 that it has STA_CONNECTED, got an IP address I can ping. It also has AP_STACONNECTED but if using WPA2_PSK, Windows says the network security key isn't correct and WiFi icon flashes, if using no security, it also doesn't work. What does work is changing to WIFI_MODE_AP and removing ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) ); (or WIFI_MODE_STA and removing the ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &ap_config) );

I have tried calling esp_wifi_start twice, and will also try similar steps on other laptops.

Weirdly, this does work on another laptop. Will keep testing for consistency.

These are not real passwords or SSID but equivalent in length and mixture of numbers and letters.

Code: Select all

	
    nvs_flash_init();
    tcpip_adapter_init();
    ESP_ERROR_CHECK( esp_event_loop_init(wifi_event_handler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_APSTA) );
    
	wifi_config_t sta_config =
	{
        .sta = {
			.ssid = "BTHomeHub5-ZXCV",
			.password = "8d6fds56de",
			.channel = 11,
		}
    };

	wifi_config_t ap_config =
	{
		.ap = {
			.ssid = "ESP32",
			.password = "Defesiohog2011",
			.authmode = WIFI_AUTH_WPA2_PSK,
			.ssid_hidden = 0,
			.max_connection = 3,
			.beacon_interval = 100
		}
	};
	
    ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
    ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &ap_config) );
    ESP_ERROR_CHECK( esp_wifi_start() );
Event handler:

Code: Select all

esp_err_t wifi_event_handler(void *ctx, system_event_t *event)
{
	static char tag[] = "app_main";

    switch(event->event_id)
    {
        case SYSTEM_EVENT_WIFI_READY:
        {
           ESP_LOGI(tag, "SYSTEM_EVENT_WIFI_READY");
           break;
        }
  
        case SYSTEM_EVENT_SCAN_DONE:
        {
           ESP_LOGI(tag, "SYSTEM_EVENT_SCAN_DONE");
           break;
        }
  
  	  case SYSTEM_EVENT_STA_START:
        {
           ESP_LOGI(tag, "SYSTEM_EVENT_STA_START");
           ESP_ERROR_CHECK( esp_wifi_connect() );
           break;
        }
  
        case SYSTEM_EVENT_STA_STOP:
        {
           ESP_LOGI(tag, "SYSTEM_EVENT_STA_STOP");
           break;
        }
  
        case SYSTEM_EVENT_STA_CONNECTED:
        {
           ESP_LOGI(tag, "SYSTEM_EVENT_STA_CONNECTED");
           break;
        }
  
        case SYSTEM_EVENT_STA_DISCONNECTED:
        {
           ESP_LOGI(tag, "SYSTEM_EVENT_STA_DISCONNECTED");
           break;
        }
  
        case SYSTEM_EVENT_STA_AUTHMODE_CHANGE:
        {
           ESP_LOGI(tag, "SYSTEM_EVENT_STA_AUTHMODE_CHANGE");
           break;
        }
  
        case SYSTEM_EVENT_STA_GOT_IP:
        {
           ESP_LOGI(tag, "SYSTEM_EVENT_STA_GOT_IP");
           break;
        }
  
        case SYSTEM_EVENT_STA_LOST_IP:
        {
           ESP_LOGI(tag, "SYSTEM_EVENT_STA_LOST_IP");
           break;
        }
  
        default:
        {
           ESP_LOGI(tag, "EventHandler received %i", event->event_id);
           break;
        }
	}
    return ESP_OK; 
}

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: APSTA mode, IP addresses, Android reconnection

Postby jcsbanks » Fri Aug 31, 2018 11:08 am

The issue seems specific to Intel Centrino N 6235 devices I have in two PCs. Despite reinstalling the latest Intel drivers. I will see if I can change the wireless card in one laptop to prove it.

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: APSTA mode, IP addresses, Android reconnection

Postby jcsbanks » Fri Aug 31, 2018 12:04 pm

On two laptops, Intel Centrino N6235 and N2230 are the problems. Changing to an old Broadcom WiFi adapter and all is well. Changing back to N6235 on one laptop breaks it again.

In ATPSTA mode with Intel Centrino WiFi only, the ESP32 reports a station has joined, but the station reports the password is incorrect, WiFi icon flashes. If not using security, cannot ping the ESP32.

I guess I need to order some newer Intel WiFi modules and test them when in APSTA mode.

As it is, with Broadcom WiFi adapters it is nice to see my ESP32 application working as intended :)

boarchuz
Posts: 606
Joined: Tue Aug 21, 2018 5:28 am

Re: APSTA - works with Broadcom but not Intel Centrino WiFi [title changed]

Postby boarchuz » Fri Aug 31, 2018 2:30 pm

Try setting it to station mode, waiting until a connection is established, and then configuring the AP (or default to pure AP if station connect times out, or connection drops). Otherwise, if it doesn't have a connection, it will be scanning channels trying to reconnect which will cause a lot of instability with devices connected to its own AP.

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], karunt and 132 guests