hoerresb / WifiWizard

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

getCurrentSSID is working on IOS device but not on Xcode Simulator #41

Closed peli44 closed 9 years ago

peli44 commented 9 years ago

I can run getCurrentSSID on a device with an app downloaded from Xcode. But I get "Not available" running the same code on a simulator. The device and the Mac running the simulator are connected to the same WiFi.

hoerresb commented 9 years ago

I don't have a very good explanation for why the plugin won't work on a simulator, but this behavior is to be expected. Simulator APIs don’t have all the features that are available on a device and I suspect the wifi API is one of them.

peli44 commented 9 years ago

I tried som of the other functions too. But didnt have so much success. I tested them on a Samsung phone. getCurrentSSID and isWifiEnabled are working ok

But I cant get setWifiEnabled(true) to work. It will not switch on the WiFi

neither is connectNetwork working.

Maybe I use them in some bad way or have forgotten something.

Do you have any simple example showing how to use them. I just want to be sure ths WiFi is on and that the phone is connected to the network with the SSID Textning.

/Per

Per Liljeqvist mail: per.liljeqvist@gmail.com mobile: +46 70 6697558 web: www.dogood.se

28 sep 2015 kl. 17:23 skrev hoerresb notifications@github.com:

I don't have a very good explanation for why the plugin won't work on a simulator, but this behavior is to be expected. Simulator APIs don’t have all the features that are available on a device and I suspect the wifi API is one of them.

— Reply to this email directly or view it on GitHub https://github.com/parsonsmatt/WifiWizard/issues/41#issuecomment-143775954.

hoerresb commented 9 years ago

Is the still for ios? Unfortunately, the only functionality for ios is getCurrentSSID. On Sep 28, 2015 7:40 PM, "peli44" notifications@github.com wrote:

I tried som of the other functions too. But didnt have so much success. I tested them on a Samsung phone. getCurrentSSID and isWifiEnabled are working ok

But I cant get setWifiEnabled(true) to work. It will not switch on the WiFi

neither is connectNetwork working.

Maybe I use them in some bad way or have forgotten something.

Do you have any simple example showing how to use them. I just want to be sure ths WiFi is on and that the phone is connected to the network with the SSID Textning.

/Per

Per Liljeqvist mail: per.liljeqvist@gmail.com mobile: +46 70 6697558 web: www.dogood.se

28 sep 2015 kl. 17:23 skrev hoerresb notifications@github.com:

I don't have a very good explanation for why the plugin won't work on a simulator, but this behavior is to be expected. Simulator APIs don’t have all the features that are available on a device and I suspect the wifi API is one of them.

— Reply to this email directly or view it on GitHub < https://github.com/parsonsmatt/WifiWizard/issues/41#issuecomment-143775954 .

— Reply to this email directly or view it on GitHub https://github.com/parsonsmatt/WifiWizard/issues/41#issuecomment-143911666 .

peli44 commented 9 years ago

No I am running it on an Android device a Samsung Galaxy.

/Per

Per Liljeqvist mail: per.liljeqvist@gmail.com mobile: +46 70 6697558 web: www.dogood.se

29 sep 2015 kl. 03:16 skrev hoerresb notifications@github.com:

Is the still for ios? Unfortunately, the only functionality for ios is getCurrentSSID. On Sep 28, 2015 7:40 PM, "peli44" notifications@github.com wrote:

I tried som of the other functions too. But didnt have so much success. I tested them on a Samsung phone. getCurrentSSID and isWifiEnabled are working ok

But I cant get setWifiEnabled(true) to work. It will not switch on the WiFi

neither is connectNetwork working.

Maybe I use them in some bad way or have forgotten something.

Do you have any simple example showing how to use them. I just want to be sure ths WiFi is on and that the phone is connected to the network with the SSID Textning.

/Per

Per Liljeqvist mail: per.liljeqvist@gmail.com mobile: +46 70 6697558 web: www.dogood.se

28 sep 2015 kl. 17:23 skrev hoerresb notifications@github.com:

I don't have a very good explanation for why the plugin won't work on a simulator, but this behavior is to be expected. Simulator APIs don’t have all the features that are available on a device and I suspect the wifi API is one of them.

— Reply to this email directly or view it on GitHub < https://github.com/parsonsmatt/WifiWizard/issues/41#issuecomment-143775954 .

— Reply to this email directly or view it on GitHub https://github.com/parsonsmatt/WifiWizard/issues/41#issuecomment-143911666 .

— Reply to this email directly or view it on GitHub https://github.com/parsonsmatt/WifiWizard/issues/41#issuecomment-143916623.

hoerresb commented 9 years ago

ok. Here is some example code. This code checks for wifiWizard, then checks is the wifi is enabled. If wifi is not enabled we enable it. Let me know if this is of any help. Thanks

  if(typeof WifiWizard != 'undefined'){
            if(WifiWizard.isWifiEnabled(function(result){
                    if(result){
                       //wifi is connected
                    }else{
                        WifiWizard.setWifiEnabled(true,function(results){
                            if(results == 'OK'){
                                //enabled wifi 
                            }
                        },function(fail){
                               //error message for setWifiEnabled
                            console.log(fail);
                        });
                    }

                },function(fail){
                    //error message for isWifiEnabled 
                }));
        }
peli44 commented 9 years ago

I tested your program. Added some alerts to see what is happening.

if(typeof WifiWizard != 'undefined'){ alert ("WiFiWizard exist"); if(WifiWizard.isWifiEnabled(function(result){ if(result){ //wifi is connected alert ("WiFi connected"); }else{ alert ("WiFi not connected"); WifiWizard.setWifiEnabled(true,function(results){ alert ("Enable results="+results); if(results == 'OK'){ alert ("WiFi Enabled") //enabled wifi }

                    },function(fail){
                           //error message for setWifiEnabled
                           alert ("Error enabling WiFi")
                        console.log(fail);
                    });
                }

            },function(fail){
                //error message for isWifiEnabled 
            }));

        }

With WiFi enabled I get the output : WiFIWizard exist, WiFi connected. With WiFi disabled I get the output: WiFI Wizard exist, WiFi not connected. Nothing more. I had expected to get Enable results = OK (or something else) or Error enabling WiFi. But I get none of them. So in some way setWifiEnabled isn’t working. Have you any idea why?

Per Liljeqvist

mobil: +46 70 6697558 mail: per.liljeqvist@gmail.com www.dogood.se

29 sep 2015 kl. 05:07 skrev hoerresb notifications@github.com:

if(typeof WifiWizard != 'undefined'){ if(WifiWizard.isWifiEnabled(function(result){ if(result){ //wifi is connected }else{ WifiWizard.setWifiEnabled(true,function(results){ if(results == 'OK'){ //enabled wifi } },function(fail){ //error message for setWifiEnabled console.log(fail); }); }

            },function(fail){
                //error message for isWifiEnabled 
            }));
    }
hoerresb commented 9 years ago

I've been trying to replicate your bug but I cannot. I tested this exact code on a samsung galaxy s4 running android 5.0.1 and it works as intended. I'm not exactly sure at the moment why the code would not get executed as you described.

are you running the latest version of WifiWizard v 0.2.9?

peli44 commented 9 years ago

Funny . I am also running the Galaxy s4 with 5.0.1.

I have been tested it a bit more. From what I can see it must be some timing problem. But I don’t know what it is. I will send you the last code I have used. I put some alerts in the code to test what could go wrong. When I inserted the alert (hit 3) it never fails. Removing it I sometimes get problems. Then getCurrentSSID or connectNetwork won’t work as they should. I think they are not excecuted I never get to the result functions. With alert (hit 3) active it never fails.

Is it always working for you? And you hav removed all the alerts?

One interesting thing was that getCurrentSSID had the output ”Textning” and not Textning without the ”:s. Why is it so? No problem when you know it, else a bit confusing.

Thanks for helping me to look into this. I still feel a bit confused and insecure. I know I have understood the functionality and how to write the program but as it is not always working correct I don’t know what to do.

I will test it a bit more to see if I can find why its working like this. Maybe I have som other problem in my total code that will interfere. The code I send you is included in a system that we are using. We haven’t had this kind of control before we have always relied on that the user configure the WiFi in a correct way. And as it is not possible to use it for IOS or Windows phone I am not sure how we will do. I know its not possible to use it for IOS have you looked into Windows Phone and if you can implement the funcionaity there?

/Per

        WifiWizard.isWifiEnabled(function(result)
            {
               if(result)
               {
                  //alert ("WiFi enabled");
                  WifiWizard.getCurrentSSID(function(ssid)
                   {
                    //alert("Current SSID="+ssid);
                    if (ssid =='"Textning"')
                    {
                        //alert ("Textning connected")
                    }
                    else
                    {
                        //alert (”Connect tol Textning")
                        WifiWizard.connectNetwork("Textning", function(s)
                        {
                        //alert (”Connected to ="+s)
                        }
                        , function(e)
                        {
                            //alert ("Error connectNetwork="+e)
                        }
                        );
                    }
                   }
                   ,fail);
                }
                else
                {
                    //alert ("WiFi not enabled");
                    WifiWizard.setWifiEnabled(true, win, fail);

                }

            },function(f)
            {
                alert ("Error isWifiEnabled="+f) 
            }
            );

    //alert ("hit 3”)

    function fail()
    {
        alert ("fail")
    }//fail

    function win(s)
    {
        //alert (”Connected="+s)
    }

Per Liljeqvist

mobil: +46 70 6697558 mail: per.liljeqvist@gmail.com www.dogood.se

30 sep 2015 kl. 00:17 skrev hoerresb notifications@github.com:

I've been trying to replicate your bug but I cannot. I tested this exact code on a samsung galaxy s4 running android 5.0.1 and it works as intended. I'm not exactly sure at the moment why the code would not get executed as you described.

are you running the latest version of WifiWizard v 0.2.9?

— Reply to this email directly or view it on GitHub https://github.com/parsonsmatt/WifiWizard/issues/41#issuecomment-144206913.

peli44 commented 9 years ago

And I am using 0.2.9

/Per

Per Liljeqvist

mobil: +46 70 6697558 mail: per.liljeqvist@gmail.com www.dogood.se

30 sep 2015 kl. 00:53 skrev Per Liljeqvist per.liljeqvist@gmail.com:

Funny . I am also running the Galaxy s4 with 5.0.1.

I have been tested it a bit more. From what I can see it must be some timing problem. But I don’t know what it is. I will send you the last code I have used. I put some alerts in the code to test what could go wrong. When I inserted the alert (hit 3) it never fails. Removing it I sometimes get problems. Then getCurrentSSID or connectNetwork won’t work as they should. I think they are not excecuted I never get to the result functions. With alert (hit 3) active it never fails.

Is it always working for you? And you hav removed all the alerts?

One interesting thing was that getCurrentSSID had the output ”Textning” and not Textning without the ”:s. Why is it so? No problem when you know it, else a bit confusing.

Thanks for helping me to look into this. I still feel a bit confused and insecure. I know I have understood the functionality and how to write the program but as it is not always working correct I don’t know what to do.

I will test it a bit more to see if I can find why its working like this. Maybe I have som other problem in my total code that will interfere. The code I send you is included in a system that we are using. We haven’t had this kind of control before we have always relied on that the user configure the WiFi in a correct way. And as it is not possible to use it for IOS or Windows phone I am not sure how we will do. I know its not possible to use it for IOS have you looked into Windows Phone and if you can implement the funcionaity there?

/Per

          WifiWizard.isWifiEnabled(function(result)
          {
               if(result)
               {
                  //alert ("WiFi enabled");
                  WifiWizard.getCurrentSSID(function(ssid)
                   {
                      //alert("Current SSID="+ssid);
                  if (ssid =='"Textning"')
                  {
                      //alert ("Textning connected")
                  }
                  else
                  {
                      //alert (”Connect tol Textning")
                      WifiWizard.connectNetwork("Textning", function(s)
                      {
                      //alert (”Connected to ="+s)
                      }
                      , function(e)
                      {
                          //alert ("Error connectNetwork="+e)
                      }
                      );
                  }
                   }
                   ,fail);
                }
                else
                {
                  //alert ("WiFi not enabled");
                  WifiWizard.setWifiEnabled(true, win, fail);

                }

          },function(f)
          {
              alert ("Error isWifiEnabled="+f) 
            }
            );

  //alert ("hit 3”)

  function fail()
  {
      alert ("fail")
  }//fail

  function win(s)
  {
      //alert (”Connected="+s)
  }

Per Liljeqvist

mobil: +46 70 6697558 mail: per.liljeqvist@gmail.com mailto:per.liljeqvist@gmail.com www.dogood.se http://www.dogood.se/

30 sep 2015 kl. 00:17 skrev hoerresb <notifications@github.com mailto:notifications@github.com>:

I've been trying to replicate your bug but I cannot. I tested this exact code on a samsung galaxy s4 running android 5.0.1 and it works as intended. I'm not exactly sure at the moment why the code would not get executed as you described.

are you running the latest version of WifiWizard v 0.2.9?

— Reply to this email directly or view it on GitHub https://github.com/parsonsmatt/WifiWizard/issues/41#issuecomment-144206913.

hoerresb commented 9 years ago

Hmmm, I'm not sure if this is related to your problem, but I noticed if I run the code as the app loads it doesn't work properly. I'm using the Ionic frame work so I have to wrap the code in an $IonicPlatform.ready(function() { //wifiwizard code })

I think this is equivalent to document.addEventListener("deviceready", yourCallbackFunction, false); in cordova.

It seems to be always working when I do this and I've kept the alerts in.

I think similar functionality for windows is possible but I haven't got around to adding it. If it is of some interest I can looking into adding some functionality for windows phones.

I'm going to test a bit more. Let me know if this helps. Thanks.

peli44 commented 9 years ago

My problems was when I took away the alert (hit 3). With that active I never has any problem.

Now I have taken all the alerts away and I think it is working most of the times. But I am not sure.

I am using the recommended frame from Phonegap. Waiting until all is loaded. So I guess it should be correct.

/Per

Per Liljeqvist mail: per.liljeqvist@gmail.com mobile: +46 70 6697558 web: www.dogood.se

30 sep 2015 kl. 06:52 skrev hoerresb notifications@github.com:

Hmmm, I'm not sure if this is related to your problem, but I noticed if I run the code as the app loads it doesn't work properly. I'm using the Ionic frame work so I have to wrap the code in an $IonicPlatform.ready(function() { //wifiwizard code })

I think this is equivalent to document.addEventListener("deviceready", yourCallbackFunction, false); in cordova.

It seems to be always working when I do this and I've kept the alerts in.

I think similar functionality for windows is possible but I haven't got around to adding it. If it is of some interest I can looking into adding some functionality for windows phones.

I'm going to test a bit more. Let me know if this helps. Thanks.

— Reply to this email directly or view it on GitHub https://github.com/parsonsmatt/WifiWizard/issues/41#issuecomment-144280997.

hoerresb commented 9 years ago

Closing for now, let us know if any other issues come up. Thanks.