A Dummy Light for My Network

I’ve always heard the red lights in car dashboard referred to as Dummy Lights. One example might be the use of a light to indicate high temperature in lieu of a temperature gauge. Over the past few weeks, I’ve spent more time doing unique things with hardware and software. Yesterday I challenged myself to build an indicator light to show health issues with my Meraki MX.

Before I get into this, the cool factor here is not what I have built. The cool factor is that someone with very little experience, driven by curiosity, can build this in a very short period of time. I’m neither a professional developer nor someone with deep knowledge around hardware hacking. So I want to solicit thoughts, feedback, and recommendations.

The Trigger

After a little research, I found that the Meraki Dashboard provides a “Load Monitor” that is returned via a perfScore value. This feature is in beta and there’s not a lot of information on it. Therefore, consider your own data source that you would like to use as a trigger value. The following python code will store a numeric value (score) between 1 and 100 (with a lower number being a better score).

import requests
import json
import time
import datetime

mydashkey="****API Dashboard Key****"
mydevice="****Dashboard Device ID****"
mynetwork="L_xxxxxxxx"
logfile="/home/pi/mxhealth.log"
myhealth=18

url = "https://dashboard.meraki.com/api/v0/networks/" + mynetwork + "/devices/" + mydevice + "/performance"

headers = {
    'x-cisco-meraki-api-key': mydashkey,
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

jsondata = response.json()
score = jsondata['perfScore']

The Wiring

Since we know how to get a value for comparison, the next step is wiring up a Raspberry Pi. In my case, I used pins 6, 11 and 12 on my Pi (Pi 2 Model B) and wired two LEDs.

LEDWiring

I leveraged a 1K Ohm resistor, but many choose a 330 Ohm. The right section of this breadboard is my actual wiring. Its hard to see the resistor but I connected both LED cathodes to a common column and inserted the resistance between that column and the ground.

PIWiring

To get a current state and understanding of the GPIO pinout, the gpio command comes in quite handy.

[email protected] ~ $ gpio readall
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |  OUT | 0 | 11 || 12 | 1 | OUT  | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
[email protected] ~ $

We can also use the GPIO command to test our wiring. In my case, I have the wPi 0 and wPi 1 wired to RED and GREEN LEDs (respectively). The following is my testing process for the physical connections.

//testing the connection to the RED LED
//set the mode as output
[email protected] ~ $ gpio mode 0 out
//turn the RED led on
[email protected] ~ $ gpio write 0 1
//turn the RED led off
[email protected] ~ $ gpio write 0 0

//testing the connection to the GREEN LED
//set the mode as output
[email protected] ~ $ gpio mode 1 out
//turn the GREEN led on
[email protected] ~ $ gpio write 1 1
//turn the GREEN led on
[email protected] ~ $ gpio write 1 0

Bringing it Together

Assuming everything is working as expected, we should be able to complete our task by combining the trigger with some Python code to control the LEDs. Here is my completed Python code.

import requests
import json
import RPi.GPIO as GPIO
import time
import datetime

mydashkey="****API Dashboard Key****"
mydevice="****Dashboard Device ID****"
mynetwork="L_xxxxxxxx"
logfile="/home/pi/mxhealth.log"
myhealth=18

url = "https://dashboard.meraki.com/api/v0/networks/" + mynetwork + "/devices/" + mydevice + "/performance"

headers = {
    'x-cisco-meraki-api-key': mydashkey,
    'content-type': "application/json",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, headers=headers)

jsondata = response.json()
score = jsondata['perfScore']

currtime = datetime.datetime.now()

with open(logfile, "a") as myfile:
    myfile.write("Dashboard Score is " + str(score) + " at " + str(currtime) + "\n")

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.OUT)
GPIO.setup(18,GPIO.OUT)

if score < myhealth:
    print "LED should be  Green"
    GPIO.output(17, GPIO.LOW)
    GPIO.output(18, GPIO.HIGH)
else:
    print "LED should be  Red"
    GPIO.output(18, GPIO.LOW)
    GPIO.output(17, GPIO.HIGH)

I could have used a loop to keep this program executing. However, I opted to make it a simple script that could be scheduled with CRON. I also included code to log the perfScore with each pass.

Conclusion

As I stated earlier, I don’t know how useful providing a GREEN or RED light is for my home Internet usage. However, I find it very cool that I can easily hack something together that interacts provides a physical status indicator of a condition that is represented in the Meraki Dashboard.

Disclaimer: This article includes the independent thoughts, opinions, commentary or technical detail of Paul Stewart. This may or may does not reflect the position of past, present or future employers.

About Paul Stewart, CCIE 26009 (Security)

Paul is a Network and Security Engineer, Trainer and Blogger who enjoys understanding how things really work. With over 15 years of experience in the technology industry, Paul has helped many organizations build, maintain and secure their networks and systems.
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to A Dummy Light for My Network

  1. Andreas says:

    Hi Paul, at our Zabbix monitoring we use several Raspberrys with LED traffic lights, which are controlled and supplied with power via USB. No tinkering with the leds, 3 colors and just as easy to program as the gpio ports;)

Leave a Reply