devstepbcn/react-native-android-wifi

Cannot connect to WIFI if I first enter wrong password and after that try with correct one

Opened this issue · 4 comments

I use next code to connect to WIFI

wifi.findAndConnect(ssid, password, (found) => {
  if (found) {
    console.log("wifi is in range");
  } else {
    console.log("wifi is not in range");
  }
});

First i tried with wrong password and I see message "wifi is in range"
But I never connected of course and this is expected result.
After that i tried to enter correct password and I see same message but i never connected to wifi which is unexpected result.
If I enter correct password in the very beginning when i open my app it works correctly.
Do you have any idea why I cannot connect to wifi after first try with wrong password and after that with correct one

gigby commented

@anton-shumanski
This is expected behavior I think. First time when you connect to some network with the wrong password this module create a native config with your wrong password then second connection this module uses already created the config. "wi-fi in range" been called due to this function (findAndConnect) return just simple result is there such wi-fi network or not, independently of your password. If there is such network then ok, will be returned TRUE.

Ok so in that case how I can set right password and connect to wifi?

gigby commented

@anton-shumanski
Just use wifi.isRemoveWifiNetwork() as it described in readme

@gigby I already tested even before I open the issue. It does not work.
I do not know how to detect that the password is wrong and just after 30 sec I check if I am connected to wifi and if I am not I just execute isRemoveWifiNetwork and after that in the callback I try to connect again with the correct password. Even using that approach I cannot connect successfully.