1

I would like to know how to write validations for the password protected wifi lists. I'm using WifiWizard plugin to connect basically but it is not connecting all the networks(especially password protected). So I would like to know how to write code for the password protected wifi lists. I'm also using Network Information plugin to register the networkSSID and I'm also using InAppBrowser to connect to the browser after passing the validations.

learner
  • 177
  • 19

1 Answers1

1

I have wrote a sample cordova app that helps in starting the wifi, search and scan for available wifi networks and connect to a particular password protected network. The code is follows:

index.html:

<!DOCTYPE html>
    <head>
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Wifi Wizard</title>
    </head>
    <body>      
        <br>        
        <br>
        Start Wifi <input type="button" value="wifi" name="Wifi" id="wifi"/>     <br>
        Search Wifi <input type="button" value="search" name="Search" id="search"/>  <br>
        Scan Wifi <input type="button" value="scan" name="Scan" id="scan"/>  <br>
        Connect Wifi <input type="button" value="connect" name="Connect" id="connect"/>  <br>
        <script type="text/javascript" src="js/jquery.js"></script> 
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/app.js"></script>
    </body>
</html>

app.js:

$(document).ready(function() {
    document.addEventListener("deviceready", onDeviceReady, false);
});

function onDeviceReady() {      
     $('#wifi').click( function() 
        {   
            try {               
                WifiWizard.isWifiEnabled(win, fail);
            }
            catch(err) {
                alert("Plugin Error - " + err.message);
            }

        }); 

    function win(e) {
        if(e) {
            alert("Wifi enabled already");
        }
        else {
            WifiWizard.setWifiEnabled(true, winEnable, failEnable);
        }

    }

    function fail(e) {
        alert("Error checking Wifi status");
    }

    function winEnable(e) {
        alert("Wifi enabled successfully");
    }

    function failEnable(e) {
        alert("Error enabling Wifi ");
    }

    $('#search').click( function() 
        {   
            try {               
                WifiWizard.listNetworks(listHandler, fail);
            }
            catch(err) {
                alert("Plugin Error - " + err.message);
            }

        }); 

    function listHandler(a){
        alert(a);
    }

    $('#scan').click( function() 
        {   
            try {               
                WifiWizard.getScanResults({numLevels: 1},listHandler1, fail);
            }
            catch(err) {
                alert("Plugin Error - " + err.message);
            }

        });

    function listHandler1(a){
        alert(JSON.stringify(a));
    }

    $('#connect').click( function() 
        {   
            try {   
                var config = WifiWizard.formatWPAConfig("NETWORK_NAME", "PASSWORD");
                WifiWizard.addNetwork(config, function() {
                    WifiWizard.connectNetwork("NETWORK_NAME");
                });             
            }
            catch(err) {
                alert("Plugin Error - " + err.message);
            }

        });

    function connectSuccess(e)
    {
        alert("Connect success");
    }

}
Gandhi
  • 11,875
  • 4
  • 39
  • 63
  • @G, could u please tell me how to change alert(json.stringfy(a)) to a continous row network display. – learner Jun 21 '16 at 06:28
  • @RSN This should do - http://stackoverflow.com/questions/17066636/parsing-json-objects-for-html-table Please accept the answer if it was helpful so that others get benefited too – Gandhi Jun 21 '16 at 08:04
  • WifiWizard.getScanResults({numLevels: 1},listHandler1, fail) what is that numLevels, what does it do? – learner Jun 21 '16 at 08:29
  • @RSN Currently, the only supported option is numLevels, and it has the following behavior: if (n == true || n < 2), *.getScanResults({numLevels: n}) will return data as before, split in 5 levels; if (n > 1), *.getScanResults({numLevels: n}) will calculate the signal level, split in n levels; if (n == false), *.getScanResults({numLevels: n}) will use the raw signal level; – Gandhi Jun 21 '16 at 08:36
  • @RSN More info on https://github.com/parsonsmatt/WifiWizard WifiWizard.getScanResults section. Please do upvote the answer :) – Gandhi Jun 21 '16 at 08:37
  • G, the example site you gave for json data is actually they bind the data from a variable but how to do for my case. – learner Jun 21 '16 at 08:45
  • @RSN The object 'a' is you json. iterate over it as shown in the link – Gandhi Jun 21 '16 at 08:50
  • k they have binded even some names with the json am I suppose to do like that – learner Jun 21 '16 at 08:53
  • @RSN They have not binded anything. They are trying to fetch name attribute from JSON. You can fetch whatever is required for your from the JSON like SSID, name etc.. Please try to understand the basics of anything before gettin deep into it. – Gandhi Jun 21 '16 at 08:56
  • G, if I put in json as you said to look in another site, will I actually get the password window if I click on the wifi link. – learner Jun 21 '16 at 09:41
  • @RSN I dont understand what you are really trying to do – Gandhi Jun 21 '16 at 10:18
  • As I just click a password protected wifi network it should ask us for the password to connect to it, as in smart phones when you click on a wifi link, a pop up window shows up asking u for a password, thats the same thing I need. – learner Jun 21 '16 at 10:29
  • @RSN Have not tested the functionality. Instead i added the network with required password and directly connected programmatically – Gandhi Jun 21 '16 at 10:39
  • i cant understand the concept you did here, so if i click on a network will I get the password pop up window to connect and if i provide the correct password will it connect or can u tell me how to put a window that asks for the password. – learner Jun 21 '16 at 10:49
  • @RSN My implementation is different. It wont prompt password manually. It does everthing programatically.If your requirement is to prompt password, i need to dig further – Gandhi Jun 21 '16 at 10:55
  • so what does this do, whether it has the ability to connect through a password if I click on a wifi network and when I ran the sample I got no idea to which network it got connected – learner Jun 21 '16 at 11:00
  • @RSN Whatever SSID you specified in connect network, it will connect to that particular network. Please try to understand the code before trying to enhance it – Gandhi Jun 21 '16 at 11:47
  • ok, what if Im selecting a new one which is not included or connected. If I make a password pop up window and if I use these functions will it try to connect or will it not work – learner Jun 21 '16 at 12:10