四博智联产品售后

标题: 扫描环境中的Wifi信号 [打印本页]

作者: ycf    时间: 2015-12-28 16:23
标题: 扫描环境中的Wifi信号
  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. void setup() {
  8.   Serial.begin(115200);

  9.   // Set WiFi to station mode and disconnect from an AP if it was previously connected
  10.   WiFi.mode(WIFI_STA);
  11.   WiFi.disconnect();
  12.   delay(100);

  13.   Serial.println("Setup done");
  14. }

  15. void loop() {
  16.   Serial.println("scan start");

  17.   // WiFi.scanNetworks will return the number of networks found
  18.   int n = WiFi.scanNetworks();
  19.   Serial.println("scan done");
  20.   if (n == 0)
  21.     Serial.println("no networks found");
  22.   else
  23.   {
  24.     Serial.print(n);
  25.     Serial.println(" networks found");
  26.     for (int i = 0; i < n; ++i)
  27.     {
  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) == ENC_TYPE_NONE)?" ":"*");
  36.       delay(10);
  37.     }
  38.   }
  39.   Serial.println("");

  40.   // Wait a bit before scanning again
  41.   delay(5000);
  42. }
复制代码


scanwifi.rar

3.94 KB, 下载次数: 5023






欢迎光临 四博智联产品售后 (http://bbs.doit.am/) Powered by Discuz! X3.2