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.


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

Piiot B.jpg

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

piot circuit B.JPG

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



(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.





//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                ""

#define    EMAIL_TX_INPUT_2_RECIPIENT                ""

#define    EMAIL_TX_INPUT_3_RECIPIENT                ""

#define    EMAIL_TX_INPUT_4_RECIPIENT                ""

#define    EMAIL_TX_INPUT_5_RECIPIENT                ""

#define    EMAIL_TX_INPUT_6_RECIPIENT                ""


#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



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.



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.