Arduino as a Network Monitor

I have set up an Arduino as a Network monitor so I can be silently alerted if a WEB server on the LAN/Internet goes down. In a previous post, here, I show the relay circuit I am using in this sketch to flash a CFL lamp. This sketch also uses the same ENC28J60 module to connect to the LAN/Internet.

Arduino Leonardo and SPI Communications using the ENC28J60 ethernet moduleThe uniqueness of this code is that it uses PING against multiple servers. I tried and tried to get this function using the UIPEthernet library working without success. I finally switched to the EtherCard library and found the solution for PINGing multiple servers. The EtherCard library also solves the problem of the CS Pin on the Arduino Leonardo that I document here. (The EtherCard library allows the code to select which pin will be used for the CS pin.)

There are several interesting things to note about this sketch:

  1. It uses PROGMEM so the IP Addresses are preserved thru each PING loop
  2. The IP address for the ENC28J60 module is dynamically set (the comments show how to switch to a static IP)
  3. MAXCYCLES can be set to re-ping and not alert in case your LAN is not perfect (the device you are pinging might miss a few)
  4. Since this is wired as a temporary setup, I blink the light when the sketch first starts to make sure the wiring is correct
  5. An LCD is used to display the IP address and millisecond PING times (this same info is also displayed to the serial port)

Here is the sketch:

To use it in your environment, change the IP addresses to PING (and number of them) to suit your LAN. Also see the comments to use a static versus dynamic IP address for the monitor itself.

14 comments

Skip to comment form

    • Abu on May 27, 2016 at 10:18 am

    Hi
    I try your code but no any respond in the serial it shows DHCP fails
    But am using the Ethernet shield with mage2560. If I used example file it works and I need to monitor 8 server boxs via SMS text.
    any Help from you thank you very much indeed.

      • earl on May 27, 2016 at 10:28 am
        Author

      Hi,
      IF you have a DHCP server, check its log to see why the server is not giving it an address. IF you don’t have a DHCP server then take a look at the comments to have the sketch use a static IP address.
      Earl

    • Darko Svilkovic on July 8, 2018 at 4:18 am

    Could you send/upload the complete connecting diagram …

    i’m using an ethernet card,and have no output on LCD display …

    thx

      • earl on July 9, 2018 at 4:58 am
        Author

      Here is how to connect the LCD (this is an UNO but the pin connections I use on the Leonardo are the same)
      https://microcontrollerelectronics.com/wp-content/uploads/2017/01/LCD.png

      Also, you don’t really need the LCD, look at the serial monitor, you should see the output there too.

    • Shane on December 10, 2018 at 6:24 pm

    Dear Earl,
    I am really new to Arduino but I have some knowledge in basic electronics and pc hardware. I am trying to build a system that displays LAN server status as in if server is up green LED or if not display an LED lit in different color ( preferably red )or maybe if thats too complicated, just a non illuminated LED for a server that is down. This display is for 8 servers on a labelled diagram of a railway track. Thanks in advance.

    Shane.

      • earl on December 11, 2018 at 4:40 am
        Author

      Hi Shane, You should be able to use the code here to start from. Arduino coding is a fun adventure!

      Earl

        • Kanchan on July 27, 2019 at 7:07 am

        HELLO EARL
        Actually also i want little bit same thing but it not happening. I want to ping only one server. If we got positive reply then one pin of arduino will go on HIgh State. But if we dont get reply from that server. The pin will be on low state.
        And after using this code i am unable to get any results of ping in serial window. Please guide me regarding this matter.

          • earl on July 29, 2019 at 4:45 am
            Author

          Hi!

          Are you sure that your wiring is correct and did you change the IP addresses to match your network?

          Earl

    • Fikri on May 6, 2020 at 4:11 pm

    Hello, can i replace the ip address shown at LCD with the name of my own server ?

      • earl on May 7, 2020 at 12:30 pm
        Author

      Yes. Check the comments in the code. It shows where to change IP addresses.

        • Fikri on May 7, 2020 at 3:25 pm

        Not the ip address, i mean like 192.168.1.1 = NASserver.
        I want LCD shown NASserver not the ip

          • earl on May 11, 2020 at 8:06 am
            Author

          You could also see if the UIPethernet library does DNS lookup but if your IPs are local you might not have a local DNS server.

          So, probably the easiest way to do what you want is to maintain a table of IP addresses to server names. Check which IP is being pinged and then display its name instead.

    • Paul D. on June 22, 2020 at 6:42 am

    Hi Earl!

    You did great job, thank you!
    But i got a question. Your program stops after one of IPs is not pinging (i guess it’s about while(1) operand). How do i change your code to continue pinging rest of IPs after one is down?
    Thanks in advance!

      • earl on June 22, 2020 at 8:05 am
        Author

      Hi Paul!

      You can change line 130 from:

      if (cycles >= MAXCYCLES) while (1) blink();

      to this:

      if (cycles >= MAXCYCLES) polling = 0;

      and that should continue to ping the rest.

      Earl

Leave a Reply

Your email address will not be published.