3

I have a Wifi Micro controller ESP8266 which also has an access point. I have referred to other blogs which talk about programmatically connecting to an access point and tried both the way

  1. Using the exposed standard APIS

    wifiManager.enableNetwork(netId, true); wifiManager.saveConfiguration(); wifiManager.reconnect();

  2. Using the APIs which have @ hide on them

    wifiManager.connect(netId, ActionListener)

The problem I am facing is that some time after i connect to the access point its getting disconnected from the esp8266 access point and connecting back to my router in both the above mentioned methods.

If i connected via the top bar or through the settings app its connecting in a stable way and never disconnects and I even get the notification

Wi-Fi has no internet access

I don't get the no internet access notification when i connect programmatically. How is the settings app able to connect to the access point in a stable way while my App is not able to.

I am running Androidn 6.0.1 API 23

thehellmaker
  • 162
  • 3
  • 13
  • This not only happens through my app but also while configuring amazon alexa where i have to connect to the device's access point. – thehellmaker Aug 13 '16 at 17:45
  • found a new issue same as mine http://stackoverflow.com/questions/35145831/failed-to-connect-to-specific-wifi-in-android-programmatically – thehellmaker Aug 13 '16 at 18:47
  • Hi Akash, What's code you are using to connect to esp. I tried below but not working for me. Can you share your code snippet wifiConfiguration.SSID = "\"" + networkInfo.name + "\""; password = getPassword(networkInfo.name); wifiConfiguration.preSharedKey = "\"" + password + "\""; wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.WPA); – Nitin Kr Sep 18 '16 at 13:10

2 Answers2

0

If you specifically request using that Network once before it disconnects, it will stay connected indefinitely:

  • ConnectivityManager.bindProcessToNetwork(Network)
  • Network.bindSocket(Socket)
  • Network.openConnection(URL)

Also see my answer on how to synchronize the timing between network connection and access: https://stackoverflow.com/a/52304308/4969370

Androbin
  • 991
  • 10
  • 27
0

I figured 2 main issues with Android connecting to ESP8266 or ESP32 hotspot. I was using AP-STA dual mode. I read up that since ESP8266 and ESP32 have single radio handling AP and STA the connection will be fragile and not very stable which is why my android device was getting disconnected from AP during configuration.

The solve for this is keep the ESP* device in SOFT_AP mode during configuration and STA mode when its connected to the Access point and never in AP-STA dual mode. This completely solve my stability issues.

thehellmaker
  • 162
  • 3
  • 13