Monitor a Network Equipment Room
Raspberry Pi
Preliminary Discussion
A common function of network management is to monitor the environment in the network equipment rooms. Things to watch are temperature, humidity, smoke, entry into the room, and so on. This can be done by purchasing devices that incorporate various sensors and notification methods. In this lab we will see how these devices do what they do as well as learn how to create a set of such devices to form a complete monitoring system, not just one sensor at a time.
Setup
The following parts are needed for this lab:
Raspberry Pi Board
GrovePi
Raspberry Pi Case
Raspberry Pi Power Supply
Magnetic Switch
Temperature and Humidity Sensor
Smoke Sensor
Water Sensor
LED
Buzzer
An Internet Connection
This program is required:
Any method that allows interaction with the Raspberry Pi will work. In this example the following is used:
TeraTerm or some other terminal program attached to the same network as the Raspberry Pi in order to access the operating system’s command line.
Assemble the Parts
To attach the sensors and output devices to the Raspberry Pi board the Grove System by Seeed Systems was used along with the GrovePi board from Dexter Industries in order to reduce and protect the connections required. Since this class is for network managers, not electronics technicians, the easier it is to connect everything together, the better.
The active components used for this lab perform the following functions:
The Raspberry Pi board reads the input from the sensors and acts on that data to send outputs defining actions to take.
The GrovePi board connects the devices to the Raspberry Pi using a common set of sensors and connectors.
The sensors detect state changes and produce attention getting outputs.
The individual parts used look like this:
Raspberry Pi
GrovePi
GrovePi Attached to Raspberry {i
Raspberry Pi Power Cable
Grove System Magnetic Switch
Grove System Temperature Humidity Pro Sensor
Grove System MQ-2 Smoke Sensor
Grove System Water Sensor
Grove System LED
Grove System Buzzer
And no I don’t know why that label is on all of the buzzers. I did not wash it, just removed the label.
The finished system looks like this:
The devices connect to the GrovePi this way:
Smoke sensor to GrovePi A0
Water sensor to GrovePi D2
Magnetic switch to GrovePi D3
Temperature and Humidity sensor to GrovePi D4
Buzzer to GrovePi D2
LED to GrovePi D8
Let’s apply power to the system by plugging the USB cable into the port on the Raspberry Pi and the other end to apower outlet.
Load the Code
So that the parts can talk to each other and to us, we need to load and run a Python script. The font has been reduced in size to prevent line wrapping.
import time
importgrovepi
gas_sensor=0
water_sensor=2
magnetic_switch=3
temp_humid=4
led=7
buzzer=8
grovepi.pinMode(gas_sensor,"INPUT")
grovepi.pinMode(water_sensor,"INPUT")
grovepi.pinMode(magnetic_switch,"INPUT")
grovepi.pinMode(led,"OUTPUT")
grovepi.pinMode(buzzer,"OUTPUT")
grovepi.digitalWrite(led,0)
grovepi.digitalWrite(buzzer,0)
while True:
smoke = grovepi.analogRead(gas_sensor)
density = (float)(smoke / 1024)
if smoke > 170:
grovepi.digitalWrite(led,1)
grovepi.digitalWrite(buzzer,1)
print ("There is Smoke in the Network Equipment Room")
print ("ALARM ALARM ALARM")
fromemail.MIMEMultipart import MIMEMultipart
fromemail.MIMEText import MIMEText
fromaddr = ""
toaddr = ""
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "ALARM ALARMALARM Smoke in the Network Equipment Room"
body = "There is smoke in the Network Equipment Room"
msg.attach(MIMEText(body, 'plain'))
importsmtplib
server = smtplib.SMTP('smtp.chipps.com', 2525)
server.ehlo()
server.starttls()
server.ehlo()
server.login("", "!mail4706")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
time.sleep(2)
else:
print ("No Smoke Has Been Detected in the Network Equipment Room")
time.sleep(2)
h = grovepi.digitalRead(water_sensor)
if h > 0:
print("The Network Equipment Room is Dry")
time.sleep(2)
else:
print("Water is in the Network Equipment Room")
grovepi.digitalWrite(led,1)
grovepi.digitalWrite(buzzer,1)
print ("ALARM ALARM ALARM")
fromemail.MIMEMultipart import MIMEMultipart
fromemail.MIMEText import MIMEText
fromaddr = ""
toaddr = ""
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "ALARM ALARMALARM Water in the Network Equipment Room"
body = "There is water in the Network Equipment Room"
msg.attach(MIMEText(body, 'plain'))
importsmtplib
server = smtplib.SMTP('smtp.chipps.com', 2525)
server.ehlo()
server.starttls()
server.ehlo()
server.login("", "!mail4706")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
time.sleep(2)
grovepi.digitalWrite(buzzer,0)
time.sleep(2)
switchState = grovepi.digitalRead(magnetic_switch)
if(switchState == 0):
print "The Door to the Network Equipment Room is Open"
grovepi.digitalWrite(led,1)
grovepi.digitalWrite(buzzer,1)
print ("ALARM ALARM ALARM")
fromemail.MIMEMultipart import MIMEMultipart
fromemail.MIMEText import MIMEText
fromaddr = ""
toaddr = ""
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "ALARM ALARMALARM The Door to the Network Equipment Room is Open"
body = "The door to the Network Equipment Room has been opened"
msg.attach(MIMEText(body, 'plain'))
importsmtplib
server = smtplib.SMTP('smtp.chipps.com', 2525)
server.ehlo()
server.starttls()
server.ehlo()
server.login("", "!mail4706")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
time.sleep(2)
grovepi.digitalWrite(buzzer,0)
time.sleep(2)
else:
print "The Door to the Network Equipment Room is Closed"
grovepi.digitalWrite(led,0)
time.sleep(2)
[temp,humidity] = grovepi.dht(temp_humid,1)
temp = temp * 9/5 + 32
print "The Temperature in the Network Equipment Room is", temp, " The Humidity Level in the Network Equipment Room is", humidity
if temp > 95:
grovepi.digitalWrite(led,1)
grovepi.digitalWrite(buzzer,1)
print ("ALARM ALARM ALARM")
fromemail.MIMEMultipart import MIMEMultipart
fromemail.MIMEText import MIMEText
fromaddr = ""
toaddr = ""
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "ALARM ALARMALARM Temperature Humidity in the Network Equipment Room is Too High"
body = "The temperature humidity in the Network Equipment Room is too high"
msg.attach(MIMEText(body, 'plain'))
importsmtplib
server = smtplib.SMTP('smtp.chipps.com', 2525)
server.ehlo()
server.starttls()
server.ehlo()
server.login("", "!mail4706")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
time.sleep(2)
grovepi.digitalWrite(buzzer,0)
time.sleep(2)
else:
time.sleep(2)
grovepi.digitalWrite(led,0)
grovepi.digitalWrite(buzzer,0)
Watch the Result
When there are no error conditions sensed by the sensors the following is displayed on the terminal screen over and over:
When a problem is detected by one of the sensors, the LED is lit, the buzzer sounds, an alarm message is displayed on the terminal screen, and an email message is sent. This message could also, and more commonly would be, a text message to a cellphone. Email is used here due to the complexity and expense of using SMS.
Let’s test one of these and look at the change in the output.
Let’s zoom in on the alarm indication.
Here is the email message that was sent:
And a close-up
Source
The basic procedure used here is a combination of the individual sensor labs and some study of the Python scripting language.
1
Copyright 2014 Kenneth M. Chipps Ph.D.