#include "ESP8266WiFi.h" #define LED_PIN LED_BUILTIN #define COLUMN_SEPARATOR "," #define ROW_SEPARATOR "\n" void setup() { pinMode(LED_PIN, OUTPUT); Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.disconnect(); Serial.printf("time%sssid%schannel%ssignal%sencryption%sbssid%shidden%s", COLUMN_SEPARATOR, COLUMN_SEPARATOR, COLUMN_SEPARATOR, COLUMN_SEPARATOR, COLUMN_SEPARATOR, COLUMN_SEPARATOR, ROW_SEPARATOR); } void loop() { digitalWrite(LED_PIN, HIGH); int count = WiFi.scanNetworks(false, true); digitalWrite(LED_PIN, LOW); String ssid; uint8_t encryptionType; int32_t RSSI; uint8_t* BSSID; int32_t channel; bool isHidden; String encryptionText; for (int i = 0; i < count; i++) { WiFi.getNetworkInfo(i, ssid, encryptionType, RSSI, BSSID, channel, isHidden); switch (encryptionType) { case ENC_TYPE_WEP: encryptionText = "WEP"; break; case ENC_TYPE_TKIP: encryptionText = "WPA1"; break; case ENC_TYPE_CCMP: encryptionText = "WPA2"; break; case ENC_TYPE_NONE: encryptionText = "NONE"; break; case ENC_TYPE_AUTO: encryptionText = "WPA1+2"; break; // Encountered in the wild: 802.1X seems to set to 255 case 255: encryptionText = "802.1X"; break; default: encryptionText = String(encryptionType); } Serial.printf("%lu%s%s%s%d%s%d%s%s%s%s%s%u%s", millis(), COLUMN_SEPARATOR, ssid.c_str(), COLUMN_SEPARATOR, channel, COLUMN_SEPARATOR, RSSI, COLUMN_SEPARATOR, encryptionText.c_str(), COLUMN_SEPARATOR, WiFi.BSSIDstr(i).c_str(), COLUMN_SEPARATOR, isHidden, ROW_SEPARATOR); } delay(1000); }