You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wifi_scan.ino 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 "WiFi.h"
  7. void setup()
  8. {
  9. Serial.begin(115200);
  10. // Set WiFi to station mode and disconnect from an AP if it was previously connected
  11. WiFi.mode(WIFI_STA);
  12. WiFi.disconnect();
  13. delay(100);
  14. Serial.println("Setup done");
  15. }
  16. void loop()
  17. {
  18. Serial.println("scan start");
  19. // WiFi.scanNetworks will return the number of networks found
  20. int n = WiFi.scanNetworks();
  21. Serial.println("scan done");
  22. if (n == 0) {
  23. Serial.println("no networks found");
  24. } else {
  25. Serial.print(n);
  26. Serial.println(" networks found");
  27. for (int i = 0; i < n; ++i) {
  28. // Print SSID and RSSI for each network found
  29. Serial.print(i + 1);
  30. Serial.print(": ");
  31. Serial.print(WiFi.SSID(i));
  32. Serial.print(" (");
  33. Serial.print(WiFi.RSSI(i));
  34. Serial.print(")");
  35. Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
  36. delay(10);
  37. }
  38. }
  39. Serial.println("");
  40. // Wait a bit before scanning again
  41. delay(5000);
  42. }