In this article by Stefan Sjogelid, author of book Raspberry Pi for Secret Agents Second Edition. We will be setting up SIP Witch by adding softphones, connect them together, and then we will run the softphone on the Pi.
When you're out in the field and need to call in a favor from a fellow agent or report back to HQ, you don't want to depend on the public phone network if you can avoid it. Landlines and cell phones alike can be tapped by all sorts of shady characters and to add insult to injury, you have to pay good money for this service. We can do better.
Welcome to the wonderful world of Voice over IP (VoIP). VoIP is a blanket term for any technology capable of delivering speech between two end users over IP networks. There are plenty of services and protocols out there that try to meet this demand, most of which force you to connect through a central server that you don't own or control.
We're going to turn the Pi into the central server of our very own phone network. To aid us with this task, we'll deploy GNU SIP Witch—a peer-to-peer VoIP server that uses Session Initiation Protocol (SIP) to route calls between phones.
While there are many excellent VoIP servers available (Asterisk, FreeSwitch, and Yate and so on) SIP Witch has the advantage of being very lightweight on the Pi because its only concern is connecting phones and not much else.
(For more resources related to this topic, see here.)
Once we have the SIP server up and running we'll be adding one or more software phones or softphones. It's assumed that server and phones will all be on the same network. Let's get started!
pi@raspberrypi ~ $ sudo apt-get install sipwitch
pi@raspberrypi ~ $ sudo nano /etc/default/sipwitch
Find the line that reads #PLUGINS="zeroconf scripting subscriber forward" and remove the # character to uncomment the line. This directive tells SIP Witch that we want the standard plugins to be loaded.
pi@raspberrypi ~ $ sudo nano /etc/sipwitch.conf
Note how some blocks of text are between <!-- and --> tags. These are comments in XML documents and are ignored by SIP Witch. Whatever changes you want to make, ensure they go outside of those tags.
<user id="phone1">
<extension>201</extension>
<secret>SecretSauce201</secret>
<display>Agent 201</display>
</user>
<user id="phone2">
<extension>202</extension>
<secret>SecretSauce202</secret>
<display>Agent 202</display>
</user>
The user ID will be used as a user/login name later from the softphones. In this default configuration, the extensions can be any number between 201 and 299. The secret is the password that will go together with the username on the softphones. We will look into a better way of storing passwords later in this chapter. Finally, the display string defines an identity to present to other phones when calling.
<localnames>[IP address]</localnames>
Those are all the changes we need to make to the configuration at the moment.
Basic SIP Witch configuration for two phones
pi@raspberrypi ~ $ sudo service sipwitch start
The SIP Witch server runs in the background and only outputs to a log file viewable with this command:
pi@raspberrypi ~ $ sudo cat /var/log/sipwitch.log
Command
|
Description
|
sudo sipwitch dump
|
Shows how the SIP Witch server is currently configured.
|
sudo sipwitch registry
|
Lists all currently registered softphones.
|
sudo sipwitch calls
|
Lists active calls.
|
sudo sipwitch message [extension] "[text]"
|
Sends a text message from the server to an extension. Perfect for sending status updates from the Pi through scripting.
|
Running your own telecommunications service is kind of boring without actual phones to make use of it. Fortunately, there are softphone applications available for most common electronic devices out there.
The configuration of these phones will be pretty much identical no matter which platform they're running on. This is the basic information that will always need to be specified when configuring your softphone application:
Once a softphone is successfully registered with the SIP Witch server, you should be able to see that phone listed using the sudo sipwitch registry command.
What follows is a list of verified decent softphones that will get the job done.
MicroSIP is an open source softphone that also supports video calls. Visit http://www.microsip.org/downloads to obtain and install the latest version (MicroSIP-3.8.1.exe at the time of writing).
Configuring the MicroSIP softphone for Windows
Right-click on either the status bar in the main application window or the system tray icon to bring up the menu that lets you access the Account settings.
Telephone is a basic open source softphone that is easily installed through the Mac App store.
Configuring the Telephone softphone for Mac OS X
SFLphone is an open source softphone with packages available for all major distributions and client interfaces for both GNOME and KDE. Use your distribution's package manager to find and install the application.
Configuring SFLphone GNOME client in Ubuntu
CSipSimple is an excellent open source softphone available from the Google Play store. When adding your account, use the basic generic wizard.
Configuring the CSipSimple softphone on Android
Linphone is an open source softphone that is easily installed through the iPhone App store. Select I have already a SIP-account to go to the setup assistant.
Configuring Linphone on the iPhone
It's always good to be able to reach your agents directly from HQ, that is, the Pi itself. Proving once again that anything can be done from the command line, we're going to install a softphone called Linphone that will make good use of your USB microphone.
This new softphone obviously needs a user ID and password just like the others. We will take this opportunity to look at a better way of storing passwords in SIP Witch.
Type sudo sipwitch dump to see how SIP Witch is currently configured. Find the accounts: section and note how there's already a user ID named pi with extension 200.
This is the result of a SIP Witch feature that automatically assigns an extension number to certain Raspbian user accounts. You may also have noticed that the display string for the pi user looks empty. We can easily fix that by filling in the full name field for the Raspbian pi user account with the following command:
pi@raspberrypi ~ $ sudo chfn -f "Agent HQ" pi
Now restart the SIP Witch server with sudo service sipwitch restart and verify with sudo sipwitch dump that the display string has changed.
So how do we set the password for this automatically added pi user? For the other accounts, we specified the password in clear text inside <secret> tags in /etc/sipwitch.conf. This is not the best solution from a security perspective if your Pi would happen to fall into the wrong hands. Therefore, SIP Witch supports specifying passwords in encrypted digest form. Use the following command to create an encrypted password for the pi user:
pi@raspberrypi ~ $ sudo sippasswd pi
We can then view the database of SIP passwords that SIP Witch knows about:
pi@raspberrypi ~ $ sudo cat /var/lib/sipwitch/digests.db
Now you can add digest passwords for your other SIP users as well and then delete all <secret> lines from /etc/sipwitch.conf to be completely free of clear text.
With our pi user account up and ready to go, let's proceed to set up Linphone:
pi@raspberrypi ~ $ sudo apt-get install linphone-nogtk
Now we fire up the Linphone command-line client:
pi@raspberrypi ~ $ linphonec
Warning: Could not start udp transport on port 5060, maybe this port is already used.
That is, in fact, exactly what is happening. The standard communication channel for the SIP protocol is UDP port 5060, and it's already in use by our SIP Witch server. Let's tell Linphone to use port 5062 with this command:
linphonec> ports sip 5062
linphonec> soundcard list
linphonec> soundcard show
linphonec> soundcard use [number]
Use the following command to list all currently supported codecs:
linphonec> codec list
Now use this command to disable all codecs that are not PCMU or PCMA:
linphonec> codec disable [number]
linphonec> register sip:pi@[IP address] sip:[IP address] [password]
That's all you need to start calling your fellow agents from the Pi itself. Type help to get a list of all commands that Linphone accepts.
The basic commands are call [user id] to call someone, answer to pick up incoming calls and quit to exit Linphone. All the settings that you've made will be saved to ~/.linphonerc and loaded the next time you start linphonec.
Now that you know the Linphone basics, let's explore some interesting features not offered by most other softphones.
linphonec> soundcard use files
pi@raspberrypi ~ $ sudo apt-get install espeak
Now we tell Linphone what to say next:
linphonec> speak english Greetings! I'm a Linphone, obviously.
This sentence will be spoken as soon as there's an established call. So you can either make an outgoing call or answer an incoming call to start the conversation, after which you're free to continue the conversation in Italian:
linphonec> speak italian Buongiorno! Mi chiamo Enzo Gorlami.
linphonec> autoanswer enable
pi@raspberrypi ~ $ sox "original file.mp3" -c 1 -r 48000 playme.wav
Now we can tell Linphone to play the file:
linphonec> play playme.wav
linphonec> record message.wav
In this article, we set up our very own phone network using SIP Witch and connected softphones running on a wide variety of platforms including the Pi itself.
Further resources on this subject: