📜 ⬆️ ⬇️

Asterisk for home

What is Asterisk and why is it needed at home

Asterisk is an open virtual PBX (telephone switch). You can read more about Asterisk in the Asterisk IP-PBX blog. It all started with the fact that I received a rather large bill from a local telephone company for mediogurid negotiations. There were actually two options to pay less: either buy IP telephony cards and call from a home phone using a card, or call from a PC via SIP providers. The first option is inconvenient because it is necessary to search and buy cards of the desired IP telephony provider, and the second one is tied to a computer. The decision came when I found out about Asterisk. It could be connected to both a landline and a SIP provider and to a home landline phone. At home, I already had a server on which to install everything.

Installation and Setup

So, the first step is to install Asterisk. In debian it is done extremely simply. You just need to install the asterisk package. I recommend installing version 1.6 of squeeze (testing at the moment, later it will be version 6.0) of the Debian distribution, since there is an addon chan_mobile for it, but more on that later.
There are many Russian-language articles about setting up SIP connections and dialplans, so I will not dwell on this.

Secondly, you need to connect Asterisk to the landline and to the home phone. To do this, Digium produces special PCI and PCI-e cards. They are quite expensive, but on eBay, you can find their counterparts released by the Chinese company OpenVox, which are much cheaper. I purchased a dual-port OpenVox A400E PCI-e card with one FXO port and one FXS port.

Further, setting up the katra:





channel => 1

channel => 2

SIP configuration:

register => login:password@provider
callerid="User" <1001>


sip_login, sip_password, provider is your login password and provider respectively.
user_login, user_password is the login and password for connecting the SIP phone to Asterisk.

Simple extensions.conf:


exten => s,n,Answer()
exten => s,n,Playback(tt-weasels)
exten => s,n,Hangup()

exten => s,n,Answer()
exten => s,n,WaitExten(30)
exten => _0.,1,NoOp()
exten => _0.,n,Goto(outbound-city,${EXTEN},1)
exten => _NXXXXXX,1,NoOp()
exten => _NXXXXXX,n,Goto(outbound-city,${EXTEN},1)
exten => _NXXNXXXXXX,1,NoOp()
exten => _NXXNXXXXXX,n,Goto(outbound-sip,${EXTEN},1)

exten => t,1,Playback(vm-goodbye)
exten => t,n,Hangup()
exten => i,1,Playback(invalid)
exten => i,n,Hangup()

exten => s,n,Answer()
exten => s,n,Dial(SIP/user_login)
exten => s,n,Hangup()

exten => s,n,Answer()
exten => s,n,Dial(DAHDI/1)
exten => s,n,Hangup()

exten => _XXXXXXXXXX,1,Dial(SIP/$[7${EXTEN}]@provider)
exten => _XXXXXXXXXX,n,Hangup()

exten => _0.,1,Dial(DAHDI/2/${EXTEN})
exten => _0.,n,Hangup()
exten => _NXXXXXX,1,Dial(DAHDI/2/${EXTEN})
exten => _NXXXXXX,n,Hangup()

Such extension.conf allows you to call from your home phone to seven-digit numbers and numbers starting with 0 through the city telephone network, and to long-distance numbers through a SIP provider.

Additional features

1. Record all telephone conversations

To do this, in Dialplan (extensions.conf) insert a call to the application MixMonitor.
exten => s,n,Answer()
exten => s,n,MixMonitor(phone-${UNIQUEID}.wav)
exten => s,n,WaitExten(30)

Call records will be added to the / var / spool / asterisk / monitor folder

2. Receive and send faxes

To send a fax, call the SendFax application and pass the name of the TIFF file as an argument. TIFF can be obtained from PDF with the command
$ /usr/bin/gs -q -sDEVICE=tiffg3 -sPAPERSIZE=a4 -r204x196 -dNOPAUSE -sOutputFile=/var/spool/asterisk/outgoing/mydocument.tif -- /var/spool/asterisk/outgoing/mydocument.pdf
Please note that not any TIFF file can be sent as a fax, but only in TIFF / F format (tiffg3).
To send a fax manually, launch the asterisk console and execute the command:
# asterisk -r
server*CLI> originate originate DAHDI/1 application SendFax /tmp/test.tif

In order to configure fax reception, add the following to dialplan:
exten => s,n,Answer()
exten => s,n,Wait(5)
exten => s,n,Dial(DAHDI/1)
exten => s,n,Hangup()

exten => fax,1,ReceiveFax(/var/spool/asterisk/fax/${CALLERID(num)}-${UNIQUEID}.tif)
exten => fax,n,Hangup()

A delay of 5 seconds after Answer () is necessary in order for Asterisk to recognize the incoming fax signal and switch to extension fax.
Do not forget to specify faxdetect = both in chan_dahdi.conf.

Incoming faxes will be folded in TIFF format in the / var / spool / asterisk / fax folder
There are scripts that allow to automate the process of receiving / transmitting faxes with conversion to PDF and back, as well as sending received faxes to e-mail.

3. Filtering calls by callerid

In order for CALLERID to work, I had to separately order the corresponding service from a telephone operator. Fortunately, it is free, but I connected it for a couple of days. If CALLERID works, then the dialplan can be controlled depending on the number from which the call comes.
exten => s,1,Wait(2)
exten => s,n,GotoIf($["${CALLERID(num):-10}" = "5555555555"]?1000)
exten => s,n,Dial(DAHDI/1)
exten => s,n,Hangup()

exten => s,1000,Wait(600)
exten => s,n,Answer()
exten => s,n,Congestion()
exten => s,n,Hangup()

In this example, calls from 5555555555 are ignored.
Important note: CALLERID is transmitted before the handset is lifted, and fax signals are transmitted after the handset is lifted. Therefore, for a stable reception of the fax signal, it is necessary to put a delay after Answer, I sometimes have to add a delay to Answer for a steady reception of CALLERID.

4. Connect to the GSM network

In order to make calls via the GSM network, there are special PCI-e cards worth more than $ 1,000, which is not acceptable at home. But, fortunately, there is an addon to Asterisk, which allows you to use a regular cell phone as a gateway to the GSM network. To do this, install the asterisk-mobile package. It appeared in the Debian distribution not so long ago. In addition, you need a USB Bluetooth adapter. Anyone working under Linux will do (Asterisk can work via bluez), and the phone itself that supports Bluetooth.
in mobile.conf we write:


Where instead of 00: 11: 22: 33: 44: 55 address of your Bluetooth adapter.
Run the Asterisk console and look for the phone:
server*CLI> mobile search
Address Name Usable Type Port
66:77:88:99:AA:BB Nokia Yes Phone 13

Add a section for mobile to mobile.conf:

Where instead of 66: 77: 88: 99: AA: BB is the address of your phone, and instead of port = 13 you need to enter the port on which your phone works. After that, you can restart the chan_mobile module and check that everything works.
server*CLI> module unload chan_mobile
server*CLI> module load chan_mobile
server*CLI> mobile show devices
ID Address Group Adapter Connected State SMS
GSM 66:77:88:99:AA:BB 0 blue Yes Free Yes

In the dialplan, add the incoming and outgoing contexts:
exten => _913NXXXXXX,1,NoOp()
exten => _913NXXXXXX,n,Goto(outbound-gsm,${EXTEN},1)

exten => s,n,Answer()
exten => s,n,Dial(DAHDI/1)
exten => s,n,Hangup()

exten => _NXXNXXXXXX,1,Dial(Mobile/GSM/${EXTEN})
exten => _NXXNXXXXXX,n,Hangup()

Calls to mobile numbers in the Siberian region will be sent via GSM.

Important note: do not forget to pair the server with your phone. This is done with the command / usr / bin / bluetooth-agent

If your phone supports sending SMS, then you can configure sending SMS from dialplan. For example, when receiving a fax:
exten => fax,1,ReceiveFax(/var/spool/asterisk/fax/${CALLERID(num)}-${UNIQUEID}.tif)
exten => fax,n,MobileSendSMS(GSM,+75555555555,incoming fax #${UNIQUEID} from ${CALLERID(num)})
exten => fax,n,Hangup()


Asterisk has many additional features that are not mentioned in this topic. For example, you can take: voice menus and integration with the Festival voice synthesis system, voice mailboxes, placing calls in a queue, etc. But it is difficult to think of these features in everyday life, so we omit them. Perhaps readers will figure out how else you can use the home Asterisk PBX.

Source: https://habr.com/ru/post/103218/

All Articles