element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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
RIoTboard
  • Products
  • Dev Tools
  • Single-Board Computers
  • RIoTboard
  • More
  • Cancel
RIoTboard
Blog Riotboard: IoT based intrusion detection & alert system: Part3 : Email alerts
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join RIoTboard to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: tusharp
  • Date Created: 29 Oct 2015 7:32 AM Date Created
  • Views 832 views
  • Likes 3 likes
  • Comments 1 comment
  • tusharp
  • alert
  • Ubuntu
  • gpio
  • pir
  • freescale
  • imx6
  • riotboard
  • embedded
  • riot
  • intrusion
  • camera
  • iot
  • logitech
  • c310
  • arm9
  • sensor
  • linux
Related
Recommended

Riotboard: IoT based intrusion detection & alert system: Part3 : Email alerts

tusharp
tusharp
29 Oct 2015

In this mini blog series we will build an IoT based intruder detection and alert system.

 

Blogs:

Part1 : Connecting Pir Sensor

Part2 : Capturing intruder image

Part3 :  Email alert  <--- this blog

 

In previous blog we integrated a camera to Riotboard for capturing images on IR detection.

 

In this mini blog we will send email (with captured image) of the intruder.

 

now add below line to previous code (below ln30)

system("python /opt/send_snapshot.py");


#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int main()
{
int ret =0;
int fd=0;
char buf[1];

system("devmem 0x20E00A0 w 0x5  ");
system("echo 113 > /sys/class/gpio/unexport");
system("echo 113 > /sys/class/gpio/export");
usleep(100000);
system("echo in > /sys/class/gpio/gpio113/direction");
usleep(100000);

fd = open("/sys/class/gpio/gpio113/value",O_RDONLY);
while(1)
{
ret = read(fd,buf,sizeof(1));
if(lseek(fd,0,SEEK_SET) < 0) return 1;

if(ret>0 && (atoi(buf)==1))
    {
        printf("\n\033[031;43m HUMAN DETECTED \033[0m ");
        fflush(stdout);
        system("fswebcam -d /dev/video2 capture.jpg");
        usleep(500000);
        system("python /opt/intrusion_detection/send_snapshot.py");
    }
else
    printf("\nNo Detection");

fflush(stdin);
fflush(stdout);
usleep(500000);

}
close(fd);
}

 

 

Now create a file "send_snapshot.py" in /opt/ directory

cd /opt/

touch send_snapshot.py

 

copy the below contents to "send_snapshot.py"

#!/usr/bin/python

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os

send_user = "YOUR_GMAIL_ID@gmail.com"        #sender_email
send_pwd = "YOUR_GMAIL_PASSWORD"             #sender_password
recv_user = "YOUR_GMAIL_ID@gmail.com"        #receiver_email
subject = "intrusion detected !!!!"

def mail(to, subject, text, attach):
   msg = MIMEMultipart()

   msg['From'] = send_user
   msg['To'] = recv_user
   msg['Subject'] = subject

   msg.attach(MIMEText(text))

   part = MIMEBase('application', 'octet-stream')
   part.set_payload(open(attach, 'rb').read())
   Encoders.encode_base64(part)
   part.add_header('Content-Disposition',
           'attachment; filename="%s"' % os.path.basename(attach))
   msg.attach(part)

   mailServer = smtplib.SMTP("smtp.gmail.com", 587)
   mailServer.ehlo()
   mailServer.starttls()
   mailServer.ehlo()
   mailServer.login(send_user, send_pwd)
   mailServer.sendmail(send_user, to, msg.as_string())
   mailServer.close()

mail(recv_user,    subject,"below is the snapshot of intruder !!!","capture.jpg")

 

this script sends snapshot to gmail,  in line 10,11 & 12 replace the defaults with your sender gmail id, sender gmail password and receiver email.

 

Now perform some hand movement infront of IR sensor, it will show human detected, captures image as "capture.jpg" and sends an email.

 

ruqy6d.jpg

 

Received email:

 

555snd.jpg

 

 

So we conclude this mini blog series on Intrusion detection and notification.

  • Sign in to reply
  • DAB
    DAB over 9 years ago

    Nice project.

     

    I may have to dig my old RIOT board out and set this one up.

     

    DAB

    • 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