AI智能
改变未来

使用Arduino开发ESP32:WiFi.scanNetworks()函数

WiFi.scanNetworks() //扫描周围wifi
此函数定义在WiFiScan.cpp中
方法体完整代码:

/*** Start scan WiFi networks available* @param async         run in async mode* @param show_hidden   show hidden networks* @return Number of discovered networks*/int16_t WiFiScanClass::scanNetworks(bool async, bool show_hidden, bool passive, uint32_t max_ms_per_chan, uint8_t channel){if(WiFiGenericClass::getStatusBits() & WIFI_SCANNING_BIT) {return WIFI_SCAN_RUNNING;}WiFiScanClass::_scanTimeout = max_ms_per_chan * 20;WiFiScanClass::_scanAsync = async;WiFi.enableSTA(true);scanDelete();wifi_scan_config_t config;config.ssid = 0;config.bssid = 0;config.channel = channel;config.show_hidden = show_hidden;if(passive){config.scan_type = WIFI_SCAN_TYPE_PASSIVE;config.scan_time.passive = max_ms_per_chan;} else {config.scan_type = WIFI_SCAN_TYPE_ACTIVE;config.scan_time.active.min = 100;config.scan_time.active.max = max_ms_per_chan;}if(esp_wifi_scan_start(&config, false) == ESP_OK) {_scanStarted = millis();if (!_scanStarted) { //Prevent 0 from millis overflow++_scanStarted;}WiFiGenericClass::clearStatusBits(WIFI_SCAN_DONE_BIT);WiFiGenericClass::setStatusBits(WIFI_SCANNING_BIT);if(WiFiScanClass::_scanAsync) {return WIFI_SCAN_RUNNING;}if(WiFiGenericClass::waitStatusBits(WIFI_SCAN_DONE_BIT, 10000)){return (int16_t) WiFiScanClass::_scanCount;}}return WIFI_SCAN_FAILED;}
我们可以看到官方自带的注释:/*** Start scan WiFi networks available       开始扫描可用的WiFi网络* @param async         run in async mode   参数 async   以异步模式运行* @param show_hidden   show hidden networks   参数 show_hidden 显示隐藏的网络* @return Number of discovered networks   返回值 已发现的网络的数量*/

在WiFiType.h文件中,我找到了定义:

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 使用Arduino开发ESP32:WiFi.scanNetworks()函数