pleasedontcode

WiFi Sentinel rev_01

Sep 29th, 2025
83
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 Sentinel
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-09-30 03:56: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. /* START CODE */
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <WiFi.h>
  29.  
  30. /*
  31. Incompatibilities with USER CODE:
  32. - 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.
  33. - 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.
  34. */
  35.  
  36.  
  37. /****** FUNCTION PROTOTYPES *****/
  38. void setup(void);
  39. void loop(void);
  40. void analyze_rf_environment(void);
  41.  
  42. void setup(void)
  43. {
  44.     // put your setup code here, to run once:
  45.     Serial.begin(115200);
  46.     delay(100);
  47.     Serial.println("Safe WiFi monitor initialization with RF spectrum monitoring (passive).");
  48.  
  49.     // Initialize WiFi in station mode and disconnect any previous connections
  50.     WiFi.mode(WIFI_STA);
  51.     WiFi.disconnect(true);
  52.  
  53.     // Initialize a simple LED indicator for RF activity (built-in LED on most ESP32 boards)
  54.     const int ledPin = 2; // Built-in LED GPIO; adjust if needed for your board
  55.     pinMode(ledPin, OUTPUT);
  56.     digitalWrite(ledPin, LOW);
  57.  
  58.     Serial.println("Starting safe WiFi scan for monitoring only.");
  59. }
  60.  
  61. void analyze_rf_environment(void)
  62. {
  63.     // Passive RF spectrum analysis by scanning nearby networks
  64.     static unsigned long lastScan = 0;
  65.     const unsigned long scanInterval = 5000; // 5 seconds
  66.     unsigned long now = millis();
  67.     if (now - lastScan >= scanInterval) {
  68.         lastScan = now;
  69.         int n = WiFi.scanNetworks();
  70.         if (n <= 0) {
  71.             const int ledPin = 2;
  72.             digitalWrite(ledPin, LOW);
  73.             return;
  74.         }
  75.  
  76.         long sum_rssi = 0;
  77.         for (int i = 0; i < n; ++i) {
  78.             sum_rssi += WiFi.RSSI(i);
  79.         }
  80.         int avg_rssi = (int)(sum_rssi / n);
  81.  
  82.         // If average RSSI is relatively high (strong signals on average), indicate busy spectrum
  83.         // Typical RSSI values: -30 very strong, -90 weak
  84.         const int ledPin = 2;
  85.         if (avg_rssi > -65) {
  86.             // Busy spectrum, turn the indicator ON
  87.             digitalWrite(ledPin, HIGH);
  88.         } else {
  89.             // Spectrum looks quieter, turn the indicator OFF
  90.             digitalWrite(ledPin, LOW);
  91.         }
  92.  
  93.         Serial.print("RF Spectrum avg RSSI: ");
  94.         Serial.println(avg_rssi);
  95.         WiFi.scanDelete();
  96.     }
  97. }
  98.  
  99. void loop(void)
  100. {
  101.     // Passive monitoring tasks
  102.     analyze_rf_environment();
  103.  
  104.     // Existing safe monitoring: perform a periodic WiFi scan and print results
  105.     static unsigned long lastPrint = 0;
  106.     const unsigned long printInterval = 5000; // 5 seconds
  107.     unsigned long now = millis();
  108.     if (now - lastPrint >= printInterval) {
  109.         lastPrint = now;
  110.         int n = WiFi.scanNetworks();
  111.         Serial.print("Networks found: ");
  112.         Serial.println(n);
  113.         for (int i = 0; i < n; ++i) {
  114.             Serial.print("  SSID: ");
  115.             Serial.print(WiFi.SSID(i));
  116.             Serial.print("  RSSI: ");
  117.             Serial.println(WiFi.RSSI(i));
  118.         }
  119.         WiFi.scanDelete();
  120.     }
  121. }
  122.  
  123. /* END CODE */
  124.  
Advertisement
Add Comment
Please, Sign In to add comment