first commit
This commit is contained in:
commit
a5a0434432
1126 changed files with 439481 additions and 0 deletions
30
Projects/Catch_A_Lunch_Thief/README.md
Normal file
30
Projects/Catch_A_Lunch_Thief/README.md
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
## **Catch a Lunch Thief**
|
||||
|
||||
Have you ever had your lunch stolen? This project will help you find the culprit! Using the GrovePi, a Raspberry Pi, and a Raspberry Pi camera this project will e-mail you when your lunch is moved, taking a picture of the offender and helping you nab the lunch thief.
|
||||
|
||||
See more at the [GrovePi Site](http://dexterindustries.com/GrovePi/)
|
||||
|
||||
## License
|
||||
.
|
||||
The MIT License (MIT)
|
||||
|
||||
GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi.
|
||||
Copyright (C) 2017 Dexter Industries
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
58
Projects/Catch_A_Lunch_Thief/catch_a_lunch_thief.py
Normal file
58
Projects/Catch_A_Lunch_Thief/catch_a_lunch_thief.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#! /usr/local/bin/python
|
||||
# This project by Dexter Industries will help you figure out who's stealing your lunch! In
|
||||
# this project, we will use the GrovePi to take a picture of the culprit when the light in
|
||||
# your fridge turns on. We will use the light detector for Grove to detect when the fridge
|
||||
# door has been opened.
|
||||
#
|
||||
# Hardware Setup:
|
||||
# - Use the Raspberry Pi and GrovePi. (http://www.dexterindustries.com/shop/grovepi-starter-kit-2/)
|
||||
# - Use the Raspberry Pi camera. (http://www.dexterindustries.com/shop/raspberry-pi-camera/)
|
||||
# - Connect the light sensor to A0. (http://www.dexterindustries.com/shop/grove-light-sensor/)
|
||||
# You can adjust the threshold value if you have a bright environment.
|
||||
# Change the email_destination to change the destination you send an e-mail to.
|
||||
|
||||
import time
|
||||
import datetime
|
||||
import grovepi
|
||||
import picamera
|
||||
import send_email_pic
|
||||
|
||||
email_destination = 'examples@dexterindustries.com' # Change this to the destination e-mail.
|
||||
destination = [email_destination] # We put it into an array.
|
||||
|
||||
# Connect the Grove Light Sensor to analog port A0
|
||||
# SIG,NC,VCC,GND
|
||||
light_sensor = 0 # Connect the light sensor to A0 Port.
|
||||
grovepi.pinMode(light_sensor,"INPUT") # Set the A0 port to input.
|
||||
|
||||
# Send a picture once sensor exceeds threshold resistance
|
||||
threshold = 600 # Adjust this threshold higher or lower
|
||||
# Depending on how bright your fridge is.
|
||||
|
||||
camera = picamera.PiCamera() # Setup the Pi Camera
|
||||
|
||||
# Simple function to get the date as a string.
|
||||
def get_time_string():
|
||||
dateString = '%Y-%m-%d_%H-%M-%S'
|
||||
return_string = datetime.datetime.now().strftime(dateString)
|
||||
return return_string
|
||||
|
||||
while True:
|
||||
try:
|
||||
# Get sensor value. Read the light sensor.
|
||||
sensor_value = grovepi.analogRead(light_sensor)
|
||||
|
||||
# Sense the light coming on, within the target range
|
||||
if sensor_value > threshold:
|
||||
print ('The fridget light is on!') # Print a note to let us know how it goes.
|
||||
file_name = "lunch_status-"+str(get_time_string())+".jpg"
|
||||
camera.capture(file_name) # Take a picture and save it to file_name
|
||||
# Now send an e-mail
|
||||
send_email_pic.send_email("The fridge has been opened!", destination, "The fridge has been opened!", file_name)
|
||||
else:
|
||||
print ('.') # Do nothing! It's still dark.
|
||||
|
||||
time.sleep(.5) # If your hold time is less than this, you might not see as many detections
|
||||
|
||||
except IOError:
|
||||
print ("Error")
|
||||
59
Projects/Catch_A_Lunch_Thief/send_email_pic.py
Normal file
59
Projects/Catch_A_Lunch_Thief/send_email_pic.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#! /usr/local/bin/python
|
||||
# This example will show you how to send an email in python, with a picture
|
||||
# attachment. This example uses outlook.com to send an e-mail.
|
||||
|
||||
SMTPserver = 'smtp.live.com'
|
||||
sender = 'dexterexamples@outlook.com'
|
||||
|
||||
USERNAME = "dexterexamples@outlook.com"
|
||||
PASSWORD = "password"
|
||||
|
||||
text_subtype = 'plain' # typical values for text_subtype are plain, html, xml
|
||||
content="""\ Test message """
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
# from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP
|
||||
# protocol (port 465, uses SSL)
|
||||
|
||||
from smtplib import *
|
||||
from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
|
||||
from email.MIMEText import MIMEText
|
||||
# Here are the email package modules we'll need for images.
|
||||
from email.mime.image import MIMEImage
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
|
||||
def send_email(content, destination, subject, file):
|
||||
try:
|
||||
msg = MIMEMultipart()
|
||||
msg['Subject']= subject
|
||||
msg['From'] = sender # some SMTP servers will do this automatically, not all
|
||||
|
||||
fp = open(file, 'rb') # Open File name "file"
|
||||
img = MIMEImage(fp.read()) # Read the file.
|
||||
fp.close() # Good housekeeping: close the file.
|
||||
msg.attach(img) # Attach the file to the message.
|
||||
|
||||
conn = SMTP(SMTPserver, port = 587, timeout = 60) # timeout is critical here for long term health.
|
||||
conn.ehlo()
|
||||
conn.starttls()
|
||||
conn.ehlo()
|
||||
conn.login(USERNAME, PASSWORD)
|
||||
conn.set_debuglevel(1)
|
||||
try:
|
||||
conn.sendmail(sender, destination, msg.as_string())
|
||||
finally:
|
||||
conn.close()
|
||||
except Exception as exc:
|
||||
# Print a message error!
|
||||
print("Mail failed; %s" % str(exc))
|
||||
print("Moving on!")
|
||||
|
||||
# Example function call! This is what calling the function would look like!
|
||||
# send_email(content, destination, subject, file) where "content" is the content of the email, destination is the destination
|
||||
# of the e-mail (who you're emailing to) and subject is the subject of the e-mail. file is the filename of the image file
|
||||
# you want to attach. It's usually best to include the full path of the file!
|
||||
file = "/home/pi/test.jpg"
|
||||
destination = ['examples@dexterindustries.com'] # Enter the destination e-mail address here, between the ''
|
||||
send_email("Hello from my Raspberry Pi!", destination, "Hello from Dex!", file)
|
||||
Loading…
Add table
Add a link
Reference in a new issue