Scanning for wifi signals only in 2.4Ghz band
Asked Answered
S

4

7

I need to scan for available Wi-Fi signals and their strengths. I'm using wifiManager.startScan(); and asynchronous wifiManager.getScanResult();.

On devices without support of 5GHz band it takes about 500ms to get the results, on devices with 5GHz band support it takes about 2s, and that is too much for me. I guess the 1.5s delay is in searching the whole 5GHz band.

Is there any way I could tell the device to scan only in the 2.4GHz band, or any other way I could get the results faster (for example through NDK)? I searched through the entire web and found nothing, so I guess this is the only way.

Thank you.

Stoops answered 27/6, 2013 at 14:23 Comment(0)
N
2

Is there any way I could tell the device to scan only in the 2.4GHz band

I think there is not way how to achieve it.

All you can do is only call startScan() and wait for results. Then you can filter results due to their frequency especially for 2.4Ghz frequency of each AP (Access Point) should be bellow 2500 Mhz.

Nuncupative answered 3/9, 2013 at 7:10 Comment(1)
for 5 Ghz I am getting the frequency value below 2500.Sabulous
H
2

NOTE: These api's are removed from Android Nogut version. Applicable till Mashmallow

/**
 * Auto settings in the driver. The driver could choose to operate on both
 * 2.4 GHz and 5 GHz or make a dynamic decision on selecting the band.
 * @hide
 */
public static final int WIFI_FREQUENCY_BAND_AUTO = 0;

/**
 * Operation on 5 GHz alone
 * @hide
 */
public static final int WIFI_FREQUENCY_BAND_5GHZ = 1;

/**
 * Operation on 2.4 GHz alone
 * @hide
 */
public static final int WIFI_FREQUENCY_BAND_2GHZ = 2;

Use above constants part of WifiManager.java, to set the required frequency bands. And we can set frequency with API setFrequencyBand(int mode, boolean persist). These are hidden API's.

code snippet:

WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);

// To scan only 2.4 GHz Frequency band

// true, if this needs to be remembered

wm.setFrequencyBand(2, false);

// Start scan.

wm.startScan();

// To get the frequency band used.

int band = wm.getFrequncyBand();
Hole answered 20/11, 2014 at 10:57 Comment(3)
This would be perfect except that those functions are hidden and can't be referenced.Homager
I'm not seeing any reference to setFrequencyBand or getFrequencyBand with my wifi manager. I know it was a hidden API, but has it been removed completely?Humiliating
These api's are removed from Android Nogut.Hole
R
1

Supplicant config file provide option to explicitly declare range of channels where you want to scan for available network. If you device uses wpa_supplicant then in config file you can define scan frequency like below.

scan_freq: List of frequencies to scan

for more info look for above text in below mention link.

Visit http://hostap.epitest.fi/gitweb/gitweb.cgi?p=hostap.git;a=blob_plain;f=wpa_supplicant/wpa_supplicant.conf .

Retake answered 4/10, 2013 at 5:51 Comment(1)
the link is broken. It downloads a gitweb.cgi file. If I open it, it shows some xml or html. Also, I couldn't find scan_freq in this file.Nullipore
H
0
    final WifiManager wifiManager = (WifiManager)



context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);                

wifiManager.getScanResults().get(0).frequency >= 2500
Hansom answered 8/11, 2018 at 15:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.