本站改版新增arduino频道
#include <WiFi.h> void setup() { Serial.begin(115200); delay(1000); // 设置 ESP32 为 WiFi Station 模式 WiFi.mode(WIFI_STA); WiFi.disconnect(); // 断开当前连接(如果有) delay(100); Serial.println("Starting WiFi scan..."); } void loop() { // 扫描所有 WiFi 网络 int numNetworks = WiFi.scanNetworks(); if (numNetworks == 0) { Serial.println("No networks found."); } else { Serial.print(numNetworks); Serial.println(" networks found:"); Serial.println("----------------------------"); Serial.println("No. | SSID | RSSI | Encryption | BSSID "); Serial.println("----------------------------"); for (int i = 0; i < numNetworks; i++) { // 输出 WiFi 信息 Serial.printf("%2d | %-16s | %4d | %-10s | %s\n", i + 1, WiFi.SSID(i).c_str(), WiFi.RSSI(i), getEncryptionType(WiFi.encryptionType(i)), WiFi.BSSIDstr(i).c_str()); } } Serial.println("\nScan complete. Waiting 10 seconds...\n"); delay(10000); // 10 秒后重新扫描 } // 获取加密类型(字符串形式) const char* getEncryptionType(wifi_auth_mode_t encryptionType) { switch (encryptionType) { case WIFI_AUTH_OPEN: return "Open"; case WIFI_AUTH_WEP: return "WEP"; case WIFI_AUTH_WPA_PSK: return "WPA"; case WIFI_AUTH_WPA2_PSK: return "WPA2"; case WIFI_AUTH_WPA_WPA2_PSK: return "WPA/WPA2"; case WIFI_AUTH_WPA2_ENTERPRISE: return "WPA2-Enterprise"; default: return "Unknown"; } }
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0096671581268311 seconds