element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog Set up Email Alerts with the Raspberry Pi
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Catwell
  • Date Created: 19 Nov 2014 6:58 AM Date Created
  • Views 4554 views
  • Likes 4 likes
  • Comments 8 comments
  • rpiintermediate
  • controller
  • hmi
  • complete
  • internet_of_things
  • raspberry_pi
  • cabeatwell
  • rpi
  • iot
  • raspberry_pi_projects
Related
Recommended

Set up Email Alerts with the Raspberry Pi

Catwell
Catwell
19 Nov 2014

The Internet of Things (IoT) is an expected feature for any new product coming out. But, I’ve noticed that the IoT systems out there are all quite specific. Health monitoring, home control, kitchen appliance… each focusing on their little worlds. But, what if you want to monitor when a mouse trap snaps, the mailbox opens, or someone moved your lunch in the fridge at work? That is where my general purpose IoT system comes into play. Which I will call the PiioT (Pi + IoT) for the remainder of this post. (I do dislike tongue-in-cheek names though… but moving on. ) So, dust off that old Raspberry Pi Model B.

 

I made it simple… it looks for a logic signal trip, like a switch. When it receives the signal, it sends out an email. Maybe one day you hid a switch underneath your beverage in the fridge, the next day you are monitoring your file cabinet.

 

Of course, a circuit could be built to do any one function. Then it can be set to then send a logic signal to the PIoT. An example, a temperature sensor circuit is off monitoring a fish tank, let’s say, when a certain temp it reached, a logic signal is sent to the central server, the PiioT. All IoT related tasks are shuffled off to the Raspberry Pi, in other words.

 

I placed in one output pin as well. So, you can send an email to the system and it will set a pin high/low. This way you can daisy chain off of that with lights, a relay, a series of relays. Turning on a relay is the easiest way to turn on an AC powered device like lights, radio, sprinkler system, holiday decorations, coffee maker, etc.


You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Here were my requirements

- Use a Pi

- Several input pins. I used 6, but it could be set it up to use many more.

- Have an output pin

- Emails received and triggered by email.

 

Project by sections

Again, I made it simple. All you need is one Raspberry Pi.

- I used pins 19, 21, 22, 23, 24, 26 for inputs for switches or sensors.

I set the output on pin 7.


- The email address has to be configured for use. I made a gmail account for this project. I am only using it for the output pin, where I send it a command to turn on. Unfortunately, a recompile will be needed to set your own email.

 

- The system checks the email address set up for the output trigger. If there is a new one, it will trigger the output and then delete the email.


The difficulties

- Dealing with various ISPs was the biggest issue. Dynamic IPs didn’t quite work out. I had to use a static IP with an ISP that can handle ETRN. Which means Extended Turn, and extension of the SMTP mail delivery protocol. This allows one SMTP server to request from another SMTP server.


- Using one’s own email server system might be a better idea than with gmail.

 

Pics and system



image

Nothing in this picture is really necessary... just one Pi is all you need. I am just showing the system igniting a LED on the lower right after receiving an email trigger.


Schematic and Design

image

Sticking with the general purpose angle of the project, I drafted this with generic inputs and outputs. Replace as seen fit...

 

Code

(Full code attached to this page)

//###########################

//##### OPERATION NOTES #####

//###########################

//

//

//----- PROGRAM SETTINGS -----

//    /settings.h has all of the programs settings in it.  To edit it from the command line:

//    Edit the file:

//        nano /home/pi/settings.h

//    Make the changes required then press CTRL+X to exit, pressing Y to confirm the save.

//    Build the application:

//        cd /home/pi/whatevername

//        make

//    Reboot the RPi to run the application again, or use this to run it from the command line:

//        sudo ./whatevername.a      (CTRL+C to forcibly close it again if needed after running in this way)

//

//

//----- SENDING EMAIL -----

//To change the mailbox email is received from edit this file:

//    nano /etc/ssmtp/ssmtp.conf

 

//Including these strings anywhere in an email (subject or body) sent to the RPi will cause the associated action

//STRINGS MUST BE LOWERCASE HERE but are not case sensitive when sending.

const char EMAIL_RX_SET_OUTPUT_HIGH_STRING[] =    {"set output high"};        //Sets the output high and enables monitoring of the input pins

const char EMAIL_RX_SET_OUTPUT_LOW_STRING[] =    {"set output low"};            //Sets the output low and enables monitoring of the input pins

 

//-------------------------------

//--------- Output pin ----------

//-------------------------------

#define OUR_OUTPUT_PIN(state)                    bcm2835_gpio_write(RPI_V2_GPIO_P1_07, state)        //If changing this ensure the initialise() port setup is also changed in ap-main.cpp

const int output_pin_default_state =            1;            //0 = low, inputs not being monitored.  1 = high, inputs are being monitored.

 

//-------------------------------

//----- SEND EMAIL SETTINGS -----

//-------------------------------

//Note - these need to be C constant strings. You cannot include a quotation mark within these strings - use an html code instead.

 

#define    EMAIL_TX_INPUT_1_RECIPIENT                "fake@email.com"

#define    EMAIL_TX_INPUT_2_RECIPIENT                "fake@email.com"

#define    EMAIL_TX_INPUT_3_RECIPIENT                "fake@email.com"

#define    EMAIL_TX_INPUT_4_RECIPIENT                "fake@email.com"

#define    EMAIL_TX_INPUT_5_RECIPIENT                "fake@email.com"

#define    EMAIL_TX_INPUT_6_RECIPIENT                "fake@email.com"

 

#define    EMAIL_TX_INPUT_1_SUBJECT                "Email Alert for input 1"

#define    EMAIL_TX_INPUT_1_BODY                    "Input 1 was triggered"

 

#define    EMAIL_TX_INPUT_2_SUBJECT                "Email Alert for input 2"

#define    EMAIL_TX_INPUT_2_BODY                    "Input 2 was triggered"

 

#define    EMAIL_TX_INPUT_3_SUBJECT                "Email Alert for input 3"

#define    EMAIL_TX_INPUT_3_BODY                    "Input 3 was triggered"

 

#define    EMAIL_TX_INPUT_4_SUBJECT                "Email Alert for input 4"

#define    EMAIL_TX_INPUT_4_BODY                    "Input 4 was triggered"

 

#define    EMAIL_TX_INPUT_5_SUBJECT                "Email Alert for input 5"

#define    EMAIL_TX_INPUT_5_BODY                    "Input 5 was triggered"

 

#define    EMAIL_TX_INPUT_6_SUBJECT                "Email Alert for input 6"

#define    EMAIL_TX_INPUT_6_BODY                    "Input 6 was triggered"

 

//Input pins

//Pull any pin low to trigger the associated email being sent

#define SWITCH_1_INPUT                            bcm2835_gpio_lev(RPI_V2_GPIO_P1_19)        //If changing this ensure the initialise() port setup is also changed in ap-main.cpp

#define SWITCH_2_INPUT                            bcm2835_gpio_lev(RPI_V2_GPIO_P1_21)        //If changing this ensure the initialise() port setup is also changed in ap-main.cpp

#define SWITCH_3_INPUT                            bcm2835_gpio_lev(RPI_V2_GPIO_P1_22)        //If changing this ensure the initialise() port setup is also changed in ap-main.cpp

#define SWITCH_4_INPUT                            bcm2835_gpio_lev(RPI_V2_GPIO_P1_23)        //If changing this ensure the initialise() port setup is also changed in ap-main.cpp

#define SWITCH_5_INPUT                            bcm2835_gpio_lev(RPI_V2_GPIO_P1_24)        //If changing this ensure the initialise() port setup is also changed in ap-main.cpp

#define SWITCH_6_INPUT                            bcm2835_gpio_lev(RPI_V2_GPIO_P1_26)        //If changing this ensure the initialise() port setup is also changed in ap-main.cpp

 

BOM

Just one Raspberry Pi B. Just $35 for a IoT controller is a decent price. This will work with every Pi version, even the A+.

What is connected to the inputs/output is up to the user.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Other uses of the system

- Imagination is the limit

 

Oddities and observations

- A Dynamic IP internet connection did not work. A static IP was the only way I could connect to the gmail server.

- The model B+ & A+ seem to have a different networking parameters.. so stick with the old model B or A for the time being.

Attachments:
PiioT emailalert.zip
  • Sign in to reply

Top Comments

  • cstanton
    cstanton over 10 years ago +1
    So what's to stop me spamming the crap out of this once I know its e-mail address? Even if its expecting e-mails from a specific address, those can be spoofed.
  • fvan
    fvan over 10 years ago in reply to mcb1 +1
    Alerts for Android and iOS are available. There is also an example from openHAB where it demonstrates sending an email in case it is unable to send the notification. Like so: rule "Notify Fire Alarm" when…
  • Former Member
    Former Member over 9 years ago in reply to Catwell

    Catwell,

     

    Thank you for your reaction.

     

    I can’t wait............. 

     

     

    Jaap

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Catwell
    Catwell over 9 years ago in reply to Former Member

    Jaap,

     

    I'll see what I can do.

     

    C

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago

    Hello Cabe,

     

    Can you please send me a comlete (SD) image from this project by wetransfer?

    My email adres is jaapvdberg@yahoo.com

     

    Kind regearts Jaap

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fvan
    fvan over 10 years ago in reply to mcb1

    Alerts for Android and iOS are available. There is also an example from openHAB where it demonstrates sending an email in case it is unable to send the notification.

     

    Like so:

     

    rule "Notify Fire Alarm"
    when
    Item Fire_Alarm changed
    then
    if (!pushNotification("Title", "Fire Alarm changed to ("+ BMA_Alarm.state.toString +")!!"), 2) {
    sendMail("y...@email.com", "Fire", "Fire alarm changed to ("+ BMA_Alarm.state.toString +")!!")
    }
    end

    (from: https://groups.google.com/forum/#!msg/openhab/Sud17n2us1w/NObcZVv1GrIJ)

     

    Frederick

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 10 years ago in reply to cstanton

    Christopher

    Do you recall if OpenHAB in the Forget Me Not had email options.

    I don't recall anyone used it, but I recall someone was sending alerts to his phone.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube