What is the maximum rate at which I can scan for WiFi networks on a Mac using Apple's CoreWLAN Framework?

123 views Asked by At

I am trying to repeatedly scan for WiFi networks in my surroundings to later extract some information from them (like RSSI, noise, etc.). It is important for me to be able to do multiple scans quickly so I can do this in different places of a house/floor.

So, I wrote this simple code in main.c of an Objective C project. It scans for networks, displays how many networks were found, waits for 1 second and repeats the process.

#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import <CoreWLAN/CoreWLAN.h>

int main(int argc, const char * argv[]) {

    @autoreleasepool {

        CWInterface *currentInterface = [CWInterface interface];
        NSLog(@"Interface: %@\n", currentInterface);

        NSArray *networks;

        while (true) {

            networks = [[currentInterface scanForNetworksWithName:nil error:nil] allObjects];
            NSLog(@"%lu networks found.", (unsigned long)networks.count);
            usleep(1000000);

        }

    }
    return 0;
}

The output I get looks something like the following:

2015-05-22 15:32:09.103 WifiScannerXcode2[42928:13413575] Interface: <CWInterface: 0x6100000c1730> [interfaceName=en0]
2015-05-22 15:32:11.614 WifiScannerXcode2[42928:13413575] 37 networks found.
2015-05-22 15:32:12.632 WifiScannerXcode2[42928:13413575] 37 networks found.
2015-05-22 15:32:13.652 WifiScannerXcode2[42928:13413575] 37 networks found.
2015-05-22 15:32:15.297 WifiScannerXcode2[42928:13413575] 37 networks found.
2015-05-22 15:32:16.315 WifiScannerXcode2[42928:13413575] 37 networks found.
2015-05-22 15:32:17.336 WifiScannerXcode2[42928:13413575] 37 networks found.
2015-05-22 15:32:18.358 WifiScannerXcode2[42928:13413575] 37 networks found.
2015-05-22 15:32:19.378 WifiScannerXcode2[42928:13413575] 37 networks found.
2015-05-22 15:32:22.902 WifiScannerXcode2[42928:13413575] 47 networks found.
2015-05-22 15:32:23.928 WifiScannerXcode2[42928:13413575] 47 networks found.
2015-05-22 15:32:25.568 WifiScannerXcode2[42928:13413575] 49 networks found.
2015-05-22 15:32:26.590 WifiScannerXcode2[42928:13413575] 49 networks found.
2015-05-22 15:32:27.611 WifiScannerXcode2[42928:13413575] 49 networks found.
2015-05-22 15:32:28.632 WifiScannerXcode2[42928:13413575] 49 networks found.
2015-05-22 15:32:29.656 WifiScannerXcode2[42928:13413575] 49 networks found.
2015-05-22 15:32:30.684 WifiScannerXcode2[42928:13413575] 49 networks found.
2015-05-22 15:32:34.205 WifiScannerXcode2[42928:13413575] 39 networks found.
2015-05-22 15:32:35.854 WifiScannerXcode2[42928:13413575] 39 networks found.
2015-05-22 15:32:36.874 WifiScannerXcode2[42928:13413575] 39 networks found.
2015-05-22 15:32:37.896 WifiScannerXcode2[42928:13413575] 39 networks found.
2015-05-22 15:32:38.916 WifiScannerXcode2[42928:13413575] 39 networks found.
2015-05-22 15:32:39.936 WifiScannerXcode2[42928:13413575] 39 networks found.
2015-05-22 15:32:40.960 WifiScannerXcode2[42928:13413575] 39 networks found.
2015-05-22 15:32:41.981 WifiScannerXcode2[42928:13413575] 39 networks found.
2015-05-22 15:32:45.507 WifiScannerXcode2[42928:13413575] 39 networks found.
2015-05-22 15:32:47.151 WifiScannerXcode2[42928:13413575] 40 networks found.
2015-05-22 15:32:48.176 WifiScannerXcode2[42928:13413575] 40 networks found.
2015-05-22 15:32:49.201 WifiScannerXcode2[42928:13413575] 40 networks found.
2015-05-22 15:32:50.225 WifiScannerXcode2[42928:13413575] 40 networks found.
2015-05-22 15:32:51.246 WifiScannerXcode2[42928:13413575] 40 networks found.
2015-05-22 15:32:52.268 WifiScannerXcode2[42928:13413575] 40 networks found.
2015-05-22 15:32:53.289 WifiScannerXcode2[42928:13413575] 40 networks found.
2015-05-22 15:32:56.806 WifiScannerXcode2[42928:13413575] 40 networks found.

I observe that the data is grouped in sets of ~8 samples, i.e. only after 8 seconds does it actually do an effective scan for new networks. I can't see any documentation saying that this is the case, so my question is "how long do I need to wait to do an effective scan and how do I achieve it?"

By using the Mac's native Wireless Diagnostic scan tool, I can do an effective scan every 3 seconds approximately. How do I achieve that rate?

0

There are 0 answers