Hardware Reference
In-Depth Information
e-mail project (project 4 in this chapter). Using the program you created to print the tem-
perature to the screen, replace the main routine with the code in Listing 13-3.
Listing 13-3 Temperature Alert
# This is the main routine of the program
tempind=False
while True:
temperature=GetTemperature()
if temperature > 25 and tempind==False:
#Use the SendEmail routine from the
#e-mail project
SendEmail(“The temperature is “+ ;
str(temperature))
tempind=True;
else:
#This will ensure you only receive one e-mail
#once the temperature is above 25
#This variable is set back to false when the
#temperature is less than or equal to 25
tempind=False;
#Fetch the temperature every 10 seconds
time.sleep(10)
Project 4: How to Send an E-mail Alert
he sensors play an important role in monitoring your home but are not much use without hav-
ing an action associated with them. An e-mail alert is a useful type of action as you can pack as
much information as want into the body of the e-mail and send it to a smartphone. Other useful
alerts (not detailed in this chapter) are a lashing LED, an LCD display and a buzzer or siren, which
are all easily achievable tasks with a Raspberry Pi. Another useful tool for home automation, but
also beyond the scope of this chapter, is a web page and a database. You can log sensor data to a
database and design web pages to represent that data to you so that you can monitor your home.
What You Will Need
his project is all software based and can be used in conjunction with all the other projects in the
chapter. All you will need is your Raspberry Pi, an editor and some Python code that I will provide.
Software
In order to send an e-mail from your Raspberry Pi, you need to send it from an e-mail server. You
need to know your e-mail account details. here are three pieces of information you will need:
 
Search WWH ::




Custom Search