Add GPS tracker

This commit is contained in:
Just Call Me Koko
2025-07-25 13:27:31 -04:00
parent 701abd2aa7
commit 1febb4a13c
6 changed files with 105 additions and 34 deletions

View File

@@ -6,7 +6,7 @@ Buffer::Buffer(){
bufB = (uint8_t*)malloc(BUF_SIZE); bufB = (uint8_t*)malloc(BUF_SIZE);
} }
void Buffer::createFile(String name, bool is_pcap){ void Buffer::createFile(String name, bool is_pcap, bool is_gpx){
int i=0; int i=0;
if (is_pcap) { if (is_pcap) {
do{ do{
@@ -14,12 +14,18 @@ void Buffer::createFile(String name, bool is_pcap){
i++; i++;
} while(fs->exists(fileName)); } while(fs->exists(fileName));
} }
else { else if ((!is_pcap) && (!is_gpx)) {
do{ do{
fileName = "/"+name+"_"+(String)i+".log"; fileName = "/"+name+"_"+(String)i+".log";
i++; i++;
} while(fs->exists(fileName)); } while(fs->exists(fileName));
} }
else {
do{
fileName = "/"+name+"_"+(String)i+".gpx";
i++;
} while(fs->exists(fileName));
}
Serial.println(fileName); Serial.println(fileName);
@@ -46,7 +52,7 @@ void Buffer::open(bool is_pcap){
} }
} }
void Buffer::openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap) { void Buffer::openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap, bool is_gpx) {
bool save_pcap = settings_obj.loadSetting<bool>("SavePCAP"); bool save_pcap = settings_obj.loadSetting<bool>("SavePCAP");
if (!save_pcap) { if (!save_pcap) {
this->fs = NULL; this->fs = NULL;
@@ -57,7 +63,7 @@ void Buffer::openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap) {
this->fs = fs; this->fs = fs;
this->serial = serial; this->serial = serial;
if (this->fs) { if (this->fs) {
createFile(file_name, is_pcap); createFile(file_name, is_pcap, is_gpx);
} }
if (this->fs || this->serial) { if (this->fs || this->serial) {
open(is_pcap); open(is_pcap);
@@ -74,6 +80,10 @@ void Buffer::logOpen(String file_name, fs::FS* fs, bool serial) {
openFile(file_name, fs, serial, false); openFile(file_name, fs, serial, false);
} }
void Buffer::gpxOpen(String file_name, fs::FS* fs, bool serial) {
openFile(file_name, fs, serial, false, true);
}
void Buffer::add(const uint8_t* buf, uint32_t len, bool is_pcap){ void Buffer::add(const uint8_t* buf, uint32_t len, bool is_pcap){
// buffer is full -> drop packet // buffer is full -> drop packet
if((useA && bufSizeA + len >= BUF_SIZE && bufSizeB > 0) || (!useA && bufSizeB + len >= BUF_SIZE && bufSizeA > 0)){ if((useA && bufSizeA + len >= BUF_SIZE && bufSizeB > 0) || (!useA && bufSizeB + len >= BUF_SIZE && bufSizeA > 0)){

View File

@@ -21,13 +21,14 @@ class Buffer {
Buffer(); Buffer();
void pcapOpen(String file_name, fs::FS* fs, bool serial); void pcapOpen(String file_name, fs::FS* fs, bool serial);
void logOpen(String file_name, fs::FS* fs, bool serial); void logOpen(String file_name, fs::FS* fs, bool serial);
void gpxOpen(String file_name, fs::FS* fs, bool serial);
void append(wifi_promiscuous_pkt_t *packet, int len); void append(wifi_promiscuous_pkt_t *packet, int len);
void append(String log); void append(String log);
void save(); void save();
private: private:
void createFile(String name, bool is_pcap); void createFile(String name, bool is_pcap, bool is_gpx = false);
void open(bool is_pcap); void open(bool is_pcap);
void openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap); void openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap, bool is_gpx = false);
void add(const uint8_t* buf, uint32_t len, bool is_pcap); void add(const uint8_t* buf, uint32_t len, bool is_pcap);
void write(int32_t n); void write(int32_t n);
void write(uint32_t n); void write(uint32_t n);

View File

@@ -329,6 +329,7 @@ void CommandLine::runCommand(String input) {
#ifdef HAS_GPS #ifdef HAS_GPS
if (gps_obj.getGpsModuleStatus()) { if (gps_obj.getGpsModuleStatus()) {
int get_arg = this->argSearch(&cmd_args, "-g"); int get_arg = this->argSearch(&cmd_args, "-g");
int track_arg = this->argSearch(&cmd_args, "-t");
int nmea_arg = this->argSearch(&cmd_args, "-n"); int nmea_arg = this->argSearch(&cmd_args, "-n");
if (get_arg != -1) { if (get_arg != -1) {
@@ -385,6 +386,13 @@ void CommandLine::runCommand(String input) {
else else
Serial.println("You did not provide a valid argument"); Serial.println("You did not provide a valid argument");
} }
else if (track_arg != -1) {
wifi_scan_obj.currentScanMode = GPS_TRACKER;
#ifdef HAS_SCREEN
menu_function_obj.changeMenu(&menu_function_obj.gpsInfoMenu);
#endif
wifi_scan_obj.StartScan(GPS_TRACKER, TFT_CYAN);
}
else if(cmd_args.size()>1) else if(cmd_args.size()>1)
Serial.println("You did not provide a valid flag"); Serial.println("You did not provide a valid flag");
else else

View File

@@ -772,6 +772,7 @@ void MenuFunctions::main(uint32_t currentTime)
(wifi_scan_obj.currentScanMode == ESP_UPDATE) || (wifi_scan_obj.currentScanMode == ESP_UPDATE) ||
(wifi_scan_obj.currentScanMode == SHOW_INFO) || (wifi_scan_obj.currentScanMode == SHOW_INFO) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_GPS_DATA) || (wifi_scan_obj.currentScanMode == WIFI_SCAN_GPS_DATA) ||
(wifi_scan_obj.currentScanMode == GPS_TRACKER) ||
(wifi_scan_obj.currentScanMode == WIFI_SCAN_GPS_NMEA)) { (wifi_scan_obj.currentScanMode == WIFI_SCAN_GPS_NMEA)) {
if (wifi_scan_obj.orient_display) { if (wifi_scan_obj.orient_display) {
this->orientDisplay(); this->orientDisplay();
@@ -834,6 +835,7 @@ void MenuFunctions::main(uint32_t currentTime)
(wifi_scan_obj.currentScanMode != ESP_UPDATE) && (wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
(wifi_scan_obj.currentScanMode != SHOW_INFO) && (wifi_scan_obj.currentScanMode != SHOW_INFO) &&
(wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_DATA) && (wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_DATA) &&
(wifi_scan_obj.currentScanMode != GPS_TRACKER) &&
(wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_NMEA)) (wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_NMEA))
{ {
// Stop the current scan // Stop the current scan
@@ -909,6 +911,7 @@ void MenuFunctions::main(uint32_t currentTime)
(wifi_scan_obj.currentScanMode != ESP_UPDATE) && (wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
(wifi_scan_obj.currentScanMode != SHOW_INFO) && (wifi_scan_obj.currentScanMode != SHOW_INFO) &&
(wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_DATA) && (wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_DATA) &&
(wifi_scan_obj.currentScanMode != GPS_TRACKER) &&
(wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_NMEA)) (wifi_scan_obj.currentScanMode != WIFI_SCAN_GPS_NMEA))
{ {
// Stop the current scan // Stop the current scan
@@ -3183,10 +3186,17 @@ void MenuFunctions::RunSetup()
wifi_scan_obj.StartScan(WIFI_SCAN_GPS_NMEA, TFT_ORANGE); wifi_scan_obj.StartScan(WIFI_SCAN_GPS_NMEA, TFT_ORANGE);
}); });
this->addNodes(&deviceMenu, "GPS Tracker", TFTGREEN, NULL, GPS_MENU, [this]() {
wifi_scan_obj.currentScanMode = GPS_TRACKER;
this->changeMenu(&gpsInfoMenu);
wifi_scan_obj.StartScan(GPS_TRACKER, TFT_CYAN);
});
// GPS Info Menu // GPS Info Menu
gpsInfoMenu.parentMenu = &deviceMenu; gpsInfoMenu.parentMenu = &deviceMenu;
this->addNodes(&gpsInfoMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() { this->addNodes(&gpsInfoMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() {
wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; if(wifi_scan_obj.currentScanMode != GPS_TRACKER)
wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF;
wifi_scan_obj.StartScan(WIFI_SCAN_OFF); wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
this->changeMenu(gpsInfoMenu.parentMenu); this->changeMenu(gpsInfoMenu.parentMenu);
}); });

View File

@@ -982,6 +982,9 @@ void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
gps_obj.enable_queue(); gps_obj.enable_queue();
#endif #endif
} }
else if (scan_mode == GPS_TRACKER) {
RunSetupGPSTracker();
}
else if (scan_mode == WIFI_PING_SCAN) else if (scan_mode == WIFI_PING_SCAN)
RunPingScan(scan_mode, color); RunPingScan(scan_mode, color);
else if (scan_mode == WIFI_PORT_SCAN_ALL) else if (scan_mode == WIFI_PORT_SCAN_ALL)
@@ -1206,6 +1209,10 @@ void WiFiScan::StopScan(uint8_t scan_mode)
evil_portal_obj.has_ap = false; evil_portal_obj.has_ap = false;
} }
else if ((currentScanMode == GPS_TRACKER)) {
this->writeFooter();
}
else if ((currentScanMode == BT_SCAN_ALL) || else if ((currentScanMode == BT_SCAN_ALL) ||
(currentScanMode == BT_SCAN_AIRTAG) || (currentScanMode == BT_SCAN_AIRTAG) ||
@@ -1424,6 +1431,17 @@ void WiFiScan::startLog(String file_name) {
); );
} }
void WiFiScan::startGPX(String file_name) {
buffer_obj.gpxOpen(
file_name,
#if defined(HAS_SD)
sd_obj.supported ? &SD :
#endif
NULL,
save_serial // Set with commandline options
);
}
void WiFiScan::parseBSSID(const char* bssidStr, uint8_t* bssid) { void WiFiScan::parseBSSID(const char* bssidStr, uint8_t* bssid) {
sscanf(bssidStr, "%02X:%02X:%02X:%02X:%02X:%02X", sscanf(bssidStr, "%02X:%02X:%02X:%02X:%02X:%02X",
&bssid[0], &bssid[1], &bssid[2], &bssid[0], &bssid[1], &bssid[2],
@@ -2119,37 +2137,49 @@ void WiFiScan::RunGenerateSSIDs(int count) {
#endif #endif
} }
/*void WiFiScan::RunShutdownBLE() { void WiFiScan::logPoint(String lat, String lon, float alt, String datetime) {
#ifdef HAS_SCREEN datetime.replace(" ", "T");
display_obj.tft.setTextWrap(false); datetime += "Z";
display_obj.tft.setFreeFont(NULL);
display_obj.tft.setCursor(0, 100);
display_obj.tft.setTextSize(1);
display_obj.tft.setTextColor(TFT_CYAN);
display_obj.tft.print(F(text_table4[18]));
#endif
if (this->ble_initialized) { buffer_obj.append(" <trkpt lat=\"" + lat + "\" lon=\"" + lon + "\">\n");
this->shutdownBLE(); buffer_obj.append(" <ele>" + String(alt, 2) + "</ele>\n");
#ifdef HAS_SCREEN buffer_obj.append(" <time>" + datetime + "</time>\n");
display_obj.tft.setTextColor(TFT_GREEN); buffer_obj.append(" </trkpt>\n");
display_obj.tft.println(F("OK")); //gpxFile.flush();
#endif }
}
else {
#ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_RED);
display_obj.tft.println(F(text17));
display_obj.tft.println(F(text_table4[19]));
#endif
}
}*/
void WiFiScan::RunGPSInfo() { void WiFiScan::writeHeader() {
Serial.println("Writing header to GPX file...");
buffer_obj.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
buffer_obj.append("<gpx version=\"1.1\" creator=\"ESP32 GPS Logger\" xmlns=\"http://www.topografix.com/GPX/1/1\">\n");
buffer_obj.append(" <trk>\n");
buffer_obj.append(" <name>ESP32 Track</name>\n");
buffer_obj.append(" <trkseg>\n");
}
void WiFiScan::writeFooter() {
Serial.println("Writing footer to GPX file...\n");
buffer_obj.append(" </trkseg>\n");
buffer_obj.append(" </trk>\n");
buffer_obj.append("</gpx>\n");
}
void WiFiScan::RunSetupGPSTracker() {
this->startGPX("tracker");
this->writeHeader();
initTime = millis();
}
void WiFiScan::RunGPSInfo(bool tracker) {
#ifdef HAS_GPS #ifdef HAS_GPS
String text=gps_obj.getText(); String text=gps_obj.getText();
if (tracker) {
if (gps_obj.getFixStatus()) {
this->logPoint(gps_obj.getLat(), gps_obj.getLon(), gps_obj.getAlt(), gps_obj.getDatetime());
}
}
Serial.println("Refreshing GPS Data on screen..."); Serial.println("Refreshing GPS Data on screen...");
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
@@ -7569,6 +7599,12 @@ void WiFiScan::main(uint32_t currentTime)
this->RunGPSInfo(); this->RunGPSInfo();
} }
} }
else if (currentScanMode == GPS_TRACKER) {
if (currentTime - initTime >= 1000) {
this->initTime = millis();
this->RunGPSInfo(true);
}
}
else if (currentScanMode == WIFI_SCAN_GPS_NMEA) { else if (currentScanMode == WIFI_SCAN_GPS_NMEA) {
if (currentTime - initTime >= 1000) { if (currentTime - initTime >= 1000) {
this->initTime = millis(); this->initTime = millis();

View File

@@ -111,6 +111,7 @@
#define WIFI_CONNECTED 52 #define WIFI_CONNECTED 52
#define WIFI_PING_SCAN 53 #define WIFI_PING_SCAN 53
#define WIFI_PORT_SCAN_ALL 54 #define WIFI_PORT_SCAN_ALL 54
#define GPS_TRACKER 55
#define BASE_MULTIPLIER 4 #define BASE_MULTIPLIER 4
@@ -455,7 +456,7 @@ class WiFiScan
void broadcastCustomBeacon(uint32_t current_time, AccessPoint custom_ssid); void broadcastCustomBeacon(uint32_t current_time, AccessPoint custom_ssid);
void broadcastSetSSID(uint32_t current_time, const char* ESSID); void broadcastSetSSID(uint32_t current_time, const char* ESSID);
void RunAPScan(uint8_t scan_mode, uint16_t color); void RunAPScan(uint8_t scan_mode, uint16_t color);
void RunGPSInfo(); void RunGPSInfo(bool tracker = false);
void RunGPSNmea(); void RunGPSNmea();
void RunMimicFlood(uint8_t scan_mode, uint16_t color); void RunMimicFlood(uint8_t scan_mode, uint16_t color);
void RunPwnScan(uint8_t scan_mode, uint16_t color); void RunPwnScan(uint8_t scan_mode, uint16_t color);
@@ -477,6 +478,9 @@ class WiFiScan
void RunPortScanAll(uint8_t scan_mode, uint16_t color); void RunPortScanAll(uint8_t scan_mode, uint16_t color);
bool checkMem(); bool checkMem();
void parseBSSID(const char* bssidStr, uint8_t* bssid); void parseBSSID(const char* bssidStr, uint8_t* bssid);
void logPoint(String lat, String lon, float alt, String datetime);
void writeHeader();
void writeFooter();
public: public:
@@ -621,6 +625,7 @@ class WiFiScan
void RunLoadAPList(); void RunLoadAPList();
void RunSaveATList(bool save_as = true); void RunSaveATList(bool save_as = true);
void RunLoadATList(); void RunLoadATList();
void RunSetupGPSTracker();
void channelHop(); void channelHop();
uint8_t currentScanMode = 0; uint8_t currentScanMode = 0;
void main(uint32_t currentTime); void main(uint32_t currentTime);
@@ -632,6 +637,7 @@ class WiFiScan
bool save_serial = false; bool save_serial = false;
void startPcap(String file_name); void startPcap(String file_name);
void startLog(String file_name); void startLog(String file_name);
void startGPX(String file_name);
//String macToString(const Station& station); //String macToString(const Station& station);
static void getMAC(char *addr, uint8_t* data, uint16_t offset); static void getMAC(char *addr, uint8_t* data, uint16_t offset);