MohsenSaber2019
Member
Hi All.
i wrote an app that connects to my ESP8266 local web server. everythings is ok on Android 4.4.2 .
But in Android 7+ i'm facing a boring problem!
I have written a function (named NetCheck) whose function is to check the status of the network. If the connected network is not the network that I want, it will try to make the necessary changes to successfull connect. This function works well on all versions of Android(4 ~ 10). here is the code:
After making sure I am on the desired network, I will call the second function (called Connect ). This function must call a URL from ESP8266. If there is no change in the status of the network, this function also works well.here is the code:
Problem
If I manually disconnect the connection from the WiFi network and re-call the Netcheck function, the first step is done correctly and the connection to the ESP8266 network is restored. But the second function(Connect) does not work properly. In fact, in response to my request, it returns the following error:
So, what i can do?
Notice: The problem is not seen on Android 4.4!
Thank you in advance for your participation.
i wrote an app that connects to my ESP8266 local web server. everythings is ok on Android 4.4.2 .
But in Android 7+ i'm facing a boring problem!
I have written a function (named NetCheck) whose function is to check the status of the network. If the connected network is not the network that I want, it will try to make the necessary changes to successfull connect. This function works well on all versions of Android(4 ~ 10). here is the code:
NetCheck:
Sub NetCheck
SetStatus(False)
If Main.ssidn="" And Main.ssidp="" Then
Tm_Chck.Enabled = False
Activity.Finish()
StartActivity(Main)
Else
If MyWifis.isWifiEnabled()==False Then
MyWifis.EnableWifi(True)
If MyWifis.APIversion > 25 Then
Sleep(4000)
End If
End If
If MyWifis.isSavedWifiAP(Main.ssidn) == False Then
MyWifis.saveWifiAP(Main.ssidn,2,Main.ssidp,False)
End If
If MyWifis.connectWifiAP(Main.ssidn) == False Then
MyWifis.saveWifiAP(Main.ssidn,2,Main.ssidp,True)
End If
Log(MyWifis.WifiSSID)
If MyWifis.WifiSSID==Main.ssidn Then
Sleep(500)
Connect
Tm_Chck.Enabled = False
Else
Tm_Chck.Enabled = True
End If
End If
End Sub
After making sure I am on the desired network, I will call the second function (called Connect ). This function must call a URL from ESP8266. If there is no change in the status of the network, this function also works well.here is the code:
Connect:
Sub Connect
AllowJb1 = False
Dim job_connect As HttpJob
job_connect.Initialize("Connect",Me)
job_connect.Download(Login.Df_Serv)
Log(Login.Df_Serv)
job_connect.GetRequest.Timeout = 2000
Wait for (job_connect) JobDone(job_connect As HttpJob)
If job_connect.Success Then
AllowJb1 = True
Dim Response As String = ""
Try
Response = job_connect.GetString
Catch
Log(LastException)
End Try
If Response.Contains("*Status ========================") Then
Successful_Login
End If
Else
AllowJb1 = True
End If
job_connect.Release
End Sub
Problem
If I manually disconnect the connection from the WiFi network and re-call the Netcheck function, the first step is done correctly and the connection to the ESP8266 network is restored. But the second function(Connect) does not work properly. In fact, in response to my request, it returns the following error:
B4X:
ResponseError. Reason: java.net.SocketException: Machine is not on the network, Response:
So, what i can do?
Notice: The problem is not seen on Android 4.4!
Thank you in advance for your participation.