Ionic app need to connect the specific wifi only

hai,
For a iot project,when my app is open need to check if my phone is connected to the specific WiFi(pre-configured).if connection is ok then need to open a specific ip
My question is that how can i know the device is connected to the specific wifi?

is the specific ip address only available in that wifi?

If so --> just make a test request if you can connect --> if not you are not connected to the wifi.

2 Likes

Hi,

Use WifiWizard plugin to get SSID of your Wifi

You have an example here : http://stackoverflow.com/questions/31182536/how-can-i-get-wifi-network-information-ssid-in-a-phonegap-app

1 Like

thanks
its works
this my code

$scope.getCurrentSSID = function () {
        WifiWizard.getCurrentSSID(ssidHandler, fail);
    }

   function ssidHandler(s) {
         if(s=="testWifi"){
         $scope.showNotifPopup(s);
       }     
    }

    function fail(e) {
        alert("Failed" + e);
    }

    $scope.showNotifPopup = function (s) {
        var confirmPopup = $ionicPopup.confirm({
            title: "Confirm",
            template: "You are connected to " + s + " Press confirm to continue"
        });

        confirmPopup.then(function (res) {
            if (res) {
               openInAppBrowser()

            } else {
                console.log('You are not sure');
            }
        });
    }

   function openInAppBrowser() {
        window.open('https://my Ip', '_system', 'location=yes')
    }

No problem :slight_smile:

Happy coding

Hi.
How can I receive data from specific device using wifi after connection.
The device sends data repeatly.
I tried with hotspot an I could scan wifi-hotspot. But I can’t receive data.
Is it possible with WifiWizard?
If it is impossible with wifiwizard, is there any other way to solve this problem?
After receiving data, I have to send data to this device.
I have already know the ssid and password of this device.
I want to know for both android and iphone.
Thank you advance.

Hey @SilverStar101, I need some more information before I can help you.

  • Are you running your own server which this device connects to?
  • What type of “data” are you hoping to send and receive?

Without more info, and without using the WifiWizard plugin, here is what I would do:

  • App is launched

  • Test for connection to internet (You can ping a server or use the WifiWizard to see if a connection is established)

  • If no connection, you’ll need to set up a listener for the online event. (I recommend the cordova-plugin-network-information plugin)

  • Once you are connected, you can establish a Socket.io socket in order to quickly send and receieve data between your device and server.

  • If you need to uniquely identify the device, I would generate a unique device ID if one has not been created, and store this somewhere, so you can retrieve it and attach it to any outgoing requests, so your server can also identify which device is sending it data.

Again, I need a little bit more information to really help you here, but I hope the info above helps you out. If not, please let me know.

Cheers

Hello, DaDanny.
Thank you for your advice.
The device uses ESP8266 module(wifi-module).
The data I need to receive and send is only message contains few strings.
We can set SSID and Password for ESP8266 module.
And I am so sorry that I am a beginner about ionic.
So I want sample codes related to my project.
Thank you for your help.
Looking forward to your reply.
Warm regards.

Sorry @SilverStar101, but it sounds like you’ll need quite a bit of code to accomplish what you are looking for, namely a server to receive any transmitted data and a database to store the data. I’ve heard a ton of great things about Firebase, so I’d recommend that in your situation.

Basically, what you would do is:

  • Device connects with module
  • Once connection is established, start sending/receiving data to and from the server (Firebase instance)
  • Store data on the server

There are a lot of ways to accomplish that, but again, I recommend Firebase in your situation and it shouldn’t be too difficult to get up and running.

Let me know if you need any other help or advice.

Hi there,
i need to do the same.
have you find any solution for this please ?
any line guide?