|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+#include "rpcWiFi.h"
|
|
|
2
|
+#include "TFT_eSPI.h"
|
|
|
3
|
+
|
|
|
4
|
+TFT_eSPI tft;
|
|
|
5
|
+
|
|
|
6
|
+void setup()
|
|
|
7
|
+{
|
|
|
8
|
+ // Set up the display
|
|
|
9
|
+ tft.begin();
|
|
|
10
|
+ tft.setRotation(3);
|
|
|
11
|
+ tft.fillScreen(TFT_BLACK);
|
|
|
12
|
+ tft.setFreeFont(&FreeSans9pt7b);
|
|
|
13
|
+ tft.fillScreen(TFT_BLACK);
|
|
|
14
|
+
|
|
|
15
|
+ // Intro messages
|
|
|
16
|
+ tft.setTextColor(TFT_WHITE);
|
|
|
17
|
+ tft.drawString("Wi-Fi Scanner", 10, 10);
|
|
|
18
|
+ tft.setTextColor(TFT_RED);
|
|
|
19
|
+ tft.drawString("Scanning...", 10, 30);
|
|
|
20
|
+
|
|
|
21
|
+ // Set up WiFi
|
|
|
22
|
+ WiFi.mode(WIFI_STA);
|
|
|
23
|
+ WiFi.disconnect(); // Ensure we are not connected to an AP
|
|
|
24
|
+}
|
|
|
25
|
+
|
|
|
26
|
+void loop()
|
|
|
27
|
+{
|
|
|
28
|
+ // Scan for networks and create array of seen SSIDs
|
|
|
29
|
+ int number_of_networks = WiFi.scanNetworks();
|
|
|
30
|
+ String seen_ssids[number_of_networks];
|
|
|
31
|
+
|
|
|
32
|
+ // Reset the screen to it's title only to prepare to display APs
|
|
|
33
|
+ tft.fillScreen(TFT_BLACK);
|
|
|
34
|
+ tft.setTextColor(TFT_WHITE);
|
|
|
35
|
+ tft.drawString("Wi-Fi Networks:", 10, 10);
|
|
|
36
|
+
|
|
|
37
|
+ // Text positioning (starting at 10)
|
|
|
38
|
+ int textpos = 30;
|
|
|
39
|
+ int seen_ptr = 0;
|
|
|
40
|
+
|
|
|
41
|
+ // Loop through networks
|
|
|
42
|
+ for(int i = 0; i < number_of_networks; i++)
|
|
|
43
|
+ {
|
|
|
44
|
+ // Check if we already saw that SSID, we don't have much
|
|
|
45
|
+ // screen space, so there's no point showing repeats
|
|
|
46
|
+ bool seen = false;
|
|
|
47
|
+ for(int x = 0; x < number_of_networks; x++)
|
|
|
48
|
+ {
|
|
|
49
|
+ if(WiFi.SSID(i) == seen_ssids[x])
|
|
|
50
|
+ {
|
|
|
51
|
+ seen = true;
|
|
|
52
|
+ break;
|
|
|
53
|
+ }
|
|
|
54
|
+ }
|
|
|
55
|
+
|
|
|
56
|
+ // As long as it isn't already displayed, continue
|
|
|
57
|
+ if(!seen && WiFi.SSID(i)!="")
|
|
|
58
|
+ {
|
|
|
59
|
+ // Add a "*" to the start of the SSID if it is locked
|
|
|
60
|
+ String enc_string = "* ";
|
|
|
61
|
+ if(WiFi.encryptionType(i) == WIFI_AUTH_OPEN)
|
|
|
62
|
+ {
|
|
|
63
|
+ enc_string = "";
|
|
|
64
|
+ }
|
|
|
65
|
+ String text = enc_string + WiFi.SSID(i);
|
|
|
66
|
+
|
|
|
67
|
+ // Determine the font color based on signal strength
|
|
|
68
|
+ if(WiFi.RSSI(i) > -61){tft.setTextColor(TFT_GREEN);}
|
|
|
69
|
+ else if(WiFi.RSSI(i) < -60 && WiFi.RSSI(i) > -91){tft.setTextColor(TFT_ORANGE);}
|
|
|
70
|
+ else{tft.setTextColor(TFT_RED);}
|
|
|
71
|
+
|
|
|
72
|
+ // Print the SSID to screen
|
|
|
73
|
+ tft.drawString(text, 10, textpos);
|
|
|
74
|
+
|
|
|
75
|
+ // Adjust necessary counters
|
|
|
76
|
+ textpos += 20;
|
|
|
77
|
+ seen_ssids[seen_ptr] = WiFi.SSID(i);
|
|
|
78
|
+ seen_ptr++;
|
|
|
79
|
+ }
|
|
|
80
|
+ }
|
|
|
81
|
+ delay(5000);
|
|
|
82
|
+}
|