wifi扫描

获取当前位置的wifi,信道,强度,mac

#include "ESP8266WiFi.h"
IPAddress apIP(192, 168, 4, 1);
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
// WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
// WiFi.softAP("215-wifi","1234567890"); WiFi.disconnect();
delay(100);
Serial.println("Setup done"); } void loop() {
Serial.println("scan start");
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
String maxwifi="";
int wifiq=-100; if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")"); /*
byte:value表示加密类型
TKIP(WPA)= 2
WEP = 5 WEP 加密由于是一种静态加密方式,收发的包中就含有密码信息,因此可以非常容易地就直接破解密码,目前已经很少被使用
CCMP(WPA)= 4 动态加密
无= 7
AUTO = 8
*/
Serial.print((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");//获取当前网络的加密类型
Serial.print(" channel:"); Serial.print(WiFi.channel(i)); /*
byte:value表示加密类型
TKIP(WPA)= 2
WEP = 5
CCMP(WPA)= 4
无= 7
AUTO = 8
*/
Serial.print(" encryptionType:"); Serial.println(WiFi.encryptionType(i));
/*
using ESP8266WiFiScanClass::SSID;
using ESP8266WiFiScanClass::encryptionType;
using ESP8266WiFiScanClass::RSSI;
using ESP8266WiFiScanClass::BSSID;
using ESP8266WiFiScanClass::BSSIDstr;
using ESP8266WiFiScanClass::channel;
using ESP8266WiFiScanClass::isHidden; */
if(WiFi.RSSI(i)>wifiq){
wifiq= WiFi.RSSI(i); maxwifi=String(WiFi.SSID(i)) ;
}
delay(10);
}
}
Serial.println("");
Serial.print("maxwifi:"); Serial.println(maxwifi);
//WiFi.softAP(maxwifi,"xixi",11); delay(5000);
}

  

上一篇:使用eclipse查看源码的方法


下一篇:C#委托和事件讲解