-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodemcu_oled_wifiscanner.ino
executable file
·128 lines (99 loc) · 2.87 KB
/
nodemcu_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#define OLED_ADDR 0x3C
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define Y_START_YELLOW 0
#define Y_START_BLUE 17
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
const unsigned char PROGMEM lock [] = {
0x00, 0x18, 0x24, 0x7E, 0x7E, 0x7E, 0x7E, 0x00,
};
const unsigned char bars_0 [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55,
};
const unsigned char bars_1 [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x55,
};
const unsigned char bars_2 [] = {
0x00, 0x00, 0x00, 0x04, 0x04, 0x14, 0x14, 0x55,
};
const unsigned char bars_3 [] = {
0x00, 0x01, 0x01, 0x05, 0x05, 0x15, 0x15, 0x55,
};
//------------------------------------------------------------------------------
int16_t cursor_x = 22;
int16_t cursor_y = 15;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT);
void setup() {
display.begin( SSD1306_SWITCHCAPVCC, OLED_ADDR);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
Serial.begin(9600);
}
void draw_lock() {
display.drawBitmap(0, cursor_y - 1, lock, 8, 8, 1);
}
void draw_signal_strength(int strength) {
if (-30 < strength) {
display.drawBitmap(10, cursor_y - 1, bars_3, 8, 8, 1);
} else if ((-30 > strength) && ( -50 < strength)) {
display.drawBitmap(10, cursor_y - 1, bars_2, 8, 8, 1);
} else if ((-50 > strength) && (-60 < strength)) {
display.drawBitmap(10, cursor_y - 1, bars_1, 8, 8, 1);
} else {
display.drawBitmap(10, cursor_y - 1, bars_0, 8, 8, 1);
}
}
void writeln_on_display(String text) {
display.setCursor(cursor_x, cursor_y);
display.println(text);
}
void loop() {
Serial.println("clear display ...");
display.clearDisplay();
display.drawRect(0, 0, 128, 16, WHITE);
display.setTextColor(WHITE);
display.setCursor(cursor_x, 4);
display.println("available WIFI");
cursor_y = Y_START_BLUE - 1;
display.setTextColor(WHITE);
Serial.println("Wifi scan started");
int n = WiFi.scanNetworks();
Serial.println("Wifi scan ended");
if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i) {
Serial.print(i + 1);
Serial.print(") ");
Serial.print(WiFi.SSID(i));
Serial.print(WiFi.RSSI(i));
Serial.print("dBm ");
draw_signal_strength(WiFi.RSSI(i));
if(ENC_TYPE_NONE == WiFi.encryptionType(i))
{
Serial.println(" <<***OPEN***>>");
}else{
Serial.println();
if (i < 6) {
draw_lock();
}
}
if (i < 6) {
writeln_on_display(WiFi.SSID(i));
cursor_y = cursor_y + 10;
}
}
}
Serial.println("");
display.display();
delay(5000);
WiFi.scanDelete();
}