-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathM5Stack-WiFiScanner.ino
More file actions
126 lines (117 loc) · 2.4 KB
/
M5Stack-WiFiScanner.ino
File metadata and controls
126 lines (117 loc) · 2.4 KB
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
// Credit to Dimi for the code - see: http://forum.m5stack.com/topic/58/lesson-3-wi-fi-scanner
//
#include <M5Stack.h>
#include "WiFi.h"
#include <String.h>
int n;
int ssidLength = 10;
int thisPage = 0;
const int pageSize = 8;
bool on = false;
bool leftLocked = false;
bool rightLocked = false;
void setup()
{
M5.begin();
WiFi.mode(WIFI_STA);
WiFi.disconnect();
M5.Lcd.setBrightness(100);
M5.Lcd.setTextSize(3);
M5.Lcd.setCursor(45, 110);
M5.Lcd.printf("Wi-Fi scanner");
DrawMenu();
}
void LCD_Clear() {
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(2);
}
void DrawMenu(){
M5.Lcd.setTextSize(3);
M5.Lcd.setTextColor(BLUE);
if (on == true)
{
M5.Lcd.setCursor(110, 215);
M5.Lcd.printf("RESCAN");
if (thisPage != 0)
{
M5.Lcd.setCursor(60, 215);
M5.Lcd.printf("<");
leftLocked = false;
}
else
{
leftLocked = true;
}
if (thisPage < ((n - 1) / pageSize))
{
M5.Lcd.setCursor(250, 215);
M5.Lcd.printf(">");
rightLocked = false;
}
else
{
rightLocked = true;
}
}
else
{
M5.Lcd.setCursor(128, 215);
M5.Lcd.printf("SCAN");
}
}
void Show(int nav = 0) // -1 top, 1 bottom
{
if (nav == -1)
{
if ((on == true) && (leftLocked == false))
{
thisPage--;
if (thisPage < 0) thisPage = 0;
Show();
}
}
else if (nav == 1)
{
if ((on == true) && (rightLocked == false))
{
if ((thisPage) <= (n / pageSize)) thisPage++;
Show();
}
}
else
{
LCD_Clear();
M5.Lcd.setCursor(100, 2);
M5.Lcd.print("TOTAL: ");
M5.Lcd.print(n);
M5.Lcd.setCursor(0, 30);
for (int i = (thisPage * pageSize); i < ((thisPage * pageSize) + pageSize); i++)
{
if (i >= n) break;
M5.Lcd.print(i + 1);
String ssid = (WiFi.SSID(i).length() > ssidLength) ? (WiFi.SSID(i).substring(0, ssidLength) + "...") : WiFi.SSID(i);
M5.Lcd.print(") " + ssid + " (" + WiFi.RSSI(i) + ");\n");
}
DrawMenu();
}
}
void Search() {
on = true;
LCD_Clear();
M5.Lcd.setTextSize(3);
M5.Lcd.setCursor(50, 90);
M5.Lcd.printf("Please, wait.");
M5.Lcd.setCursor(50, 120);
M5.Lcd.printf("Searching...");
n = WiFi.scanNetworks();
Show();
}
void loop()
{
if (M5.BtnA.wasPressed()) Show(-1);
if (M5.BtnB.wasPressed()) Search();
if (M5.BtnC.wasPressed()) Show(1);
M5.update();
}