Tuesday, April 14, 2015

Building a Home IP Phone Network with Raspberry Pi and Asterisk

Check on Amazon I set up a PBX (IP phone server) on Raspberry Pi and got old smartphones working as internal extension phones.
I handed one to my 5-year-old daughter and she was thrilled to have her own phone — now I get calls at the most random moments.

With the right configuration you can also connect to an external phone line for real incoming and outgoing calls, but the goal here is just a fun toy phone for the kids.

I'm using the Raspbian environment I set up as a file server the other day.

Asterisk vs RasPBX

The software that turns a Raspberry Pi into a PBX is called Asterisk.
There's actually a dedicated Raspberry Pi distribution called RasPBX that comes up and running as a PBX right away, with web-based configuration.

Since I want to use this Pi for other things alongside the phone server, I installed Asterisk on its own rather than using RasPBX.

Installing Asterisk

Just apt-get it:
pi@raspberrypi ~ $ sudo apt-get install asterisk
Reading package lists... Done
Building dependency tree
           :

The required user account is created automatically.

Configuring Asterisk: /etc/asterisk/sip.conf


First, create extension numbers in /etc/asterisk/sip.conf.
It's a huge file but almost entirely comments.
Find the general section, make one change, then just append your extensions at the bottom.
[general]
localhost=192.168.11.0/255.255.255.0
[5130]
type=friend
username=5130
secret=PASSWORD
canreinvite=no
host=dynamic

[5134]
type=friend
username=5134
secret=PASSWORD
canreinvite=no
host=dynamic

Replace the network address in the general section with the one your Raspberry Pi is on.

The bracketed numbers are the extension numbers (phone numbers).
Any number of digits is fine, but keeping the same leading digit across all extensions makes the next configuration step easier.

The username and PASSWORD are the credentials used when registering a phone. For home use, these don't need to be strong.

Configuring Asterisk: /etc/asterisk/rtp.conf

By default, Asterisk reserves 10,000 ports for RTP. Reduce that to something reasonable:

rtpstart=10000
;rtpend=20000
rtpend=10010

Configuring Asterisk: /etc/asterisk/extensions.conf

Edit the [default] section to look like this:

exten => _5XXX,1,Dial(SIP/${EXTEN},30)
exten => _5XXX,2,Congestion
exten => _5XXX,102,Busy

"_5XXX" means "any four-digit number starting with 5." Adjust to match the extension numbers you defined in sip.conf.

Restarting Asterisk

Configuration is done. Japanese prompts? Custom voice greetings? What are those?

Restart the service:
pi@raspberrypi ~ $ sudo service asterisk restart
Stopping Asterisk PBX: asterisk.
Starting Asterisk PBX: asterisk.

Setting Up the Smartphones

Search for "SIP" on Google Play or the App Store and you'll find plenty of options. Pick one you like.

Android has built-in SIP support but it's awkward to use — a third-party app is recommended.

For something kid-friendly, here's what I used:

In each app, enter the extension number, username, and password from sip.conf.
The phones need to be on the same Wi-Fi network as the Raspberry Pi.

Make a Call

That's all the setup done. Give it a try.
Note that the receiving side also needs to have the app running in the background to receive calls.

Handing an old smartphone to the kids and having it actually ring your phone is a lot of fun.

No comments:

Post a Comment