wkm001
Posts: 4
Joined: Sat Dec 07, 2013 6:52 pm

Simple Doorbell

Sat Dec 07, 2013 7:21 pm

Through my searching on this site some of the doorbell ideas are quite impressive. But I want to do something much more simple.

Like most homes, my dogs bark when the doorbell rings. The wire for my doorbell runs through the basement. I want to remove the doorbell and power supply for the doorbell from the equation. Can I detect when two pins on the Pi are shorted by the outdoor switch and send an email? I'll send the email to <My10DigitPhoneNumber>@vtext.com so it will be delivered to my mobile phone as an SMS.

From other postings it looks like I could create a Gmail address for this purpose. But if the script can support SMTP Auth I can use Comcast's SMTP server.

Can someone point me in the right direction?

User avatar
DougieLawson
Posts: 39880
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Simple Doorbell

Sat Dec 07, 2013 10:04 pm

As long as your ISP has port 25 open for you. Then you can send email.

The email doesn't need 100% valid headers, it does need a valid RFC2821 envelope (for GMail). The RFC2822 payload is valid even with bogus addresses. I had to use the reverse DNS lookup for my public IP address for the from address (else Google rejected it).

Start by installing & configuring postfix on your Pi. You've already got python smtplib. It does support authentication if you need it.

Here's a sample (not using authentication):

Code: Select all

#!/usr/bin/python

import smtplib

toaddr = 'xxxxxx@gmail.com'    # redacted
me = 'doorbell@194-105-xxx-xxx.ifb.co.uk'    # redacted
msg = """From: Doorbell <doorbell@pi.local>
To: Dougie <xxxxxx@gmail.com>   #redacted
Subject: Door bell ringing

DING DONG
"""

try:
  s = smtplib.SMTP('localhost')
  s.sendmail(me, toaddr, msg)
  s.quit()
except SMTPException:
  print "Error: unable to send email"
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

wkm001
Posts: 4
Joined: Sat Dec 07, 2013 6:52 pm

Re: Simple Doorbell

Sat Dec 07, 2013 10:35 pm

Port 25 is not open.

User avatar
DougieLawson
Posts: 39880
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Simple Doorbell

Sat Dec 07, 2013 10:58 pm

wkm001 wrote:Port 25 is not open.
Are ports 587 or 465 (SMTP SSL) open on your ISP's mail relay?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

wkm001
Posts: 4
Joined: Sat Dec 07, 2013 6:52 pm

Re: Simple Doorbell

Sat Dec 07, 2013 11:09 pm

I found this thread that is pretty much what I want to do. http://www.raspberrypi.org/phpBB3/viewtopic.php?t=31818

But I have no idea which pins they are talking about our where to put the code.

User avatar
DougieLawson
Posts: 39880
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Simple Doorbell

Sat Dec 07, 2013 11:50 pm

You can use any GPIO pins.
I'd use GPIO22 (pin#15) because it's neighbour (pin# 17) is 3V3.

So now we just need to work out how to use Comcast's SMTP server.
Last edited by DougieLawson on Sun Dec 08, 2013 12:52 am, edited 1 time in total.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
DougieLawson
Posts: 39880
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Simple Doorbell

Sun Dec 08, 2013 12:40 am

Start by installing WiringPi2

git clone https://github.com/Gadgetoid/WiringPi2-Python.git
cd WiringPi2-Python
sudo python setup.py install

OR
sudo pip install wiringpi2

Code: Select all

#!/usr/bin/python
import smtplib
import wiringpi2 as wiringpi
from time import sleep       # allows us a time delay

wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(18, 1)      # sets GPIO 18 to output
wiringpi.digitalWrite(18, 0) # sets port 18 to 0 (0V, off)

wiringpi.pinMode(22, 0)      # sets GPIO 22 to input

try:
    while True:
        if wiringpi.digitalRead(22):     # If button on GPIO22 pressed
           toaddr = 'xxxxxx@gmail.com'
           me = 'doorbell@194-105-xxx-xx.ifb.co.uk'
           msg = """From: Doorbell <doorbell@pi.local>
To: Dougie <xxxxxx@gmail.com>
Subject: Door bell ringing

DING DONG
"""
           try:
              s = smtplib.SMTP('smtp.comcast.net', 587)
              s.login(comcast-userid, comcast-password) # send credentials
              s.sendmail(me, toaddr, msg)
              s.quit()
           except SMTPException:
              print "Error: unable to send email"
           wiringpi.digitalWrite(18, 1) # switch on LED. 
        else:
           wiringpi.digitalWrite(18, 0) # switch off LED.
        sleep(10)                      # delay 10s (which may be too long)

finally:  # when you CTRL+C exit, we clean up
    wiringpi.digitalWrite(18, 0) # sets port 18 to 0 (off)
    wiringpi.pinMode(18, 0)      # sets GPIO 18 back to input Mode
    # GPIO 22 is already an input, so no need to change anything
That program has to run with root privileges.
sudo /home/pi/wireMail.py
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Simple Doorbell

Sun Dec 08, 2013 12:45 am

Hi,
wkm001 wrote:Can I detect when two pins on the Pi are shorted by the outdoor switch and send an email?
DO NOT focus just on software part of the implementation !
You shouldn't simply connect wires to RasPi's GPIO and then through basement and frontyard connect the other end to a doorbell pushbutton... this approach warmly invites troubles.
I'd add few elements to keep the troubles away. ;)

I like to use opto-coupletrs for this kind of use cases. The circuit should be located close to RasPi. Additionally, power supply of this circuit could be the same as for RasPi.
Since I don't prefer "ASCII-grapics", I've just draw an example circuit, which should work well for selected components:
Image

Elements are not critical... pick something what is next to your hand. Take the resistor which limits current to around 10-15 mA. Most optocouplers would be fine with this current (but check related datasheet anyway, required current might be higher, specially for older opto-coupler models). Some opto-couplers also require pull-up resistor at the output... check also this.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

User avatar
DougieLawson
Posts: 39880
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Simple Doorbell

Sun Dec 08, 2013 1:00 am

Thanks Ivan.

I'm a software specialist. So I tested the code with a breadboard a resistor and an LED. My quick2wire interface board has a push button (with a 10K pull down resistor).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

wkm001
Posts: 4
Joined: Sat Dec 07, 2013 6:52 pm

Re: Simple Doorbell

Sun Dec 08, 2013 1:17 am

Looks like the code from the link above takes into account logging in.

# send mail
s = smtplib.SMTP('smtp server')
s.login('user name' , 'Password')
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit
print "Email sent"
time.sleep(2)

Return to “Automation, sensing and robotics”