--
參考資源
--
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#include "ESP8266WiFi.h" #define BLINK_PERIOD 250 long lastBlinkMillis; boolean ledState; #define SCAN_PERIOD 5000 long lastScanMillis; void setup() { Serial.begin(115200); Serial.println(); pinMode(LED_BUILTIN, OUTPUT); WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); } void loop() { long currentMillis = millis(); // blink LED if (currentMillis - lastBlinkMillis > BLINK_PERIOD) { digitalWrite(LED_BUILTIN, ledState); ledState = !ledState; lastBlinkMillis = currentMillis; } // trigger Wi-Fi network scan if (currentMillis - lastScanMillis > SCAN_PERIOD) { WiFi.scanNetworks(true); Serial.print("\nScan start ... "); lastScanMillis = currentMillis; } // print out Wi-Fi network scan result upon completion int n = WiFi.scanComplete(); if (n >= 0) { Serial.printf("%d network(s) found\n", n); for (int i = 0; i < n; i++) { Serial.printf("%d: %s, Ch:%d (%ddBm) %s\n", i + 1, WiFi.SSID(i).c_str(), WiFi.channel(i), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? "open" : ""); } WiFi.scanDelete(); } } |
結果
1 2 3 4 5 6 |
Scan start ... 5 network(s) found 1: YoYoHome, Ch:2 (-50dBm) 2: hoyoWifi-2.4G, Ch:3 (-67dBm) 3: abc, Ch:6 (-80dBm) 4: TEANAwireless, Ch:9 (-84dBm) 5: Home, Ch:11 (-80dBm) |
--
821 total views, 1 views today