Android Question ML WiFi 4.3 connection issue

Nitin Joshi

Active Member
Licensed User
Hi, My project was working very well when i was using MLWiFi library 3.08 and manifest editor had below sdkversion range.
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="27"/>

Today, I have updated MLWiFi lbirary to 4.3 and updated manifest editor as below...
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>

As per new requirement of ML WiFi library V4.3 to connect SSID, i have updated code in my project as well. (Code is given for the reference

I am facing 2 issues..

1) Enabling WiFi APP does not enable WiFi
2) Connect WiFi : Whenever i try to connect any SSID, my phone throws below error as attached screenshot.
Note; Before this error, a momentarily message flashes (it is very difficult to note as message flashes for fraction of second). I think message has 3 options, Cancel - Save - Connect

My mobile Android version is 10.

Connect WiFi Code:
Sub btnConnect_Click
    If WiFi.isWifiEnabled=False Then
        WiFi.EnableWifi(True)
    End If
    WiFi.saveWifiAP("Joshi",2,"123456",false,60000)
    WiFi.connectWifiAP("Joshi",2,"123456",60000)
End Sub
 

Attachments

  • 2. Error Message while connecting SSID.jpeg
    2. Error Message while connecting SSID.jpeg
    18.5 KB · Views: 365

Computersmith64

Well-Known Member
Licensed User
Longtime User
I am facing 2 issues..

1) Enabling WiFi APP does not enable WiFi
Apps targeting Q+ can't enable Wifi - so for Q+ devices I don't think it will work at all & for devices running P-, you would have to change your targetSdkVersion to 28 or lower.

2) Connect WiFi : Whenever i try to connect any SSID, my phone throws below error as attached screenshot.
Note; Before this error, a momentarily message flashes (it is very difficult to note as message flashes for fraction of second). I think message has 3 options, Cancel - Save - Connect

My mobile Android version is 10.

Connect WiFi Code:
Sub btnConnect_Click
    If WiFi.isWifiEnabled=False Then
        WiFi.EnableWifi(True)
    End If
    WiFi.saveWifiAP("Joshi",2,"123456",false,60000)
    WiFi.connectWifiAP("Joshi",2,"123456",60000)
End Sub

Is the AP you're trying to connect to connected to the internet? If so, try using saveWifiAP & set the connect parameter to true. If not, use connectWifiAP. Don't use both.

- Colin.
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
s the AP you're trying to connect to connected to the internet? If so, try using saveWifiAP & set the connect parameter to true. If not, use connectWifiAP. Don't use both.

Dear Colin, I already tried to use only .connectWiFiAP. In fact, I tried all options still mobile throws the error. Please see attached picture after mobile throws error.

By the way, AP is not connected to internet.
 
Last edited:
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
What runtime permissions are you requesting? Without seeing the rest of the relevant code it's hard to say what the problem is. Can you upload a small project that reproduces the issue?

- Colin.
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
Dear Colin,
Point well noted....

I have attached simple sample project with screen shot of manifest editor. Please check and help to resolve the problem, thank you.
 

Attachments

  • 2. Manifest Editor.JPG
    2. Manifest Editor.JPG
    50.9 KB · Views: 258
  • 2. Wifi_Connection_V1.zip
    12.3 KB · Views: 278
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Dear Colin,
Point well noted....

I have attached simple sample project with screen shot of manifest editor. Please check and help to resolve the problem, thank you.

Connects fine on my test device (Nokia 6.2 running Android Q) connecting to an ESP8266 AP with no internet, using WPA2/PSK security. The only thing I changed in your code was the ssid & password.

Having said that, your code:
B4X:
Sub btn_Save_Click
    lblStatus.Text=""
    WiFi.connectWifiAP("DispenserAP",2,"dispenser",60000)
    If WiFi.isWifiConnected And WiFi.WifiSSID="Joshi" Then lblStatus.Text="Wifi Connected"
End Sub
is not correct if you want a properly functioning implementation. You need to go back & read the first post in the library thread - particularly the part about the ConnectionResult callback.

Also, you might want to set WiFi.debug = true to help you figure out why it's not working in your case.

Oh - & you don't need:
B4X:
AddPermission(android.permission.CHANGE_NETWORK_STATE)
AddPermission(android.permission.CHANGE_WIFI_STATE)
in the manifest as those permissions are already taken care of in the library.

- Colin.
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
Dear Colin,
Thanks for your efforts!

Which B4A version was used by you? As I am using Beta 10.5. May be this is the reason for not working? If yes then how do i rollback to 10.2?

Also, you might want to set WiFi.debug = true to help you figure out why it's not working in your case.

Where do i set WiFi.debug=true?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Dear Colin,
Thanks for your efforts!

Which B4A version was used by you? As I am using Beta 10.5. May be this is the reason for not working? If yes then how do i rollback to 10.2?



Where do i set WiFi.debug=true?
I'm also using B4A 10.5. You set WiFi.debug = true in your code after you have initialized your WiFi object.

- Colin.
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
My recent observation is....I get the message connection successful but within second i get message "Something went wrong. Unable to select device"

attached is the screen shot.
 

Attachments

  • 2. Error Message while connecting SSID.jpeg
    2. Error Message while connecting SSID.jpeg
    18.5 KB · Views: 264
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
My recent observation is....I get the message connection successful but within second i get message "Something went wrong. Unable to select device"

attached is the screen shot.
Are you running the test code you uploaded, or your full app? I'd recommend you set WiFi.debug = true & then look at the logs from the library.

- Colin.
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
Dear Colin,
I am using same APP which was uploaded. I have attached screen recording for you, please check.

By the way, why I have to forcefully press connect button to connect the "Joshi" SSID? [Even though APP does not connect to WiFi. You can see in video.]

Beside this, below is the log after WiFi.debug=true is set in my code.

Logger connected to: HUAWEI BKL-L09
--------- beginning of system
--------- beginning of main
** Activity (main) Resume **
SDK: 29
[MLwifi] (Q+) Connecting to Joshi
** Activity (main) Pause, UserClosed = false **
 

Attachments

  • 2. Video Recording.zip
    397.4 KB · Views: 274
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Dear Colin,
I am using same APP which was uploaded. I have attached screen recording for you, please check.

By the way, why I have to forcefully press connect button to connect the "Joshi" SSID? [Even though APP does not connect to WiFi. You can see in video.]

Beside this, below is the log after WiFi.debug=true is set in my code.

Logger connected to: HUAWEI BKL-L09
--------- beginning of system
--------- beginning of main
** Activity (main) Resume **
SDK: 29
[MLwifi] (Q+) Connecting to Joshi
** Activity (main) Pause, UserClosed = false **
Check the Wifi preferences on your test device. Make sure there isn't an option turned on that will cause the device to switch networks if it connects to one without an internet connection.

I have 2 Android Q devices (Nokia 6.2 & Pixel) & they both work fine with this library, so your issue seems to be related to your Huawei device or your AP.

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Actually, stepping through the video it looks to me like you're trying to connect twice. The first attempt is successful & then immediately after, the connection dialog appears again, before the "something went wrong" dialog appears.

Can you clarify what you mean by:
By the way, why I have to forcefully press connect button to connect the "Joshi" SSID? [Even though APP does not connect to WiFi. You can see in video.]

- Colin.
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
Actually, stepping through the video it looks to me like you're trying to connect twice.
No Colin, i am connecting one time only.

Can you clarify what you mean by:
When I click Connect WiFi button, function .connectWIFi triggers to connect SSID (Joshi). I believe, it should automatically connect to desire SSID however I get pop up message "Device to use with WiFi connect" which has Cancel and Connect options. I have to press Connect to connect SSID Joshi. Please see attached screenshot.

Meanwhile, i will check wifi setting and will check, thank you.
 

Attachments

  • Screenshot_20210105_084252_com.huawei.himovie.overseas.jpg
    Screenshot_20210105_084252_com.huawei.himovie.overseas.jpg
    292.3 KB · Views: 237
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
When I click Connect WiFi button, function .connectWIFi triggers to connect SSID (Joshi). I believe, it should automatically connect to desire SSID however I get pop up message "Device to use with WiFi connect" which has Cancel and Connect options. I have to press Connect to connect SSID Joshi. Please see attached screenshot.

There have been multiple references to this behavior in the various discussions regarding this version of the library & in one or two other threads related to it. This is the expected (normal) behavior for devices running Q+. As I have stated on several occasions, there are significant differences in the way WiFi is handled since Android Q. You should look at the Android Developer documentation to bring yourself up to speed on what to expect on Q+ devices & then test with that in mind. What you see happening on P- devices is very different to what you will see on Q+.

No Colin, i am connecting one time only.
If you step frame-by-frame through your video you will see that immediately after the device connects to the AP, the connection dialog goes away & then another connection dialog immediately pops up, followed by the error dialog. There seems to be something causing a second connection attempt. Do you have other Android Q devices you can test on? I think you can test on the emulator too (although I can't remember tbh).

- Colin.
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
Do you have other Android Q devices you can test on?
Unfortunately, I do not have any other Android device having Q version. Meanwhile, I tried 2 things...
1) I did trial and error with all possible WiFi settings. (even tried with default setting)
2) I switched off all devices connected to AP, reset router and tried to connect single device.

None of the above option worked.

My phone has other project's APPs installed which are developed on ML WiFi library version 3.0. Can it be the reason?

I am really clueless and unable to understand what could be the reason. Please help me, thanks.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Unfortunately, I do not have any other Android device having Q version. Meanwhile, I tried 2 things...
1) I did trial and error with all possible WiFi settings. (even tried with default setting)
2) I switched off all devices connected to AP, reset router and tried to connect single device.

None of the above option worked.

My phone has other project's APPs installed which are developed on ML WiFi library version 3.0. Can it be the reason?

I am really clueless and unable to understand what could be the reason. Please help me, thanks.

I doubt that the other apps will be causing your issues. Have you looked at the unfiltered logs when you're running the app? That might give you a clue. The issue isn't that your device isn't connecting. If you look at the video, it definitely connects but then tries to connect again - which appears to be the reason for the disconnect. Is the code you're running the EXACT SAME code as you uploaded to here?

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Also, one small difference I notice between your device & mine: In the "Device to use with WiFi Connect" dialog, your's says "Joshi" & underneath says "Saved, encrypted". Mine just says "Saved" under the AP name. What encryption is your AP set up with? Have you tried without any encryption - ie" setting up the AP as open with no password?

- Colin.
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
Finally, I have moved an inch as i could connect to SSID but have some queries.

Meanwhile, my project involves 2 types of WiFi connections, 1. home wifi network 2. ESP8266 which is behaving as AP

Now before queries, let me tell you what i did to make connection successful. I changed my home wifi routers security type from "WPA-PSK/WPA2-PSK AES" to "WPA2-PSK(AES)"

Now my queries...

1) How do i connect to ESP8266 AP?
2) Why APP pops up with option Cancel and Connect? How can APP connect to SSID without prompt Cancel/Connect?
3) How do i connect to home wifi router wherein user wants to set security type "WPA-PSK/WPA2-PSK AES". It inappropriate to tell users to change home wifi security type.

Aside this: Can you share me code to detect connection successful? Below code does not work.
Wifi connection successful:
If WiFi.isWifiConnected And WiFi.WifiSSID=txtSSID.Text Then lblStatus.Text="Wifi Connected"
 
Upvote 0
Top