#include <WiFi.h> // ESP32 Wi-Fi library
#include <TFT_eSPI.h> // Graphics library for the LilyGO T-Display S3
TFT_eSPI tft = TFT_eSPI(); // Create a display object
// Variables for screen refresh
unsigned long lastScanTime = 0;
const unsigned long scanInterval = 10000; // Refresh every 10 seconds
void setup() {
// Initialize Serial Communication
Serial.begin(115200);
delay(500);
// Welcome message in serial terminal
Serial.println("Wi-Fi Scanner");
Serial.println("----------------------------");
// Initialize the display
tft.init();
tft.setRotation(1); // Adjust screen orientation if needed
tft.fillScreen(TFT_BLACK);
// Display a splash screen
splashScreen();
// Start Wi-Fi in station mode
WiFi.mode(WIFI_STA);
WiFi.disconnect(); // Ensure no active connection
delay(100);
}
void loop() {
// Perform a Wi-Fi scan every `scanInterval` milliseconds
if (millis() - lastScanTime > scanInterval) {
lastScanTime = millis();
scanWiFiNetworks();
}
}
// Function to display a splash screen
void splashScreen() {
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.println("Wi-Fi Scanner");
tft.setTextSize(1);
tft.setCursor(10, 50);
tft.println("Scanning nearby networks...");
delay(2000);
tft.fillScreen(TFT_BLACK);
}
// Function to scan Wi-Fi networks and display results
void scanWiFiNetworks() {
// Start Wi-Fi scan
Serial.println("\nScanning for Wi-Fi networks...");
int networkCount = WiFi.scanNetworks();
// Display results on the serial terminal
Serial.printf("Found %d networks:\n", networkCount);
Serial.println("----------------------------");
// Display results on the T-Display S3
tft.fillScreen(TFT_BLACK);
tft.setTextSize(1);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.setCursor(0, 0);
// If no networks are found, display a message
if (networkCount == 0) {
Serial.println("No networks found.");
tft.println("No networks found.");
return;
}
// Loop through the list of networks and display information
for (int i = 0; i < networkCount; i++) {
// Get network details
String ssid = WiFi.SSID(i);
if (ssid == "") ssid = "Hidden Network"; // Handle empty SSID
int rssi = WiFi.RSSI(i);
String encryptionType = translateEncryptionType(WiFi.encryptionType(i));
// Display on the serial terminal
Serial.printf("%d: %s (%d dBm) [%s]\n", i + 1, ssid.c_str(), rssi, encryptionType.c_str());
// Display on the T-Display S3
tft.printf("%d: %s\n", i + 1, ssid.c_str());
tft.printf(" RSSI: %d dBm\n", rssi);
tft.printf(" Encryption: %s\n\n", encryptionType.c_str());
// Add a delay between printing networks to avoid display clutter
delay(50);
}
// End of scan
Serial.println("----------------------------");
Serial.println("Scan complete.");
delay(500); // Small delay before the next scan
}
// Function to translate encryption type to human-readable text
String translateEncryptionType(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-PSK";
case WIFI_AUTH_WPA2_PSK:
return "WPA2-PSK";
case WIFI_AUTH_WPA_WPA2_PSK:
return "WPA/WPA2-PSK";
case WIFI_AUTH_WPA3_PSK:
return "WPA3-PSK";
case WIFI_AUTH_WPA2_ENTERPRISE:
return "WPA2-Enterprise";
default:
return "Unknown";
}
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1