-
Notifications
You must be signed in to change notification settings - Fork 3
/
ESP32_OLED_WifiScanner.ino
63 lines (57 loc) · 1.76 KB
/
ESP32_OLED_WifiScanner.ino
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
54
55
56
57
58
59
60
61
62
63
#include "WiFi.h"
#include "Wire.h"
#include "SSD1306.h"
SSD1306 display (0x3c, 5, 4);
void setup()
{
Serial.begin(115200);
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup done");
display.init();
display.flipScreenVertically ();
display.clear();
display.setTextAlignment (TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
}
void loop()
{
Serial.println("scan start");
display.setColor(BLACK);
display.fillRect(0,0,127,10);
display.setColor(WHITE);
display.drawString(0, 0, "Scanning... ");
display.display();
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
display.clear();
display.drawString(0, 0, "Scan results:");
display.display();
Serial.println("scan done");
if (n == 0) {
Serial.println("no networks found");
display.drawString(0,10,"No networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
display.drawString( 0 , i*8+10 , String(WiFi.SSID(i)));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
display.drawString( 100 , i*8+10 ,String(WiFi.RSSI(i)));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
delay(10);
}
}
Serial.println("");
display.display();
// Wait a bit before scanning again
delay(5000);
}