Arduino Network Monitor

During the winter I decided to purchase a NAS (Network Attached Storage) so I could backup and keep all my work easily in one place between my computers. Over time I noticed that my computer would lose internet connection and connection to my server. With the amount of networking equipment I have running, I tend to have issue finding the source of the error. One afternoon, I decided to think of a quick project to work on. With an Arduino Ethernet board lying on my desk, I decided to make a small device to place on my desk to monitor any device on my local network and also check outgoing internet service.

With a few parts lying around, I began my search in finding a simple method of making this device.  I decided to use the easiest method in checking network connections, using the good old “ping” function you could find in Windows when messing around with command prompt. The problem is, Arduino is not Windows and does not come with a “ping” function. Luckily, the Arduino community is large enough to have plenty of libraries available to suit anyone’s needs! I found a library called ICMP Ping, which allows for an Arduino with Ethernet to ping web addresses.

After assembling a quick test using the library’s example, I decided to assemble this circuit into a case. While cleaning the kitchen with my mom, I found some wooden tea boxes which were empty. The boxes were small and had a little sliding piece of wood which allowed you to open the box. The box was a perfect size to put all the components in, so I used a Dremel to make some holes for the Ethernet, LCD, and power. In the end I had a cool working device!

Summary: An ethernet device that pings local and external IPs and displays if they are online or offline.

IMG_20160129_231604823[1]

Parts Used:

  • Standard LCD Screen
  • 220 Ohm Resistor
  • Arduino Ethernet Board (Now replaced by Ethernet Shield)
  • 10k OHm Potentiometer
  • Wire
  • 5 Volt Arduino Power Supply
  • Cat 5e Ethernet Cable

sketc

Arduino Code

network_monitor.ino

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <ICMPPing.h>
#include <util.h>
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
 
//Networking Stuff
byte mac[] = {  
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
EthernetClient client;
SOCKET pingSocket = 0;
char buffer [256];
ICMPPing ping(pingSocket, (uint16_t)random(0, 255));
IPAddress NAS(192,168,1,12);
IPAddress NAS2(192,168,1,11);
IPAddress Gateway(192,168,1,1);
IPAddress Google(8,8,8,8);
IPAddress Google2(8,8,4,4);
IPAddress Verizon(4,2,2,2);
IPAddress Test(192,168,1,55);
//LCD Stuff
LiquidCrystal lcd(9, 8, 6, 5, 3, 2);
 
void setup() {
  Serial.begin(9600);
 lcd.begin(16, 2);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    lcd.print("Failed to connect");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
}
 
void loop() {
  //Display Arduino's IP
   lcd.clear();
  lcd.print("IP Address:");
  lcd.setCursor(0, 1);
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
   lcd.print(Ethernet.localIP()[thisByte], DEC);
   if(thisByte <3)
    lcd.print("."); 
  }
  delay(5000);
  testNetwork();
  delay(5000);
  testIP(NAS,"NAS");
  delay(5000);
   testIP(NAS2,"NAS 2");
  delay(5000);
}
void testNetwork()
{
 
  if(checkServer(Google)){
    lcd.clear();
   lcd.setCursor(0, 0);
    lcd.print("Internet Online");
  }
  else{
    if(checkServer(Google2)){
      lcd.clear();
   lcd.setCursor(0, 0);
        lcd.print("Internet Online");
    }
    else{
      if(checkServer(Verizon)){
        lcd.clear();
   lcd.setCursor(0, 0);
        lcd.print("Internet Online");
      }
      else{
        lcd.clear();
   lcd.setCursor(0, 0);
    lcd.print("Internet Offline");
      }
    }
  }
}
 
void testIP(IPAddress a, String IPname){
 
  if(checkServer(a)){
    lcd.clear();
     lcd.setCursor(0, 0);
    lcd.print(IPname);
    lcd.print(" Online: ");
    lcd.setCursor(0, 1);
    lcd.print(a);
  }
  else{
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(IPname);
    lcd.print(" Offline: ");
    lcd.setCursor(0, 1);
    lcd.print(a);
  }
}
boolean checkServer(IPAddress a){
   ICMPEchoReply echoReply = ping(a, 4);
  if (echoReply.status == SUCCESS)
  {
    return true;
  }
  else
  {
    return false;
  }
}
This entry was posted in Electronics, Portfolio. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *