hoerresb / WifiWizard

A Cordova plugin for managing Wifi networks
Apache License 2.0
205 stars 176 forks source link

WifiWizard.connectNetwork calls win callback even if wifi network is unavailable #31

Closed untitledlt closed 9 years ago

untitledlt commented 9 years ago

First thanks for a great plugin! Here is my code:

var onSuccessConnectToNetwork = function (result) {
    console.log(result);
};
var onFailConnectToNetwork = function (result) {
    console.log(result);
};
WifiWizard.connectNetwork('mySSID', onSuccessConnectToNetwork, onFailConnectToNetwork);

If I disable my wireless access point, provide wrong credentials, it still says Network "mySSID" connected!. onFailConnectToNetwork gets called only if I disable wireless connection on my phone. Is it possible to get actual connection result?

hoerresb commented 9 years ago

I would try to add the network first. For example, for WPA this is how I connect to the network.

                var wifi_network = WifiWizard.formatWifiConfig(ssid, 'password', 'WPA');
                WifiWizard.addNetwork(wifi_network, function (win) {
                    WifiWizard.connectNetwork(ssid, function (win) {
                        console.log(win);
                         // connection worked
                    }, function (fail) {
                       console.log(fail);
                       // connection failed.
                    });
                }, function (fail) {
                    console.log(fail);
                    // add network failed. 
                });

Also, please note this functionality is only available on android.

untitledlt commented 9 years ago

Thanks for answer! Network is added and phone connects to network successfully after few seconds if credentials are ok and AP is available. The problem is that plugin calls win without waiting for actual connection establishment. And yes, I am using Android on two of my phones.

parsonsmatt commented 9 years ago

Thanks for bringing this up! The Java code will return success whenever the network ID is found, and in fact only disables and reenables the network: code here

We'll probably want to include a loop in there which polls the current connection status, and returns true/false based on whether it actually connected.

untitledlt commented 9 years ago

I tried to implement this in Javascript with getCurrentSSID in loop, but it returns last used ssid even after disconnecting from network. How could I check the current connection status?

fenwick67 commented 9 years ago

@parsonsmatt maybe consider just adding a javascript interface for Android's ConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI) so people can check the network status themselves.

jorisw commented 9 years ago

+1 on this one.

I'm doing a WifiWizard.addNetwork() with a correct SSID but with an invalid passphrase.

A call from inside the addNetwork success callback, to WifiWizard.connectNetwork('mySSID',successCallback,errorCallback), immediately fires the successCallback, not giving me a chance to bring up an 'Invalid passphrase' message to the user. errorCallback is never fired.

hoerresb commented 9 years ago

We have a fix for this comming. I will push an update out soon since this has been a known issue for a while.

talpasco commented 8 years ago

Any update on this? Still doesn't work...

masoumiaa commented 7 years ago

When I use a correct SSID and a wrong Password, It always call successCallback ! Any update on this ?

sudhan-ionic commented 7 years ago

hai @hoerresb

var wifi_network = WifiWizard.formatWifiConfig(ssid, 'password', 'WPA');
                WifiWizard.addNetwork(wifi_network, function (win) {
                    WifiWizard.connectNetwork(ssid, function (win) {
                        console.log(win);
                         // connection worked
                    }, function (fail) {
                       console.log(fail);
                       // connection failed.
                    });
                }, function (fail) {
                    console.log(fail);
                    // add network failed. 
                });

var wifi_network = WifiWizard.formatWifiConfig(ssid, 'password', 'WPA'); instead of 'WPA' what must be replace in that place WifiWizard documentation instead of 'WPA' they using algorithm can you pls help me

ghost commented 6 years ago

Still doesn't work... Is there any fix ?