Advertisement
pleasedontcode

WiFi Scanner rev_01

Feb 13th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: WiFi Scanner
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-02-13 08:19:09
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* in promiscuous mode scan wifi for SSID */
  21.     /* "Lastmanstanding" and capture its 4-way handshake */
  22.     /* and store results to sd card */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <WiFi.h>
  27. #include <SPI.h>
  28. #include <SD.h>
  29.  
  30. /****** DEFINITION OF SYSTEM REQUIREMENTS *****/
  31. // System Requirement 1: Scan WiFi for SSID "Lastmanstanding" and capture its 4-way handshake
  32. const char* ssid = "Lastmanstanding";
  33. const char* password = "password";
  34.  
  35. // System Requirement 2: Store results to SD card
  36. File datafile;
  37.  
  38. /***** DEFINITION OF SPI PINS *****/
  39. const uint8_t SD_SCK_PIN = 18;
  40. const uint8_t SD_MISO_PIN = 19;
  41. const uint8_t SD_MOSI_PIN = 23;
  42. const uint8_t SD_SS_PIN = 5;
  43.  
  44. void setup() {
  45.   // Initialize serial communication
  46.   Serial.begin(9600);
  47.  
  48.   // Set SD chip select pin as an output
  49.   pinMode(SD_SS_PIN, OUTPUT);
  50.  
  51.   // Start the SPI library
  52.   SPI.begin(SD_SCK_PIN, SD_MISO_PIN, SD_MOSI_PIN, SD_SS_PIN);
  53.  
  54.   // Check if SD card exists and can be initialized
  55.   if (!SD.begin(SD_SS_PIN)) {
  56.     Serial.println("SD card initialization failed!");
  57.     while (1);
  58.   }
  59.  
  60.   // Connect to WiFi network
  61.   WiFi.begin(ssid, password);
  62.   while (WiFi.status() != WL_CONNECTED) {
  63.     delay(1000);
  64.     Serial.println("Connecting to WiFi...");
  65.   }
  66.  
  67.   // Open the data file on SD card
  68.   if (SD.exists("data.txt")) {
  69.     datafile = SD.open("data.txt", FILE_APPEND);
  70.   } else {
  71.     datafile = SD.open("data.txt", FILE_WRITE);
  72.     datafile.println("SSID,SIGNAL_STRENGTH,TIME");
  73.   }
  74. }
  75.  
  76. void loop() {
  77.   // System Requirement 1: Scan WiFi for SSID "Lastmanstanding" and capture its 4-way handshake
  78.   if (WiFi.status() == WL_CONNECTED) {
  79.     // Get the SSID and signal strength
  80.     String ssid = WiFi.SSID();
  81.     int signalStrength = WiFi.RSSI();
  82.  
  83.     // Get the current date and time
  84.     unsigned long currentTime = millis();
  85.  
  86.     // Print and store the data
  87.     Serial.print("SSID: ");
  88.     Serial.println(ssid);
  89.     Serial.print("Signal Strength: ");
  90.     Serial.println(signalStrength);
  91.     datafile.print(ssid);
  92.     datafile.print(",");
  93.     datafile.print(signalStrength);
  94.     datafile.print(",");
  95.     datafile.println(currentTime);
  96.  
  97.     delay(5000); // Delay for 5 seconds
  98.   }
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement