IP Monitor, simple, elegant, convenient - A maker kit project

Another maker kit project by a complete newbie… :slight_smile:

This small and simplistic device was born when a client approached with a simple, yet annoying problem, that needed solving. Visitors use network cables in boardrooms to connect to the Network and leave the phones unplugged without anyone knowing.

Scope:
The device, when connected to the WiFi, will ping all their IP phones on the network. Data will be published to a Ubidots Dashboard for easy viewing.

Prerequisites:

  • Basic C/C++ knowledge
  • Basic knowledge of Fusion360
  • Ubidots account
  • Particle account

Disclaimer
Please take care when using high voltage AC. I purposefully did not include my actual PCB design as legislation in different countries may vary.

Step 1 - Enclosure design:

Designed a simple and safe enclosure to accommodate the custom PCB using Autodesk Fusion360. If you are more familiar with Autodesk Fusion360, I can highly recommend the following set go instructional videos by Lars Christensen. You will be designing simply enclosures in no time!

Step 2 - Custom PCB (Autodesk Eagle)

I managed to repurpose a previous PCB design due to the simplistic nature of this device. The PCB accommodate an AC/DC converter, Particle Photon, some resistors and capacitors, and finally some 5050 RGB LED acting as Status LED’s mirroring the Particle onboard LED. I suppose the device can be smaller (70mm x 50mm currently) but I had some PCB’s left over from another project, so I thought why not. I removed the components I was not going to use from the render.

Thanks to the RECOM RAC05 AD/DC converter, the design allows for the use of either high voltage (110V - 240V) to power the device OR 3.3V - 5V external power supply by simply setting the onboard jumper accordingly.

Step 3 - Code
The principal is simple - ping a list of hard-coded IP’s and match a name to each IP. If a response is received, “1” is published to Ubidots. If no reply is received in 5 pings, “0” is published. I used Webhooks to send data via Device Cloud to Ubidots.

Find my code below:

// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>

//  Project:        IP Monitor 
//                  A project by FireFli (PTY) LTD

//  Date:           October 2019
//  Compiled by:    Henk Goosen - Kragtig.com
//                  Friedl Basson - FireFli (PTY) LTD
//                                      
//  Details:        Checking hard coded IP's for conection.
//                  Post result to Ubodots dashboard

//  Product:        Ladybug
//  Firmware:       V1.0.1



class IPAndName {

public:
    IPAddress address;
    std::string name;
    IPAndName(int a, int b, int c, int d, std::string n);
};

IPAndName::IPAndName(int a, int b, int c, int d, std::string n) : address(a, b, c, d) {
    name = n;
}

IPAndName addresses[] = {               //  IP Address list
    IPAndName(192, 168, 1, 1, "Router"),
    IPAndName(192, 168, 1, 9, "Extender"),
    IPAndName(192, 168, 1, 6, "iPhone"),
    IPAndName(192, 168, 1, 9, "Macbook"),
    IPAndName(192, 168, 1, 10, "iOS"),
    IPAndName(192, 168, 1, 15, "Brother"),
    IPAndName(192, 168, 1, 21, "AppleTV"),
    IPAndName(192, 168, 1, 180, "IP_Phone")
    
};

int number_of_addresses = 8;            //  Specify number of allowed IP's. Should match list.

int numberOfReceivedPackage;
unsigned long lastTime = 0;                      

int status;                             //  Define string

// Establish Ubidots Webhook
const char* WEBHOOK_NAME = "Ubidots";       
Ubidots ubidots("webhook", UBI_PARTICLE);
    
int redPin = D3;                        //  Define RGB pins
int greenPin = D2;    
int bluePin = D1;


void setup() {
        
    pinMode(redPin, OUTPUT);            //  Set RGB pins as output pins
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);   
    
    RGB.mirrorTo(D3, D2, D1);           //  Mirror onboard LED
    
}

void loop() {
    
    unsigned long current = millis();

    if (current-lastTime>120000) {                // Every 60 seconds monitor &  publish
        lastTime = current;


    for (int i=0; i<number_of_addresses; i++) {
        numberOfReceivedPackage = WiFi.ping(addresses[i].address);

         if (numberOfReceivedPackage > 0) {
             status = 1;                        // Represents ON in Ubidots Dashboard
         } else {
             status = 0;                        // Represents OFF in Ubidots Dashboard
         }
    delay(1250);

//--Ubidots Webhooks -- Multiple Variable //
    ubidots.add((char*)addresses[i].name.c_str(), status);                  // Create variable in Ubidoits and publish value
 
    bool bufferSent = false;
    bufferSent = ubidots.send(WEBHOOK_NAME, PUBLIC);                        // Use Particle webhooks to send data    
 
// Test Code -- Uncomment if you want to publish as a single Variable with value and context//
    // ubidots.addContext("Device", (char*)addresses[i].name.c_str());  //str  //tagValue

    // char* context = (char *) malloc(sizeof(char) * 60);

    // /* Builds the context with the array above to send to Ubidots */
    // ubidots.getContext(context);
    // ubidots.add("Device", status, context);  // Change for your variable name  
    
    // bool bufferSent = false;
    // bufferSent = ubidots.send(WEBHOOK_NAME, PUBLIC);  // Will use particle webhooks to send data
// Test Code -- END  // 
   
    }
  }
}

Step 4 - Ubidots Dashboard

Below is an example of a dashboard that can be done in Ubidots in just a couple of minutes without any programming knowledge. The dashboard example shows the 8 devices (IP’s) that are constantly being monitored for connectivity. It also indicates the actual device status. With a little more effort, the individual IP’s can also be rendered a different color when the main device is powered off, by setting up a couple more events and variables in Ubidots.

Further to displaying the information on the dashboard, notifications can also be set up to alert dedicated email addresses or send text to phone numbers in the event of phones being disconnected for prolonged periods of time.

WRAPPING THNGS UP

Learning curve:
With each project there seems to be something to learn. As I am a complete newbie, I am sure there will be many more lessons :laughing:

In this case - When working with both AC and DC on the same project, do not mistake EARTH (green&yellow wire on AC) for GROUND on DC. The neutral wire (blue wire) from AC should be connected to the GROUND (negative) pin on the DC side :see_no_evil:

Be careful and make sure to adhere to best practices when designing a PCB for High Current. Altium offer some great articles

A simple idea solving an everyday problem! Another Particle maker kit project!

GIVING THANKS!!

Thanks @Joe for the great Maker Kits and to @mariahernandez
for you patience and support from the entire team at Ubidots.

8 Likes