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
122 stars 145 forks source link

Sometimes WifiWizard2.getScanResults() returns an empty array. Or it has drastically different results. #85

Open asoap opened 5 years ago

asoap commented 5 years ago

Issue type

Select all that apply

Description

Sometimes WifiWizard2.getScanResults() returns an empty array. Or it has drastically different results. I'm just curious to know why this happens? Is there something I can do to prevent it from returning an empty array? The function does indeed work, it just sometimes doesn't.

Steps to Reproduce

  1. keep on hitting WifiWizard2.getScanResults() and see the results

Expected behavior: The same list or very similar list of hotspots

Reproduces how often: It's an intermittent issue. It can happen 50% of the time.

Versions

3.1.1

faizan1990 commented 5 years ago

I am having the same issue. This is my code:

WifiWizard2.startScan().then(startscanresponse => {
            // Success
        }).catch(e => {
            console.log(JSON.stringify(e));
        });;

        WifiWizard2.getScanResults().then(response => {
            this.networksData = response;
        }).catch(e => {
            console.log(JSON.stringify(e));
        });

The plugin is updating the scan results way too late. In 120 seconds, it could only get 2 fingerprints of the available WAPs. The Ionic Cordova Hotspot Plugin I was using earlier was updating in milliseconds and would return over 100 fingerprints in 120 seconds time.

And since it's updating the scan results so late, for most of the indoor area, it returns the same fingerprint (which is wrong in real life).

Any urgent help will be much appreciated.

tripflex commented 5 years ago

@faizan1990 @asoap

It is recommended to use WifiWizard2.scan which will resolve after scan results are returned. Demo: https://github.com/tripflex/WifiWizard2Demo/blob/master/client/views/wifi_scan/wifi_scan.js#L33

The problem is probably because you're immediately attempting to get the scan results after triggering the scan to start, by using .scan it will resolve the promise once the scan results are returned from Android, otherwise you will probably have to call getScanResults multiple times or add your own timeout to wait before calling getScanResults

faizan1990 commented 5 years ago

Hi @tripflex, I managed to find out what the problem was. Sorry didn't update it here. The actual problem was Wi-Fi throttling limitation applied in the last version of Android 8 and all versions of Android 9. It doesn't allow you to scan more than twice a minute for a foreground app. Very annoying, but there're a few threads about its fix.

Issue description: https://developer.android.com/guide/topics/connectivity/wifi-scan#wifi-scan-throttling

News: https://www.xda-developers.com/android-pie-throttling-wi-fi-scans-crippling-apps/