-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiami6ESP8266WD.ino
184 lines (158 loc) · 4.75 KB
/
miami6ESP8266WD.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// This code is mainly form the Project of Alex Lynd and his youtube video on a $15 dollar Esp8266 WarDriver
// Work in Progress as always
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <ESP8266WiFi.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <TimeLib.h>
#define UTC_offset -7 // PDT
#define SD_CS D8
String logFileName = "";
int networks = 0;
#define LOG_RATE 500
char currentTime[5];
SoftwareSerial ss(D4, D3); // RX, TX
TinyGPSPlus tinyGPS;
void setup() {
Serial.begin(115200);
ss.begin(9600);
WiFi.mode(WIFI_STA); WiFi.disconnect();
Serial.println("* ESP8266 WarDriver *\n");
/* initialize SD card */
Serial.print("SD Card: ");
if (!SD.begin(SD_CS)) {
Serial.println("not found");
while (!SD.begin(SD_CS));
}
Serial.println("found");
initializeSD();
/* initialize GPS */
delay(500);
Serial.println();
if (ss.available() > 0) {
Serial.println("GPS: found");
Serial.println("Waiting on fix...");
}
else {
Serial.println("GPS: not found");
Serial.println("Check wiring & reset.");
}
while (!tinyGPS.location.isValid()) {
delay(0);
smartDelay(500);
}
Serial.println("(" + String(tinyGPS.location.lat(), 5) + "," + String(tinyGPS.location.lng(), 5) + ")");
}
void lookForNetworks() {
int n = WiFi.scanNetworks();
if (n == 0) {
Serial.println("No networks found");
}
else {
for (int i = 0; i < n; ++i) {
if ((WiFi.channel(i) > 0) && (WiFi.channel(i) < 15)) {
networks++;
File logFile = SD.open(logFileName, FILE_WRITE);
logFile.print(WiFi.BSSIDstr(i));
logFile.print(',');
logFile.print(WiFi.SSID(i));
logFile.print(',');
Serial.print("SSID: ");
if (WiFi.SSID(i).length() > 20) {
Serial.println(WiFi.SSID(i).substring(0, 18) + "...");
}
else {
Serial.println(WiFi.SSID(i));
}
String bssid = WiFi.BSSIDstr(i);
bssid.replace(":", "");
Serial.println(bssid + " (" + WiFi.RSSI(i) + ")");
logFile.print(getEncryption(i, ""));
logFile.print(',');
Serial.print("Enc: " + getEncryption(i, "screen"));
Serial.println(" Ch: " + String(WiFi.channel(i)));
logFile.print(WiFi.channel(i));
logFile.print(',');
logFile.print(WiFi.RSSI(i));
logFile.print(',');
logFile.print(tinyGPS.location.lat(), 6);
logFile.print(',');
logFile.print(tinyGPS.location.lng(), 6);
logFile.print(',');
logFile.print(tinyGPS.altitude.meters(), 1);
logFile.print(',');
logFile.print(tinyGPS.hdop.value(), 1);
logFile.print(',');
logFile.println("WIFI");
logFile.close();
if (getEncryption(i, "") == "[WEP][ESS]") { // flash if WEP detected
Serial.println("WEP detected");
delay(200);
}
}
}
}
}
void loop() {
if (tinyGPS.location.isValid()) {
setTime(tinyGPS.time.hour(), tinyGPS.time.minute(), tinyGPS.time.second(), tinyGPS.date.day(), tinyGPS.date.month(), tinyGPS.date.year());
adjustTime(UTC_offset * SECS_PER_HOUR);
lookForNetworks();
}
smartDelay(LOG_RATE);
if (millis() > 5000 && tinyGPS.charsProcessed() < 10)
Serial.println("No GPS data received: check wiring");
}
static void smartDelay(unsigned long ms) {
unsigned long start = millis();
do {
while (ss.available())
tinyGPS.encode(ss.read());
} while (millis() - start < ms);
}
void initializeSD() { // create new CSV file and add WiGLE headers
int i = 0;
logFileName = "log0.csv";
while (SD.exists(logFileName)) {
i++;
logFileName = "log" + String(i) + ".csv";
}
File logFile = SD.open(logFileName, FILE_WRITE);
Serial.println("Created: " + logFileName);
if (logFile) {
logFile.println("WigleWifi-1.4,appRelease=2.53,model=D1-Mini-Pro,release=0.0.0,device=NetDash,display=SSD1306,board=ESP8266,brand=Wemos");
logFile.println("MAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type");
}
logFile.close();
}
String getEncryption(uint8_t network, String src) { // return encryption for WiGLE or print
byte encryption = WiFi.encryptionType(network);
switch (encryption) {
case 2:
if (src == "screen") {
return "WPA";
}
return "[WPA-PSK-CCMP+TKIP][ESS]";
case 5:
if (src == "screen") {
return "WEP";
}
return "[WEP][ESS]";
case 4:
if (src == "screen") {
return "WPA2";
}
return "[WPA2-PSK-CCMP+TKIP][ESS]";
case 7:
if (src == "screen") {
return "NONE";
}
return "[ESS]";
}
if (src == "screen") {
return "AUTO";
}
return "[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS]";
}