/*
* This sketch demonstrates how to scan WiFi networks.
* The API is almost the same as with the WiFi Shield library,
* the most obvious difference being the different file you need to include:
*/
#include "WiFi.h"
void setup()
{
Serial.begin(115200);
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup done");
}
void loop()
{
Serial.println("scan start");
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
delay(10);
}
}
Serial.println("");
// Wait a bit before scanning again
delay(5000);
}
LyoKICogIFRoaXMgc2tldGNoIGRlbW9uc3RyYXRlcyBob3cgdG8gc2NhbiBXaUZpIG5ldHdvcmtzLgogKiAgVGhlIEFQSSBpcyBhbG1vc3QgdGhlIHNhbWUgYXMgd2l0aCB0aGUgV2lGaSBTaGllbGQgbGlicmFyeSwKICogIHRoZSBtb3N0IG9idmlvdXMgZGlmZmVyZW5jZSBiZWluZyB0aGUgZGlmZmVyZW50IGZpbGUgeW91IG5lZWQgdG8gaW5jbHVkZToKICovCiNpbmNsdWRlICJXaUZpLmgiCgp2b2lkIHNldHVwKCkKewogICAgU2VyaWFsLmJlZ2luKDExNTIwMCk7CgogICAgLy8gU2V0IFdpRmkgdG8gc3RhdGlvbiBtb2RlIGFuZCBkaXNjb25uZWN0IGZyb20gYW4gQVAgaWYgaXQgd2FzIHByZXZpb3VzbHkgY29ubmVjdGVkCiAgICBXaUZpLm1vZGUoV0lGSV9TVEEpOwogICAgV2lGaS5kaXNjb25uZWN0KCk7CiAgICBkZWxheSgxMDApOwoKICAgIFNlcmlhbC5wcmludGxuKCJTZXR1cCBkb25lIik7Cn0KCnZvaWQgbG9vcCgpCnsKICAgIFNlcmlhbC5wcmludGxuKCJzY2FuIHN0YXJ0Iik7CgogICAgLy8gV2lGaS5zY2FuTmV0d29ya3Mgd2lsbCByZXR1cm4gdGhlIG51bWJlciBvZiBuZXR3b3JrcyBmb3VuZAogICAgaW50IG4gPSBXaUZpLnNjYW5OZXR3b3JrcygpOwogICAgU2VyaWFsLnByaW50bG4oInNjYW4gZG9uZSIpOwogICAgaWYgKG4gPT0gMCkgewogICAgICAgIFNlcmlhbC5wcmludGxuKCJubyBuZXR3b3JrcyBmb3VuZCIpOwogICAgfSBlbHNlIHsKICAgICAgICBTZXJpYWwucHJpbnQobik7CiAgICAgICAgU2VyaWFsLnByaW50bG4oIiBuZXR3b3JrcyBmb3VuZCIpOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgICAgIC8vIFByaW50IFNTSUQgYW5kIFJTU0kgZm9yIGVhY2ggbmV0d29yayBmb3VuZAogICAgICAgICAgICBTZXJpYWwucHJpbnQoaSArIDEpOwogICAgICAgICAgICBTZXJpYWwucHJpbnQoIjogIik7CiAgICAgICAgICAgIFNlcmlhbC5wcmludChXaUZpLlNTSUQoaSkpOwogICAgICAgICAgICBTZXJpYWwucHJpbnQoIiAoIik7CiAgICAgICAgICAgIFNlcmlhbC5wcmludChXaUZpLlJTU0koaSkpOwogICAgICAgICAgICBTZXJpYWwucHJpbnQoIikiKTsKICAgICAgICAgICAgU2VyaWFsLnByaW50bG4oKFdpRmkuZW5jcnlwdGlvblR5cGUoaSkgPT0gV0lGSV9BVVRIX09QRU4pPyIgIjoiKiIpOwogICAgICAgICAgICBkZWxheSgxMCk7CiAgICAgICAgfQogICAgfQogICAgU2VyaWFsLnByaW50bG4oIiIpOwoKICAgIC8vIFdhaXQgYSBiaXQgYmVmb3JlIHNjYW5uaW5nIGFnYWluCiAgICBkZWxheSg1MDAwKTsKfQ==