calebzulawski wrote:This is a good starting project; it's relatively simple as long as you have a basic understanding of programming, which you do, so you're all set.
First, if you plan on using the GPIO pins, you must buffer your detection circuit, as the GPIO pins have no protection built in, and I believe are 3V3, not the standard 5V. Various methods of isolation exist... opto-isolators, reed switches, relays. I'm not sure which are appropriate for this application.
In addition, you'll need to create the detection circuit. If you are using a simple switch (contact is lost when the door opens) you'll need pull-up or pull-down resistors so that your switch outputs a digital voltage difference at all times.
I set my son a summer holiday challenge per the topic of this thread, so we had a go at the MagPi project. It wasn't entirely straightforward so I've posted a howto on my blog that covers getting GPIO going with Python and including working source code.domesday wrote:The latest issue of the MagPi (Issue 4) has an article on building an alarm, might be a good starting point.
I've been browsing MagPi, and dipping into interesting looking projects, but obviously I failed to appreciate the dependency on earlier issues here.domesday wrote:BTW, well done for sticking with it and getting it working.
The family all use Gmail/GApps so I found some decent example code that sends emails via the Google SMTP servers using smtplib. I stripped out the attachment code as it's not required for this use case (though could be interesting for a more sophisticated project using a webcam) and left a working 'Hello World!' example on ~/ of my son's Raspbian SD card. Let's see how long it takes him to pull the code together?domesday wrote:Obviously the next step for you is to modify the program to call a routine to send an email, I expect there is a library for that, http://docs.python.org/library/smtplib. ... le-smtplib maybe?
Code: Select all
import os import smtplib import mimetypes from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email.MIMEAudio import MIMEAudio from email.MIMEImage import MIMEImage from email.Encoders import encode_base64 def sendMail(subject, text): gmailUser = '[email protected]' gmailPassword = 'yourSecr3t' recipient = '[email protected]' msg = MIMEMultipart() msg['From'] = gmailUser msg['To'] = recipient msg['Subject'] = subject msg.attach(MIMEText(text)) mailServer = smtplib.SMTP('smtp.gmail.com', 587) mailServer.ehlo() mailServer.starttls() mailServer.ehlo() mailServer.login(gmailUser, gmailPassword) mailServer.sendmail(gmailUser, recipient, msg.as_string()) mailServer.close() print'Sent email to %s' % recipient sendMail('Test', 'Hello World!')