#include "frontend.h" Frontend::Frontend(unsigned long idletime) : server(80) { // AP parameters Serial.print("Setting soft-AP ... "); if(WiFi.softAP("ESP_RIDS", "makkauhijau")) { Serial.print("Access Point IP: "); Serial.println(WiFi.softAPIP()); Serial.println("Ready"); } else { Serial.println("Failed!"); } // Specify the functions which will be executed upon corresponding GET request server.on("/", std::bind(&Frontend::handleOnConnect, this)); server.on("/getlocation", std::bind(&Frontend::handleSetCoords, this)); server.on("/numdrones", std::bind(&Frontend::handleNumDrones, this)); server.on("/start", std::bind(&Frontend::startSpoof, this)); server.onNotFound(std::bind(&Frontend::handleNotFound, this)); // read parameters from EEPROM EEPROM.begin(512); // if the value at address 42 is 42, then we know that we have past data if (EEPROM.read(42) == 42) { Serial.println("EEPROM found, reusing old values..."); EEPROM.get(latitude_addr, latitude); EEPROM.get(longitude_addr, longitude); EEPROM.get(num_drones_addr, num_drones); } else { Serial.println("EEPROM data not written before..."); } // Starting the Server server.begin(); // record the time the server started and when to end timer = millis(); maxtime = timer + idletime; } void Frontend::handleClient() { server.handleClient(); // automatically start spoofing if we've passed the maxtime if (millis() > maxtime) { startSpoof(); } } void Frontend::handleOnConnect() { Serial.println("Client Connected"); server.send(200, "text/html", HTML()); } void Frontend::handleSetCoords() { latitude = server.arg("latitude").toFloat(); longitude = server.arg("longitude").toFloat(); EEPROM.put(latitude_addr, latitude); EEPROM.put(longitude_addr, latitude); server.send(200, "text/html", HTML()); } void Frontend::handleNumDrones() { num_drones = server.arg("numdrones").toInt(); EEPROM.put(num_drones_addr, num_drones); server.send(200, "text/html", HTML()); } void Frontend::startSpoof() { do_spoof = true; server.stop(); WiFi.softAPdisconnect (true); EEPROM.put(42, 42); EEPROM.end(); } void Frontend::handleNotFound() { server.send(404, "text/plain", "Not found"); } String Frontend::HTML() { String msg = R"rawliteral( Remote ID Spoofer

Remote ID Spoofer

Latitude:
Longitude:
No. of Drones:
)rawliteral"; msg += "

Current Coordinates:
"; msg += String(latitude, 10); msg += ", "; msg += String(longitude, 10); msg += "

\n"; msg += "

Current No. of Drones:"; msg += String(num_drones); msg += "

\n"; msg += "Start Spoofing\n"; msg += "

Pressing this button will cause the device to turn off the web server and enter spoofing only mode.\n"; msg += "Please confirm your GPS coordinates before doing so.\n"; msg += "You will not be able to reconnect to this page without a power cycle.

\n"; msg += R"rawliteral( )rawliteral"; return msg; }