Seth
Published

BeagleBone Black Wireless Email Notifications

Have you ever wanted to know how to make sure your front door, any window in the house, or your backdoor stays shut or else?

BeginnerProtip1 hour1,185
BeagleBone Black Wireless Email Notifications

Things used in this project

Hardware components

BeagleBone Black Wireless
BeagleBoard.org BeagleBone Black Wireless
×1
Jumper wires (generic)
Jumper wires (generic)
×1
normally closed window sensor
×1

Software apps and online services

Debian
Python3
Flask

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Schematics

RE: Switches and the BBBW

This is the schematic, although mundane, it is for your viewing simplicity.

Code

The emailer.py file...

Python
Use this file alone or w/ the other script to send yourself emails or send your friends the emails. We will call the alertMe function in another Python file w/ a Flask microframework to make sure we can get real time happening.
import smtplib
from email.mime.text import MIMEText

def alertMe(subject, body):
    myAddress = "YourEmail@gmail.com"
    msg = MIMEText(body)
    msg["Subject"] = subject
    msg["From"] = "YourEmail@gmail.com"
    #msg["Reply-to"] = "YourEmail@gmail.com"
    msg["To"] = "YourEmail@gmail.com"

    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.starttls()
    server.login("YourEmail@gmail.com", "YourPassword")
    server.sendmail("YourEmail@gmail.com", "YourEmail@gmail.com", msg.as_string())
    server.quit()

alertMe("Hello!", "The front door has been opened!")

RE: DoorAlert.py

Python
This will tell you whether the switch has been completed or broken w/ a nice Flask App online at your BBBW address with the port of 5000. You can try this one separately for fun!
from flask import Flask, render_template
import Adafruit_BBIO.GPIO as GPIO
app = Flask(__name__)

GPIO.setup("P8_8", GPIO.IN)

@app.route("/")

def hello():
    if GPIO.input("P8_8"):
        doorStatus = "open"
    else:
        doorStatus = "closed"
    templateData = {
        "doorStatus": doorStatus,
    }
    return render_template("mainDoor.html", **templateData)

if __name__=="__main__":
    app.run(host="0.0.0.0", port=5000, debug=True)

RE: DoorAlert.py is our software to use w/ the emailer.py file from before.

Python
Hello...there is a lot going on in the source. At least for me, it is a bit difficult to explain. If you have any questions, do not hesitate to reply or let me know how you would go about it.
import Adafruit_BBIO.GPIO as GPIO
import time
from emailer import alertMe

GPIO.setup("P8_8", GPIO.IN)

alertTime = 0

while True:
    if GPIO.input("P8_8"):
        if alertTime == 0:
            alertTime = time.time() + 15
            print("The door has been opened! This message will alert you in 15 seconds if left open!")
        else:
            if time.time() > alertTime:
                alertMe("Alert, Alert!", "The door has been left open!")
                print("The door has been left open for 15 seconds. The email has been sent.")
                while GPIO.input("P8_8"):
                    time.sleep(0.5)

    else:
        alertTime = 0
    time.sleep(0.5)

Credits

Seth

Seth

32 projects • 12 followers
Stay there and someone will find you...

Comments