这一次讲的时ESP8266WiFiScan.h文件,用来搜索可用WiFi。
int8_t scanNetworks(bool async = false, bool show_hidden = false);
int8_t scanComplete(); // 查看是否搜索结束
void scanDelete(); // 删除上一次搜索的结果
// scan result
bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);
String SSID(uint8_t networkItem); // WiFi 的名称
uint8_t encryptionType(uint8_t networkItem);
int32_t RSSI(uint8_t networkItem); // 信号强度
uint8_t * BSSID(uint8_t networkItem); //
String BSSIDstr(uint8_t networkItem);
int32_t channel(uint8_t networkItem);
bool isHidden(uint8_t networkItem);
使用时只需调用WiFi.scanNetworks(); ESP8266便会搜索WiFI,并将搜索的结果存到数组中。
官方例程在调用WiFi.scanNetworks();之前先调用了
WiFi.mode(WIFI_STA);
WiFi.disconnect();
实际上可以不重复调用,因为在scanNetworks();这个函数中官方已经调用过了:
int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden) {
if(ESP8266WiFiScanClass::_scanStarted) {
return WIFI_SCAN_RUNNING;
}
ESP8266WiFiScanClass::_scanAsync = async;
WiFi.enableSTA(true);
// 使能STA模式
int status = wifi_station_get_connect_status();
if(status != STATION_GOT_IP && status != STATION_IDLE) {
WiFi.disconnect(false);
// 断开已连接的WiFi
}
scanDelete();
// 删除 上一次的搜索结果
struct scan_config config;
config.ssid = 0;
config.bssid = 0;
config.channel = 0;
config.show_hidden = show_hidden;
if(wifi_station_scan(&config, reinterpret_cast(&ESP8266WiFiScanClass::_scanDone))) {
ESP8266WiFiScanClass::_scanComplete = false;
ESP8266WiFiScanClass::_scanStarted = true;
if(ESP8266WiFiScanClass::_scanAsync) {
delay(0); // time for the OS to trigger the scan
return WIFI_SCAN_RUNNING;
}
esp_yield();
return ESP8266WiFiScanClass::_scanCount;
} else {
return WIFI_SCAN_FAILED;
}
}
这一次讲的时ESP8266WiFiScan.h文件,用来搜索可用WiFi。
int8_t scanNetworks(bool async = false, bool show_hidden = false);
int8_t scanComplete(); // 查看是否搜索结束
void scanDelete(); // 删除上一次搜索的结果
// scan result
bool getNetworkInfo(uint8_t networkItem, String &ssid, uint8_t &encryptionType, int32_t &RSSI, uint8_t* &BSSID, int32_t &channel, bool &isHidden);
String SSID(uint8_t networkItem); // WiFi 的名称
uint8_t encryptionType(uint8_t networkItem);
int32_t RSSI(uint8_t networkItem); // 信号强度
uint8_t * BSSID(uint8_t networkItem); //
String BSSIDstr(uint8_t networkItem);
int32_t channel(uint8_t networkItem);
bool isHidden(uint8_t networkItem);
使用时只需调用WiFi.scanNetworks(); ESP8266便会搜索WiFI,并将搜索的结果存到数组中。
官方例程在调用WiFi.scanNetworks();之前先调用了
WiFi.mode(WIFI_STA);
WiFi.disconnect();
实际上可以不重复调用,因为在scanNetworks();这个函数中官方已经调用过了:
int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden) {
if(ESP8266WiFiScanClass::_scanStarted) {
return WIFI_SCAN_RUNNING;
}
ESP8266WiFiScanClass::_scanAsync = async;
WiFi.enableSTA(true);
// 使能STA模式
int status = wifi_station_get_connect_status();
if(status != STATION_GOT_IP && status != STATION_IDLE) {
WiFi.disconnect(false);
// 断开已连接的WiFi
}
scanDelete();
// 删除 上一次的搜索结果
struct scan_config config;
config.ssid = 0;
config.bssid = 0;
config.channel = 0;
config.show_hidden = show_hidden;
if(wifi_station_scan(&config, reinterpret_cast(&ESP8266WiFiScanClass::_scanDone))) {
ESP8266WiFiScanClass::_scanComplete = false;
ESP8266WiFiScanClass::_scanStarted = true;
if(ESP8266WiFiScanClass::_scanAsync) {
delay(0); // time for the OS to trigger the scan
return WIFI_SCAN_RUNNING;
}
esp_yield();
return ESP8266WiFiScanClass::_scanCount;
} else {
return WIFI_SCAN_FAILED;
}
}
举报