WifiWizard2 icon indicating copy to clipboard operation
WifiWizard2 copied to clipboard

ionic 3

Open blondie63 opened this issue 6 years ago • 5 comments

Select all that apply

  • [ ] Bug
  • [ ] Enhancement
  • [ ] Task
  • [ x] Question
  • [ ] Other

Description

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

blondie63 avatar Jan 28 '19 22:01 blondie63

@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

tripflex avatar Feb 07 '19 20:02 tripflex

@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;
            }

        });

    });`

simonkincaidkintronix avatar Feb 20 '19 11:02 simonkincaidkintronix

Thanks Simon !

blondie63 avatar Feb 21 '19 08:02 blondie63

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 avatar Feb 21 '19 22:02 blondie63

@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 ?

blondie63 avatar Feb 22 '19 14:02 blondie63