How to use android to connect to an ESP8266 access point without internet in a stable way?

梦想与她 提交于 2019-12-22 17:38:19

问题


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


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/38934906/how-to-use-android-to-connect-to-an-esp8266-access-point-without-internet-in-a-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!