Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. /*
  2.  *  This sketch demonstrates how to scan WiFi networks.
  3.  *  The API is almost the same as with the WiFi Shield library,
  4.  *  the most obvious difference being the different file you need to include:
  5.  */
  6. #include "ESP8266WiFi.h"
  7.  
  8. void setup() {
  9.   Serial.begin(9600);
  10.  
  11.   // Set WiFi to station mode and disconnect from an AP if it was previously connected
  12.   WiFi.mode(WIFI_STA);
  13.   WiFi.disconnect();
  14.   delay(100);
  15.  
  16.   Serial.println("Setup done");
  17. }
  18.  
  19. void loop() {
  20.   Serial.println("scan start");
  21.  
  22.   // WiFi.scanNetworks will return the number of networks found
  23.   int n = WiFi.scanNetworks();
  24.   Serial.println("scan done");
  25.   if (n == 0)
  26.     Serial.println("no networks found");
  27.   else
  28.   {
  29.     Serial.print(n);
  30.     Serial.println(" networks found");
  31.     for (int i = 0; i < n; ++i)
  32.     {
  33.       // Print SSID and RSSI for each network found
  34.       Serial.print(i + 1);
  35.       Serial.print(": ");
  36.       Serial.print(WiFi.SSID(i));
  37.       Serial.print(" (");
  38.       Serial.print(WiFi.RSSI(i));
  39.       Serial.print(")");
  40.       Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
  41.       delay(10);
  42.     }
  43.   }
  44.   Serial.println("");
  45.  
  46.   // Wait a bit before scanning again
  47.   delay(5000);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement