tripflex / WifiWizard2

A Cordova plugin for managing Wifi networks (new version of WiFiWizard) - Latest is version 3+
https://www.npmjs.com/package/cordova-plugin-wifiwizard2
Apache License 2.0
123 stars 146 forks source link

ionic 3 #64

Open blondie63 opened 5 years ago

blondie63 commented 5 years ago

Select all that apply

Description

Is there a sample prj for ionic 3 using WifiWizard2 to get ssid only ?

tripflex commented 5 years ago

@blondie63 not that I know of, I don't personally use ionic so I would have no idea where to even start TBH.

My assumption is that is should be pretty simple and straight forward if you follow ionic tutorials for using cordova plugins for ionic, here what i found quickly searching google: https://forum.ionicframework.com/t/how-to-use-cordova-custom-plugin-in-ionic/123858/3

simonkincaidkintronix commented 5 years ago

@blondie63 @tripflex

Not sure if you still need this, but thought I would help out:

All you really need is getConnectedSSID(), but below is how I look at the current SSID, and if it doesn't match what i'm looking to connect to (this.m.wifi_network), then I initiate a connect. If it is already connected to the SSID I want I just resolve. Any questions (or improvements) please let me know!

` return new Promise( (resolve, reject) => {

        WifiWizard2.getConnectedSSID().then((res) => {

            if (res != this.m.wifi_network) {

                this.connectionStatus.next('connecting');

                WifiWizard2.timeout(1000).then( () => {

                    WifiWizard2.connect(this.m.wifi_network, true).then((res) => {

                        resolve(true);

                    }).catch( (err) => {

                        this.connectionStatus.next('disconnected');

                        reject(new Error('WIFI_NOCONNECT'));

                    });

                });

            } else {
                console.log('already connected');
                resolve(true); return;
            }

        });

    });`
blondie63 commented 5 years ago

Thanks Simon !

blondie63 commented 5 years ago

Doing some test i wrote this code:

public getSSID () { if (typeof WifiWizard2 !== 'undefined') { // WifiWizard2.requestPermission(); ONLY for Android console.log('WifiWizard2 loaded'); console.log(WifiWizard2); WifiWizard2.getConnectedSSID() .then((e) => { if (! e.includes('unknown')) { this.ssid = e; } else { this.ssid = this.ssidDef; // set a default value console.log('Unknown - SSID = ' + e); } }) .catch((e) => { console.log('Catch e: ' + e); }); } else { console.warn('WifiWizard2 not loaded'); this.ssid = this.ssidDef; } }

This code working fine on Ionic 4 and ios 12.1 But on Ionic 3 and ios 12.1 i've this error: en0 => (null) Supported interfaces: ( en0 )

Some idea ?

blondie63 commented 5 years ago

@blondie63 @tripflex

Not sure if you still need this, but thought I would help out:

All you really need is getConnectedSSID(), but below is how I look at the current SSID, and if it doesn't match what i'm looking to connect to (this.m.wifi_network), then I initiate a connect. If it is already connected to the SSID I want I just resolve. Any questions (or improvements) please let me know!

` return new Promise( (resolve, reject) => {

        WifiWizard2.getConnectedSSID().then((res) => {

            if (res != this.m.wifi_network) {

                this.connectionStatus.next('connecting');

                WifiWizard2.timeout(1000).then( () => {

                    WifiWizard2.connect(this.m.wifi_network, true).then((res) => {

                        resolve(true);

                    }).catch( (err) => {

                        this.connectionStatus.next('disconnected');

                        reject(new Error('WIFI_NOCONNECT'));

                    });

                });

            } else {
                console.log('already connected');
                resolve(true); return;
            }

        });

    });`

have you tested with Ionic 3 ?