四博智联产品售后

 找回密码
 立即注册
搜索
查看: 12751|回复: 0
打印 上一主题 下一主题

扫描环境中的Wifi信号

[复制链接]

258

主题

313

帖子

1896

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1896
跳转到指定楼层
楼主
发表于 2015-12-28 16:23:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  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, 下载次数: 5045

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|四博智联 Inc. ( 粤ICP备15034758号-1

GMT+8, 2024-11-25 20:13 , Processed in 0.049675 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表