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.
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
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
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.
tar xvfz SDL2-2.0.3.tar.gz
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.
tar xvfj pjproject-2.3.tar.bz2
./configure --disable-video --disable-ffmpeg --disable-v4l2
sudo make install
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
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:
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:
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:
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.