WiFi Surveillance Tool

A very simple configuration of the NodeMCU ESP-12 / ESP8266 board that can be used to check the status of connection of Smartphones to you local WiFi network. This way you know if the person associated to a given Smartphone is in radius or not!

You only need the following:

  • 8x red leds;
  • 1x Green led;
  • 9x 220ohm resitors;
  • Breadboard;
  • The NodeMCU ESP-12 / ESP8266

Connect from D0 to D7 as seen in pictures.

Step 1: Mise En Place

Follow the YouTube Video and Download and install the ESP8266Ping Library to get everything ready for upload!

Step 2: Upload the Sketch

/*
This sketch sends a string to a TCP server, and prints a one-line response. You must run a TCP server in your local network. For example, on Linux you can use this command: nc -v -l 3000 */

#include #include #include

#ifndef STASSID #define STASSID "ssid" #define STAPSK "password" #endif

const char* ssid = STASSID; const char* password = STAPSK;

// Set the limit of addresses you want to consider const int total_addresses = 4;

// Type all IP addresses here const IPAddress *LocalAddresses[] = { new IPAddress (192, 168, 31, 29), new IPAddress (192, 168, 31, 49), new IPAddress (192, 168, 31, 77), new IPAddress (192, 168, 31, 37), new IPAddress (192, 168, 31, 11), new IPAddress (192, 168, 31, 20), new IPAddress (192, 168, 31, 27), new IPAddress (192, 168, 31, 67)};

// set the global variables for each device! int pin_status_count[][3] = { {16, 0, 0}, {4, 0, 0}, {2, 0, 0}, {12, 0, 0}, {5, 0, 0}, {0, 0, 0}, {14, 0, 0}, {13, 0, 0} };

// set maximum light pwm light intensity const int max_pwm_light = 50; ESP8266WiFiMulti WiFiMulti;

void setup() { Serial.begin(115200);

// initialize digital pin LED_BUILTIN as an output. for (int i=0; i < 8; i++) { pinMode(pin_status_count[i][0], OUTPUT); digitalWrite(pin_status_count[i][0], HIGH); }

// We start by connecting to a WiFi network WiFi.mode(WIFI_STA); WiFiMulti.addAP(ssid, password);

Serial.println(); Serial.println(); Serial.print("Wait for WiFi... ");

while (WiFiMulti.run() != WL_CONNECTED) { Serial.print("."); delay(500); }

Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP());

delay(3000);

// turn all leds off for (int i=0; i < 8; i++) { digitalWrite(pin_status_count[i][0], LOW); } }

void loop() {

// Check all IPs for (int i=0; i < total_addresses; i++) {

pin_status_count[i][2]--;

// Decide if does ping if (pin_status_count[i][2] < 0) { // Ping Serial.print("Pinging LOCAL ip "); Serial.println(*LocalAddresses[i]); if (Ping.ping(*LocalAddresses[i])) { Serial.println("Success!!"); analogWrite(pin_status_count[i][0], max_pwm_light); pin_status_count[i][1] = 1; pin_status_count[i][2] = 10; } else { Serial.println("Error :("); if (pin_status_count[i][2] < -20) { analogWrite(pin_status_count[i][0], 0); pin_status_count[i][1] = 0; pin_status_count[i][2] = 0; } }

} } Serial.println("wait 3 sec..."); delay(3000); }

Step 3: Final Notes!

The #include libraries that the bugous instructables doesn't let me write as code are these:

  • ESP8266WiFi.h

  • ESP8266WiFiMulti.h

  • ESP8266Ping.h

To make the project more sturdy I used hot glue on the base of the LEDs and under the card board. The wire connections made on the breadboard must be well made because the hot glue may do some displacement on the wires that in case of bad wiring may result in disconnections!

Step 4: Improved Code (upgraded Sketch)!

/*
This sketch sends pings to IP addresses, and prints a one-line response. Made by Rui Seixas Monteiro */

#include #include #include

#ifndef STASSID #define STASSID "ssid" #define STAPSK "password" #endif

const char* ssid = STASSID; const char* password = STAPSK;

// Set the limit of addresses you want to consider const int total_addresses = 5;

// Type all IP addresses here const IPAddress *LocalAddresses[] = { new IPAddress (8, 8, 8, 8), new IPAddress (192, 168, 7, 243), new IPAddress (192, 168, 7, 145), new IPAddress (192, 168, 7, 172), new IPAddress (192, 168, 7, 138), new IPAddress (192, 168, 7, 11), new IPAddress (192, 168, 7, 20), new IPAddress (192, 168, 7, 27), new IPAddress (192, 168, 7, 67)};

// set the global variables for each device! // {GPIO, Status, pwm, sleep_minutes, minutes_stamp, sleep_seconds, seconds_stamp} unsigned long pin_status_count[][7] = { {15, 0, 200, 5, 120, 10, 120}, {16, 0, 100, 15, 120, 1, 120}, {4, 0, 100, 15, 120, 1, 120}, {2, 0, 100, 15, 120, 1, 120}, {12, 0, 100, 15, 120, 1, 120}, {5, 0, 100, 15, 120, 1, 120}, {0, 0, 100, 15, 120, 1, 120}, {14, 0, 100, 15, 120, 1, 120}, {13, 0, 100, 15, 120, 1, 120} }; ESP8266WiFiMulti WiFiMulti;

void setup() { Serial.begin(115200);

// turn on all leds. for (int i=0; i < 9; i++) { pinMode(pin_status_count[i][0], OUTPUT); digitalWrite(pin_status_count[i][0], HIGH); }

// stay all leds on for 3 seconds delay(3000);

// turn off all leds for (int i=0; i < 9; i++) { digitalWrite(pin_status_count[i][0], LOW); }

// We start by connecting to a WiFi network WiFi.mode(WIFI_STA); WiFiMulti.addAP(ssid, password);

Serial.println(); Serial.println(); Serial.print("Wait for WiFi... ");

while (WiFiMulti.run() != WL_CONNECTED) { Serial.print("."); delay(500); }

Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP());

delay(500); }

void loop() {

// set current time in seconds and minutes unsigned long currentSeconds = millis() / 1000; unsigned long currentMinutes = currentSeconds / 60; Serial.println(currentMinutes); // Check all IPs for (int i=0; i < total_addresses; i++) {

// Decide if does ping if (abs(currentMinutes - pin_status_count[i][4]) > pin_status_count[i][3] / 4 && abs(currentSeconds - pin_status_count[i][6]) >= pin_status_count[i][5]) { // Ping Serial.print("Pinging THIS ip "); Serial.println(*LocalAddresses[i]); if (Ping.ping(*LocalAddresses[i], 1)) { Serial.println("Success!!"); if (pin_status_count[i][1] == 0) { // Blink for 5 seconds! for (int j=0; j < 6; j++) { digitalWrite(pin_status_count[i][0], HIGH); // wait for 1/2 a second! delay(500); digitalWrite(pin_status_count[i][0], LOW); // wait for another 1/2 a second! delay(500); } } analogWrite(pin_status_count[i][0], pin_status_count[i][2]); pin_status_count[i][1] = 1; pin_status_count[i][4] = millis() / (60*1000); } else { Serial.println("Error :("); if (pin_status_count[i][1] == 1 && abs(currentMinutes - pin_status_count[i][4]) > pin_status_count[i][3] / 2) { digitalWrite(pin_status_count[i][0], HIGH); } if (abs(currentMinutes - pin_status_count[i][4]) > pin_status_count[i][3]) { digitalWrite(pin_status_count[i][0], LOW); pin_status_count[i][1] = 0; } pin_status_count[i][6] = millis() / 1000; }

} } // wait 10 milliseconds... delay(10); }

Share

    Recommendations

    • Trash to Treasure

      Trash to Treasure
    • Remix Contest

      Remix Contest
    • Paper Contest

      Paper Contest

    Discussions