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.

6 comments

Skip to comment form

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

    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
      • Reply

      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
    • Reply

    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
      • Reply

      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
    • Reply

    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
      • Reply

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

      Earl

Leave a Reply

Your email address will not be published.