hoerresb / WifiWizard

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

WifiWizard.connectNetwork always fires success #53

Open jorisw opened 8 years ago

jorisw commented 8 years ago

When I call WifiWizard.connectNetwork(), it fires the success callback even if I add a random network that's not mine, with a random passphrase. Running 0.2.11 on Android 4.1.1. My code:

if(typeof window.WifiWizard !== "undefined") {

    WifiWizard.addNetwork(WifiWizard.formatWPAConfig(networkName, passPhrase), function(){

        console.log("Added network '"+networkName+"' to the list of known networks.");

        WifiWizard.connectNetwork(networkName, function(){

            console.log("Connected to network '"+networkName+"'."); // Always logged

        },function(err){

            console.log("Failed to join network '"+networkName+"'.",err);

            deferred.reject('notConnected');

        });

    }, function(err){

        console.log("Failed to add network '"+networkName+"'.",err);

        deferred.reject('errorAddingNetwork');

    });

}else{
    deferred.reject('Wifi Wizard plugin not available.');
}
jorisw commented 8 years ago

The behavior seems to be different in 0.2.10. There, connectNetwork properly calls the error callback, but the error message is empty, not allowing me to distinguish authentication failed from connection failed.

hoerresb commented 8 years ago

I'm working on an actual fix for this issue but it needs further testing, at least for WPA networks. The idea is Android at any given time lets you access the WPA supplicant state. When entering a wrong network key the supplicate state should attempt to handshake and then disconnect.

Thanks for bearing with me on this. It's a pretty huge issue right now but not the easiest to fix.

vicatcu commented 7 years ago

@hoerresb any update on this, I too find myself wanting to know whether or not I have actually successfully connected, or otherwise, when I have failed to do so, after calling connectNetwork...

arsenal942 commented 7 years ago

@hoerresb Please can we get some form of an update regarding this. The success callback should only be triggered if the network specified was successfully connected to and not if the plugin just worked. It is really annoying having to implement a workaround. I am using version 0.2.11 (WifiWizard) and the Android version seems to be irrelevant.

For those interested I implement a wait of 5 seconds in the success callback which then compares the currently connected SSID with the specified one that was to be connected to. If they match, I assume the connection has worked and move the user onto the next stage and if they don't, I ask them to re-connect.