[text] 123

Viewer

  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(115200);
  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.     Serial.print(n);
  29.     Serial.println(" networks found");
  30.     for (int i = 0; i < n; ++i) {
  31.       // Print SSID and RSSI for each network found
  32.       Serial.print(i + 1);
  33.       Serial.print(": ");
  34.       Serial.print(WiFi.SSID(i));
  35.       Serial.print(" (");
  36.       Serial.print(WiFi.RSSI(i));
  37.       Serial.print(")");
  38.       Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
  39.       delay(10);
  40.     }
  41.   }
  42.   Serial.println("");
  43.  
  44.   // Wait a bit before scanning again
  45.   delay(5000);
  46. }
  47.  

Editor

You can edit this paste and save as new:


File Description
  • 123
  • Paste Code
  • 02 Dec-2022
  • 1.21 Kb
You can Share it: