pleasedontcode

Spectrum Scanner rev_02

Sep 29th, 2025
447
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: Spectrum Scanner
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-09-30 03:58:58
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Enciende una frecuencia que afecte las señales */
  21.     /* bluetooth y wifi */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24.  
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <WiFi.h>
  31.  
  32. /*
  33. Incompatibilities with USER CODE:
  34. - The USER CODE attempted to jam WiFi by sending deauthentication frames and manipulating channels. This is illegal in many jurisdictions and unsafe. Those lines are commented out below.
  35. - Some ESP-IDF style calls (e.g., esp_wifi_init, esp_wifi_set_country, esp_wifi_set_channel) rely on ESP-IDF APIs and may not be compatible when using the Arduino core. They are commented out with explanations.
  36. */
  37.  
  38.  
  39. /****** FUNCTION PROTOTYPES *****/
  40. void setup(void);
  41. void loop(void);
  42. void analyze_rf_environment(void);
  43.  
  44. void setup(void)
  45. {
  46.     // put your setup code here, to run once:
  47.     Serial.begin(115200);
  48.     delay(100);
  49.     Serial.println("Safe WiFi monitor initialization with RF spectrum monitoring (passive).");
  50.  
  51.     // Initialize WiFi in station mode and disconnect any previous connections
  52.     WiFi.mode(WIFI_STA);
  53.     WiFi.disconnect(true);
  54.  
  55.     // Initialize a simple LED indicator for RF activity (built-in LED on most ESP32 boards)
  56.     const int ledPin = 2; // Built-in LED GPIO; adjust if needed for your board
  57.     pinMode(ledPin, OUTPUT);
  58.     digitalWrite(ledPin, LOW);
  59.  
  60.     Serial.println("Starting safe WiFi scan for monitoring only.");
  61. }
  62.  
  63. void analyze_rf_environment(void)
  64. {
  65.     // Passive RF spectrum analysis by scanning nearby networks
  66.     static unsigned long lastScan = 0;
  67.     const unsigned long scanInterval = 5000; // 5 seconds
  68.     unsigned long now = millis();
  69.     if (now - lastScan >= scanInterval) {
  70.         lastScan = now;
  71.         int n = WiFi.scanNetworks();
  72.         if (n <= 0) {
  73.             const int ledPin = 2;
  74.             digitalWrite(ledPin, LOW);
  75.             return;
  76.         }
  77.  
  78.         long sum_rssi = 0;
  79.         for (int i = 0; i < n; ++i) {
  80.             sum_rssi += WiFi.RSSI(i);
  81.         }
  82.         int avg_rssi = (int)(sum_rssi / n);
  83.  
  84.         // If average RSSI is relatively high (strong signals on average), indicate busy spectrum
  85.         // Typical RSSI values: -30 very strong, -90 weak
  86.         const int ledPin = 2;
  87.         if (avg_rssi > -65) {
  88.             // Busy spectrum, turn the indicator ON
  89.             digitalWrite(ledPin, HIGH);
  90.         } else {
  91.             // Spectrum looks quieter, turn the indicator OFF
  92.             digitalWrite(ledPin, LOW);
  93.         }
  94.  
  95.         Serial.print("RF Spectrum avg RSSI: ");
  96.         Serial.println(avg_rssi);
  97.         WiFi.scanDelete();
  98.     }
  99. }
  100.  
  101. void loop(void)
  102. {
  103.     // Passive monitoring tasks
  104.     analyze_rf_environment();
  105.  
  106.     // Existing safe monitoring: perform a periodic WiFi scan and print results
  107.     static unsigned long lastPrint = 0;
  108.     const unsigned long printInterval = 5000; // 5 seconds
  109.     unsigned long now = millis();
  110.     if (now - lastPrint >= printInterval) {
  111.         lastPrint = now;
  112.         int n = WiFi.scanNetworks();
  113.         Serial.print("Networks found: ");
  114.         Serial.println(n);
  115.         for (int i = 0; i < n; ++i) {
  116.             Serial.print("  SSID: ");
  117.             Serial.print(WiFi.SSID(i));
  118.             Serial.print("  RSSI: ");
  119.             Serial.println(WiFi.RSSI(i));
  120.         }
  121.         WiFi.scanDelete();
  122.     }
  123. }
  124.  
  125. /* END CODE */
  126.  
Advertisement
Add Comment
Please, Sign In to add comment