Door Bell Server


28 posts   Page 1 of 2   1, 2
by cjpanici » Wed Aug 22, 2012 5:04 pm
I'd like my raspberry pi to act as a "Door Bell Server". Basically, I can not hear my door bell when I am in the basement of my home. So, I thought if my computer played an audio file and gave me a little popup or something, that would be AWESOME! Also this allows for future features that would be VERY cool and unique.

Design:
1. The door bell switch will go to the GPIO pins of the raspberry pi; simple button.
2. The server itself will play an audio file through a speaker connected to the RPi. (Have a client running on the server itself to play the audio)
3. The server program will listen for the client connections through a specific port using the socket python library
4. The server program will send messages to all clients that are connected when the door bell is pressed (GPIO pin goes high)
5. The client apps (python) will take the messages sent from the server and execute commands; play audio file.

Future plans
1. Have a camera connected to the RPi take a picture of the person at the door and send it to the clients through a GUI or email
2. Droid mobile clients, that way my phone will play audio when door bell rings. This NEEDS to be thought of when constructing the initial design!!!!
3. Swap the picture camera with a usb web cam to pop up a video feed when the door bell is pressed.
4. Be able to access the system from outside the local network to see who rings the doorbell when I am not home.
5. Upload the data to a "log" either in Access or SQL server.

Questions or foreseen roadblocks:
1. Can you create an app on droid that will take in TCP/IP messages? How to you connect a droid client to a server that's been coded in python?
2. I am confused on the socket library and having multiple clients connected to them. How to you make a client "loop" listening for commands?
3. How do you send commands to ALL connected clients from the server at once?

Other Comments:
I'd like to be able to connect to the RPi remotely using a VNC server from a Windows machine, is that even possible?
What version of linux should I use on the RPi for an application like this (I am used to Windows)?

Thanks for all of your help in advanced!!!
Chris
Posts: 10
Joined: Wed Aug 22, 2012 4:03 pm
by LeroyZ84 » Wed Aug 22, 2012 8:01 pm
nice project, that is one of my last things on the todo list, but is certainly nice.

for communicatione you perhaps want to look at web sockets http://www.websocket.org/demos.html it's a little like push messaging. if i'm guessing right.. twitter and whatsapp use this feature on android?
www.­djredmar.­com:­8080
Posts: 32
Joined: Fri Jul 27, 2012 9:23 pm
Location: Earth, Europe, Netherlands, Deventer
by cjpanici » Fri Sep 07, 2012 4:26 pm
UPDATE:

I actually have built a few software apps that talk with each other via socket messages. The server is on the RPi, and it is written in python. It supports multiple client connections, and given a command from the clients, will echo it to all the rest of the clients.

The door bell switch is attached to the GPIO pins on the RPi. The RPi has a separate client app (python again) that checks the status of the GPIO pins. When the pin goes high, the RPi client sends a message to the server (also running on the RPi) and then the server delivers another message to the rest of the clients. The rest of the clients then play an audio file at full volume. Now, any computer that is connected to the server will play an audio file when someone hits the door bell!

I have a python version of the client application, as well as a VB client application. The VB application is a lot more sophisticated because VB is in my wheelhouse as far as languages go. It will reconnect automatically if the server stops, it can be set to connect automatically (throw a shortcut in the startup folder). The server and client apps are working quite well. There are application settings to specify what file it will play when someone hits the switch, as well as reconnect times and other preferences.

The thing that I am working on now is a mobile client app so my phone will alert me when someone is at the door. I get the server connecting to the server fine, but there are separate threads, and I can't get the thing to receive data, only send it to the server. My wife and I have android phones so if anyone is good with java let me know and maybe we can collaborate. I am looking for something that will connect to a server, and wait until data is on the socket then write it to a multi-line TextEntry and parse the message.

Also, eventually, I want the RPi client to take a photo of the person at the door and send it to the client apps, or email it to my email address...but I am sure that is down the road further. I want to get all of the audio working first.

Thanks,
neech
Posts: 10
Joined: Wed Aug 22, 2012 4:03 pm
by mikerr » Fri Sep 07, 2012 5:03 pm
Many years ago I did similar but with a twist:

I rigged my door intercom system to dial my mobile phone - so I could "answer" the door from anywhere in the house,
worked well when I was working from home - caused confusion when I wasn't !
Got a Pi Camera? View it in my android app - Raspicam Remote ! No software required on the pi
User avatar
Posts: 1257
Joined: Thu Jan 12, 2012 12:46 pm
Location: NorthWest, UK
by cjpanici » Fri Sep 07, 2012 5:27 pm
Hahaha. Yeah, that would pose a problem when you were not at home.

Anyway, I am interested to see your webcam server project. Any online notes posted? Also, I am a greedy owner of 4 Pis....I love Pi!

Thanks,
neech
Posts: 10
Joined: Wed Aug 22, 2012 4:03 pm
by laptopu » Sat Sep 15, 2012 11:49 am
This is interesting work, thanks for posting your achievements. I am looking at incorporating a doorbell via the GPIO pins in an Asterisk PBX system. Using http://www.raspberry-asterisk.org I intend to set up an in-home PBX but when a doorbell is pressed it will ring the handsets for 10 seconds. What sort of script would I need to use for this, and is it just a simple case of connecting two pins via a doorbell push to trigger a script?
Posts: 13
Joined: Sat Sep 15, 2012 11:46 am
by navaismo » Tue Sep 18, 2012 2:32 am
laptopu wrote:This is interesting work, thanks for posting your achievements. I am looking at incorporating a doorbell via the GPIO pins in an Asterisk PBX system. Using http://www.raspberry-asterisk.org I intend to set up an in-home PBX but when a doorbell is pressed it will ring the handsets for 10 seconds. What sort of script would I need to use for this, and is it just a simple case of connecting two pins via a doorbell push to trigger a script?


If you are interested I have uploaded a little "how to" for make your raspberry pi as an IP Door bell.

http://raspimods.blogspot.mx/2012/09/po ... ta-de.html

You can use the translate drop down to change the language if you think its useful I can do a mini how to here in English.

NOTE: Just be careful with the GPIO and the power stage when you attach the real door.
Posts: 12
Joined: Fri Sep 14, 2012 2:54 am
by laptopu » Wed Sep 19, 2012 4:38 pm
Hi that is really useful and pretty much what I was thinking of doing. A mini guide on here would be fantastic.

I have some questions if you can help please? Would this setup work without a sound card, if the only thing I wanted to do was make all the Asterisk telephones ring? And what if I only wanted a bell push, no LED light, would I just need to ground one of the GPIO pins?

Thanks again for your help, it is great work.
Posts: 13
Joined: Sat Sep 15, 2012 11:46 am
by navaismo » Wed Sep 19, 2012 6:34 pm
Hi,

laptopu wrote:Would this setup work without a sound card, if the only thing I wanted to do was make all the Asterisk telephones ring?

Yes. Actually if you only want to trigger calls to your phones you don't need the USB sound card and don't need to compile alsa or oss support in your asterisk. I attached it in order to simulate an IP Intercom like the single button from this company http://www.its-tel.com/index.php?Itemid ... item_id=11

laptopu wrote: And what if I only wanted a bell push, no LED light, would I just need to ground one of the GPIO pins?

No you don't need the LED. You just need to attach the Button to the GPIO.
In my case the LED simulate the electronic lock, so if the person who answered the call want to open the door just enter the code(in the example the code is: 88) and it will activate the electronic lock(in the example is the LED).


So the circuit diagram to only use a button reduces to(large image here http://imgur.com/FqnNB):
Image

P1_01 is the 3.3V from the Raspberry Pi
P1_11 is the input PIN in this example pin 17 of the Chip.
P1_06 is the GND from the Raspberry Pi


Assuming your phones are registered in the asterisk running within the Raspberry Pi, you need only the listening script(this script monitor the state of the input PIN, I'm using the PIN #17, remember to initialize first in order to use it. Check this for more info: http://elinux.org/RPi_Low-level_periphe ... _script.29).

I have created an example for you:

Code: Select all
#!/bin/bash

while true;
do

   cmd=$(cat /sys/class/gpio/gpio17/value)

      if [ $cmd = '0' ]; then
         asterisk -rx 'originate local/s@fromdoor application Playback beep'
      fi
sleep 1
done


Then add the context in order to dial (If you use plain asterisk use the extensions.conf file. If you use freepbx based system use the extensions_custom.conf file):

Code: Select all
[fromdoor]
exten => s,1,SET(CALLERID(name)=From DOOR)
same => n,Dial(SIP/5001&SIP/5000,10)
same => n,hangup()

In the Dial command, change the dial string for your phones, in this case I'm calling two phones, 5000 & 5001 for 10 seconds.

And this is the video result: http://youtu.be/exmv-WD9EUE

Best Regards
Posts: 12
Joined: Fri Sep 14, 2012 2:54 am
by laptopu » Fri Sep 21, 2012 4:58 pm
That is great, and thank you for the examples they are really useful. I have my Pi on order and am not expecting it until Christmas, I have asked for one as my Christmas present :D

Once it arrives I will have a look at this and get it all set up properly. I have this page bookmarked. I hope yours works exactly how you want it to, good luck.
Posts: 13
Joined: Sat Sep 15, 2012 11:46 am
by cjpanici » Sat Oct 13, 2012 6:02 pm
Circuit:
Does anyone know if this will work? I am reluctant to test this....
Doorbell Circuit(2).jpg
Doorbell Circuit(2).jpg (42.88 KiB) Viewed 17950 times
Posts: 10
Joined: Wed Aug 22, 2012 4:03 pm
by cjpanici » Sat Oct 13, 2012 6:07 pm
I am also having a hard time finding a AC coil relay rated for 20VAC....Can I use a 24V DC relay?

I probably want to go solid state or optically isolated if possible to be sure ac power isn't leaked to the GPIO circuit.

Thanks for the help,
neech
Posts: 10
Joined: Wed Aug 22, 2012 4:03 pm
by laptopu » Sun Oct 21, 2012 11:48 am
So long as your relay completely isolates the Pi from the main voltage - which is what a relay should do, I can't see a problem with this. What you need to be careful of is making sure the relay is capable of doing what you need it to do, that's when you could find voltage on the Pi if the relay fails when it is not designed for what you want it to do.

A 24v relay will be fine with 20v but really you don't want to use a DC relay with AC circuits. Can you not drop the power from AC to DC instead? That may solve your problems.
Posts: 13
Joined: Sat Sep 15, 2012 11:46 am
by chrisidc » Sun Nov 18, 2012 7:12 pm
@navaismo:

asterisk -rx 'originate local/s@fromdoor application Playback beep'


Which command should/can be used to create a "real" call?
I mean a call from the asterisk server to be able to talk with an other client?

I am currently also trying to create such door bell and the pi should be act as asterisk server + sip client.
I searched the whole day, but was not able to find a solution to use the asterisk server also as sip client.
Posts: 2
Joined: Sun Nov 18, 2012 6:57 pm
by navaismo » Tue Dec 04, 2012 2:50 pm
chrisidc wrote:@navaismo:

asterisk -rx 'originate local/s@fromdoor application Playback beep'


Which command should/can be used to create a "real" call?
I mean a call from the asterisk server to be able to talk with an other client?

I am currently also trying to create such door bell and the pi should be act as asterisk server + sip client.
I searched the whole day, but was not able to find a solution to use the asterisk server also as sip client.


Hi, take a llok on my blog http://raspimods.blogspot.mx/2012/09/po ... ta-de.html

I'm using the raspberry Pi as doorbell to dial another asterisk server and ring One extension in order to speak and turn on a led(with that you can open a door too).

In my case I using the chan_alsa and I configure the context in the config file, so my command is "asterisk -rx 'console dial'" But you can use a local channel, a SIP or dahdi channel depends on your needs. More info type in your asterisk cli: core show application originate.

If you don't want to use guest calls in your remote asterisk you will need to use the register string and define a context for incoming/outgoing calls.
Posts: 12
Joined: Fri Sep 14, 2012 2:54 am
by WardieB » Fri Dec 28, 2012 3:47 pm
I've managed to put together a prototype doorbell that emails a push server on iPhone.
It works but as yet won't run on pi startup.

I designed it as my neighbour works in a shed at the bottom of his garden and never hears his door bell.

With my app it takes about four seconds from bell push to iPhone msg

http://raspbpi.blogspot.co.uk/
Posts: 2
Joined: Fri Dec 28, 2012 3:41 pm
by laptopu » Mon Jan 28, 2013 7:48 pm
Thinking about this, and how Navaismo has developed the idea, my original suggestion was to build just a door bell button with no intercom and the phones to ring for 10 seconds to signal someone was at the door. Navaismo posted a circuit diagram.

I have modified this diagram as I thought sometimes people wonder if a door bell button works - I would like to keep it lit up by an LED. What about if I replaced the 10k ohm resistor with an LED like the photo in my upload - how well would this work? Would I still need a resistor?
Attachments
LEDPi.png
LEDPi.png (7.36 KiB) Viewed 14622 times
Posts: 13
Joined: Sat Sep 15, 2012 11:46 am
by laptopu » Tue Jan 29, 2013 5:28 pm
Thinking more about my post above, how practical would it be to have two wires for the door push and two for an LED to light for a couple of seconds as soon as someone presses the doorbell so they have an acknowledgement?
Posts: 13
Joined: Sat Sep 15, 2012 11:46 am
by MansfieldMatthew » Wed Jan 30, 2013 11:25 am
I have the same problem as other here of working in a shed at the bottom of my garden so I've been planning to do the same thing myself as soon as I get some time.
Just as an addition to the thought here, I backed the Pebble watch on Kickstarter and it certainly would be great to get door bell notifications on my wrist regardless of where I am. Pebble are due soon to release details of how to send messages directly to your watch instead of relying on sending an email or message to your phone. Should be quite a slick solution.
I also plan to control my existing door ringer with my Raspi so that I can time control when it rings. This will mean that if anyone rings the door bell of an evening we'll receive notifications to our phones only so the loud ringer doesn't wake our baby daughter.
Posts: 2
Joined: Wed Jan 30, 2013 11:08 am
by laptopu » Wed Jan 30, 2013 9:38 pm
Yes it is exciting stuff indeed. I am still keen on getting an LED to light for say 2 seconds when the button is pressed just to acknowledge to the caller they know the button works but I'm struggling to understand how to build this into a circuit and how to write a script.

I also read in a newspaper today lots of schools are looking to buy Pi's to develop children's skills, I think this is amazing and exactly what we need.
Posts: 13
Joined: Sat Sep 15, 2012 11:46 am
by navaismo » Thu Jan 31, 2013 7:02 pm
laptopu wrote:Yes it is exciting stuff indeed. I am still keen on getting an LED to light for say 2 seconds when the button is pressed just to acknowledge to the caller they know the button works but I'm struggling to understand how to build this into a circuit and how to write a script.

I also read in a newspaper today lots of schools are looking to buy Pi's to develop children's skills, I think this is amazing and exactly what we need.

If you want to add another LED you need to enable another OUTPUT. Choose your preferred PIN and set as output. I.E. Let use the PIN 22 to add the led

First initialize the output:
Code: Select all
echo "22" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio22/direction


Then when the button is pressed:
Code: Select all
while true;
do

   cmd=$(cat /sys/class/gpio/gpio17/value)

      if [ $cmd = '0' ]; then
         asterisk -rx 'originate local/s@fromdoor application Playback beep'
         echo "1" > /sys/class/gpio/gpio22/value
         sleep(2)
         echo "0" > /sys/class/gpio/gpio22/value
      fi
sleep 1
done


And you add the LED as in the last diagram but in GPIO 22.
Posts: 12
Joined: Fri Sep 14, 2012 2:54 am
by laptopu » Fri Feb 08, 2013 5:16 pm
I am trying to get this script to start in the background when my Pi starts up. I have got this code so far:

Code: Select all
#! /bin/sh
# /etc/init.d/door.sh

### BEGIN INIT INFO
# Provides:          doorbell
# Required-Start:
# Required-Stop:
# Should-Start:     
# Default-Start:     
# Default-Stop:
# Short-Description: Allows monitoring of GPIO for doorbell
# Description:       Monitors GPIO 17 (physical pin 11) on Pi
#                    If shorted, will activate ring group.

### END INIT INFO

case "$1" in
  start)
    echo "Starting doorbell"
    # run application you want to start
    /etc/init.d/door.sh
    ;;
  stop)
    echo "Stopping doorbell"
    # kill application you want to stop
    kill /etc/init.d/door.sh
    ;;
  *)
    echo "Usage: /root/door.sh [start|stop]"
    exit 1
    ;;
esac


echo "17" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio17/direction

while true;
do

cmd=$(cat /sys/class/gpio/gpio17/value)

if [ $cmd = '0' ]; then
echo "Dialing"
asterisk -rx 'originate local/s@fromdoor application Playback beep'
fi
sleep .5
done

exit 0


I tried incorporating it using 'sudo update-rc.d door.sh defaults' and that seemed to work but the script isn't launched on boot.

If I do sudo door.sh start I can start the script but I am not returned to the command prompt - it works at this point but to get out I have to ctrl-c to exit the script then it doesn't run in the background. Any ideas please?
Posts: 13
Joined: Sat Sep 15, 2012 11:46 am
by navaismo » Fri Feb 08, 2013 10:21 pm
In Fedora Remix 17 this is how I handle the init script:
Code: Select all
#!/bin/bash
# sensing door daemon
# chkconfig: 345 20 80
# description: check if the  button on GPIO17 was pressed
# processname: ipdoor.sh

DAEMON_PATH="/root/"

DAEMON="./ipdoor.sh"
DAEMONOPTS="&"

NAME=door
DESC="Check If the Button on GPIO17 was pressed"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

case "$1" in
start)
         printf "%-50s" "Starting $NAME..."
        cd $DAEMON_PATH
        PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
        #echo "Saving PID" $PID " to " $PIDFILE
        if [ -z $PID ]; then
            printf "%s\n" "Fail"
        else
            echo $PID > $PIDFILE
            printf "%s\n" "Ok"
        fi
;;
status)
          printf "%-50s" "Checking $NAME..."
        if [ -f $PIDFILE ]; then
            PID=`cat $PIDFILE`
            if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
                printf "%s\n" "Process dead but pidfile exists"
            else
                echo "Running"
            fi
   else
            printf "%s\n" "Service not running"
        fi
;;
stop)
        printf "%-50s" "Stopping $NAME"
            PID=`cat $PIDFILE`
            cd $DAEMON_PATH
        if [ -f $PIDFILE ]; then
            kill -HUP $PID
            printf "%s\n" "Ok"
            rm -f $PIDFILE
        else
            printf "%s\n" "pidfile not found"
        fi
;;

restart)
        $0 stop
        $0 start
;;

*)
     echo "Usage: $0 {status|start|stop|restart}"
        exit 1
esac

I have created a file called 'door' in the /etc/init.d/ directory with the above code. My script to check the button lives in /root/ with the name 'ipdoor.sh'.

Then I added to the startup with:
Code: Select all
# chkconfig --add door
#chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

door              0:off   1:off   2:off   3:on   4:on   5:on   6:off

Then if I want to check the status:
Code: Select all
# service door status
Checking door...                                  Running
service door stop
Stopping door                                     Ok
# service door status
Checking door...                                  Service not running


Best Regards!
Posts: 12
Joined: Fri Sep 14, 2012 2:54 am
by laptopu » Sun Feb 10, 2013 11:54 am
This is great stuff but I'll admit getting a bit over my head now.

So to get things straight - I need two files, one named 'door' and that's the one I can paste into a file and then type 'sudo update-rc.d door defaults', then this file will point to ipdoor.sh (or door.sh as mine is called now)?

I'm okay up to that point I think, but you've lost me when you say about adding that code to startup - what file am I looking at there, and why is it important to have so many off - off - off - on parts to that?

Thanks again, I'm nearly there :lol:
Posts: 13
Joined: Sat Sep 15, 2012 11:46 am
by laptopu » Mon Feb 11, 2013 9:28 pm
I've cracked it, here's a link to another forum discussing PIAF that ties it all together:

http://pbxinaflash.com/community/index. ... ger.14414/

Thanks for everyone's help on here especially navaismo!
Posts: 13
Joined: Sat Sep 15, 2012 11:46 am