Using a Raspberry Pi Model B as a VOIP Pager

This was a slightly unusual reqest. I needed to build a paging system on the cheap for a client that already had an in-house Asterisk system. They wanted the receptionist to have the ability to dial an extension and have her voice pop out of speakers all over the building. Normally I would suggest purchasing some VOIP paging clients but they didn’t want to spend much money at all.

So, since I had some Raspberry Pi model B devices laying around I toyed with the idea of connecting loud (5W-10W) speakers to it and running a command line SIP client in auto-answer mode. In theory it should work, I’ve done something similar with small computers before. Originally I tried using Twinkle but I couldn’t get it working correctly. After a lot of compiling, and making a few small changes to the kernel modules I ended up getting it to work using Pjsua. I see that a lot of people had similar issues so the following is what I did to get it up and running correctly.

First, of course, I did a default installation of Raspbian. Since this isn’t going to be anything special I simply used Noobs to get the installation done quickly. At the end of the installation I selected the option that prevents X-Windows from starting at boot since I won’t be using it.

After the initial installation, I did the following to get everything up to date.

apt-get update
apt-get upgrade

Then I upgraded the firmware using the rpi-update script, you can skip this part if you are worried about messing up the firmware. If this post is a little old you might want to check to make sure there isn’t a more official easy method of updating the firmware.

sudo apt-get install git-core
sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
sudo chmod +x /usr/bin/rpi-update
sudo rpi-update
sudo reboot

I setup the Snd-Dummy module to use for the microphone since the Raspberry Pi doesn’t have one.

sudo modprobe snd-dummy
sudo nano -w /etc/modules
sudo reboot

After the reboot I set the sound card volume to 99%.

amixer set PCM 99

Then I installed a few things that were necessary to get Pjsau compiled and running correctly.

sudo apt-get install libv4l-dev libx264-dev libssl-dev libasound2-dev libasound2-plugins libasound2 libasound-dev asterisk build-essential automake autoconf libtool libpulse-dev libsamplerate0-dev libcommoncpp2-dev libccrtp-dev libzrtpcpp-dev libdbus-1-dev libdbus-c++-dev libyaml-dev libpcre3-dev libgsm1-dev libspeex-dev libspeexdsp-dev libcelt-dev alsa alsa-base alsa-utils alsa-tools

After this installation I rebooted, then stopped and disabled the Asterisk service since it was only installed to get some the dependencies.

sudo service asterisk stop
sudo update-rc.d asterisk disable

I downloaded the SDL code, compiled and installed it. Check the SDL site to make sure you have the latest code.This will take about 15-30 minutes to compile.

cd
mkdir sdl
cd sdl
wget http://www.libsdl.org/release/SDL2-2.0.3.tar.gz
tar xvfz SDL2-2.0.3.tar.gz
cd SDL2-2.0.3/
./configure
make
sudo make install

And finally I downloaded, compiled and installed Pjsip which includes Pjsua. Since I am only going to be using this from the command line I compiled it without the video options to avoid any potential conflicts. Check the Pjsip site to make sure you have the latest code. This will take about 30 minutes to compile.

cd
mkdir pjsip
cd pjsip
wget http://www.pjsip.org/release/2.3/pjproject-2.3.tar.bz2
tar xvfj pjproject-2.3.tar.bz2
cd pjproject-2.3/
./configure --disable-video --disable-ffmpeg --disable-v4l2
make dep
make
sudo make install
sudo reboot

The last reboot probably wasn’t necessary. Now that everything is installed all I need to do is configure the client, and setup the extension on the server. On the server I setup a standard SIP extension. If you are using FreePBX there is an “auto answer” option in the extension setup but that was not necessary in my test. In the following my SIP server is at 192.168.1.1, my SIP extension and username are 1501, and my extension password is xt1501. Note, this will only work if you are using the Snd-Dummy kernel module for the sound input. If you are using a newer version that comes with a microphone jack, or maybe using this as a guide to get it working on another device please use aplay -L or alsamixer to get the correct capture-dev and playback-dev settings.

nano -w /home/pi/1501.cfg
--id sip:1501@192.168.1.1
--registrar sip:192.168.1.1
--realm *
--username 1501
--password xt1501
--auto-answer 200
--capture-dev 2
--playback-dev 0

Now I can start the Pjsua SIP client using the configuration file I just created to connect to the server. The Pjsua binary that was compiled on my system is named pjsua-armv6l-unknown-linux-gnueabihf. It may be different on your system, if so change that in the following code.

/home/pi/pjsip/pjproject-2.3/pjsip-apps/bin/pjsua-armv6l-unknown-linux-gnueabihf --config-file /home/pi/1501.cfg

Once you run the above command you should see a lot of text scroll by that looks something like the following:

--end msg--
04:10:49.186 pjsua_app.c ..Received MWI for acc 0:
04:10:49.187 pjsua_app.c .. Content-Type: application/simple-message-summary
04:10:49.190 pjsua_app.c .. Body:
Messages-Waiting: no
Message-Account: sip:*97@192.168.1.1
Voice-Message: 0/0 (0/0)

04:10:50.152 pjsua_aud.c !Closing sound device after idle for 1 second(s)
04:10:50.153 pjsua_app.c .Turning sound device OFF
04:10:50.154 pjsua_aud.c .Closing bcm2835 ALSA: bcm2835 ALSA (hw:0,0) sound playback device and Dummy: Dummy PCM (hw:1,0) sound capture device

If you press enter you should see a menu like the following:

pjsuamenu

Now, from another phone you should be able to call the extension you setup on the Raspberry Pi. It should auto-answer and when you speak into the phone it will automatically be played through the speakers connected to the Raspberry Pi. If you install multiple Raspberry Pi clients and put them in a paging group, or add them to an existing paging group with other devices, they will all play the audio when you dial that group. If you are using speakers that are at least 10W with a built in amplifier you should be able to use this as a pager for a large room or hallway.

7 Comments
Share:

7 Comments

  1. James Rossie says:

    Hey thanks for the writeup. This was the first time I was able to pjsip to work on my pi. Did you ever try to get pjsua to run in the background like setting up with cron? I’m trying to make that work. Works fine when running from terminal interactively but will not auto answer when process is running after being initiated from cron.

    1. djinn says:

      Unfortunately I have been spending every spare moment on a big project at work for the last two months. Everything I was working on has been put on the back burner. So no, I haven’t done any more work on this.

      I just ordered a couple of electronics enclosures and USB sound cards. In my spare time over the next few weeks I am going to try to build a prototype of a Raspberry Pi case with integrated speaker and microphone, and see if our suppliers overseas can build something professional looking based off of the design. While working on that I will definitely give the cron option a try, thanks for mentioning it. Hopefully I will have time to update the project with the new case and any changes I need to make to get it working and looking decent enough to sell. If I have any success getting pjsau running as a background process I will definitely include that info in the update.

  2. Khan Aaqib says:

    Here it is set to auto answer, What am i supposed to do if i want to make call from one raspberry to another and option should be there for answer or rejection.
    Removing –auto-answer 200 would be enough or what?

  3. Alexandre St-Jacques says:

    For the ones asking how to auto-start the pager, I did a cronjob with :
    crontab -e
    @reboot /home/pi/start.sh

    did a file start.sh in my home directory with this line :
    screen -A -m -d -S “Page” /home/pi/page.sh

    and made an other file page.sh with :
    /home/pi/pjsip/pjproject-2.3/pjsip-apps/bin/pjsua-armv6l-unknown-linux-gnueabihf –config-file /home/pi/pager.cfg

    Hope this helps

  4. Carl Fortin says:

    This is a great project. Thanks a lot. I got it working with the raspberry pi zero as the pjsip client.
    I am using Asterisk PJSIP realtime in a raspberry pi 2, and it’s working pretty good.
    My next step will be to make a call by pushing a physical button connected to the raspberry.

Leave a Reply