Hack 57. Route Calls Using Distinctive Ring
Do you have only one phone line, but wish you could use two phone numbers with your Asterisk server? Try distinctive ring.
Distinctive ring is a feature offered by some phone companies that permits you to use two or three phone numbers with the same POTS line. Depending on which number is dialed, the ring signal will differ, causing the ring to sound unique for each number. This feature allows parents to avoid answering their teenagers' incoming calls. With a fax/voice ring switch device, you can use distinctive ring as an inexpensive way to receive both fax and voice calls on a single line.
With Asterisk, you can use distinctive ring to route calls automatically from the PSTN trunk to a specific phone or group of phones. Or, the distinctive ring can just be passed through to all of the phones on the private network, which will ring distinctively, and the intended recipient can answer her call on any available phone.
You can configure each Zaptel channel to detect up to four different distinctive signals. The first thing you'll need to do is open zapata.conf and add this configuration to the section for the trunk in question:
The signals used by distinctive ring consist of analog electrical cadencesvariations in voltage that cause analog phones to produce certain ring patterns. Asterisk uses the dring attribute in zapata.conf to describe the signals. Unfortunately, these signals vary from one regulatory jurisdiction to the next, and you'll have to figure out what value to give dring attributes yourself.
Here's how. When an incoming call is received on a POTS interface, Asterisk records the ring pattern in Asterisk's verbose logging output (assuming you launched Asterisk with -vvvv on the command line). Use the tail command with its -f option to watch your logfile for changes as they occur:
# tail -f /var/log/asterisk/full
While tail is following the logfile, call each number that causes distinctive rings on your POTS lines. When the POTS interface senses the ring pattern, a log entry will appear containing Asterisk's representation of it: a string of digits made up of three values separated by commas. Each value represents a duration of ringing, such that each ring pattern could have up to three rings of varying length in a one- or two-second time span. The pattern repeats at regular intervals until the call is answered.
This string supplies a value to the dring argument in zapata.conf. Repeat this process until you've identified the strings needed for each phone number associated with your POTS line. Here's a sample config in zapata.conf that describes two distinctive ring signals and assigns them different contexts in the dial plan:
usedistinctiveringdetection=yes dring1=325,95,0 dring2=95,0,0 dringcontext1=TedsCalls dringcontext2=JakesCalls channel =>1
The Zaptel channel's configuration will tell Asterisk the context into which distinctively rung calls are sent. In this example, we've used a POTS line with two ring signals and two corresponding contexts. Now, we've got to create those contexts in the dial plan. Here's a sample that accomplishes that in extensions.conf:
[TedsCalls] exten => s,1,Dial(SIP/201,30) exten => s,2,Voicemail(201) [JakesCalls] exten => s,1,Dial(SIP/202,30) exten => s,2,Voicemail(202)
There! Ted's distinctive ring will send Ted's calls to SIP/201, and Jake's distinctive ring will send them to SIP/202.