[How To] install and configure a full Voip server (Asterisk 13 & 16) on OpenWrt

In this tutorial, I'm going to show you how to install and fully configure Asterisk 13 (or 16) Voip server on OpenWRT 18.xx.xx (19.xx.xx), I commented out all parts that need to be modified with your actual configuration data.

  • Features: SIP channels, Jingle/XMPP client channel, GSM and SMS channel (chan_dongle), Blacklist, IVR (interactive voice reponse), Call-back, Wakeup call, Voicemail, Voicemail messages to email, Chanspy, Ring groups, Call diversion, Call Forwarding, Music on hold, shell script execution from a phone call (IVR choice) or from a SMS or XMPP message received (on part three of this how-to).

  • References
    my previous Asterisk_11_on_OpenWrt_14.04 guide: https://forum.archive.openwrt.org/viewtopic.php?id=53874&p=1#p253590
    Baresip Openwrt (14.04) SIP client: see previous link at post 4
    chan_dongle project: https://github.com/bg111/asterisk-chan-dongle

Important NOTE: USB external /overlay is needed, minimum 128 Mbytes of free space available is needed
Minimum of 64 Mbytes RAM is needed for full features server, CPU 400 Mhz or better

First part: packages installation

  • Prerequisites:
opkg update 
opkg install nano
opkg install zram-swap
opkg install msmtp
opkg install sox lame mpg123 # optional
  • mailsend SMTP configuration (gmail):

nano /etc/msmtprc
note: if you haven't installed nano (opkg install nano) use vi

account default
host smtp.gmail.com
port 587
auth on
user usename@gmail.com
password your-gmail-password
auto_from off
from username@gmail.com
tls on
tls_starttls on
tls_certcheck off
logfile
syslog LOG_MAIL
  • create Asterisk13 install script (for Asterisk 16 see below):

nano /root/asterisk-install.sh

insert the following lines:

opkg update
opkg install asterisk13 asterisk13-app-authenticate asterisk13-app-chanisavail asterisk13-app-chanspy asterisk13-app-confbridge asterisk13-app-controlplayback asterisk13-app-disa asterisk13-app-dumpchan asterisk13-app-exec asterisk13-app-followme asterisk13-app-ices asterisk13-app-ivrdemo asterisk13-app-minivm asterisk13-app-mixmonitor asterisk13-app-mp3 asterisk13-app-originate asterisk13-app-playtones asterisk13-app-read asterisk13-app-readexten asterisk13-app-record asterisk13-app-saycounted asterisk13-app-sayunixtime asterisk13-app-senddtmf asterisk13-app-sendtext asterisk13-app-sms asterisk13-app-stack asterisk13-app-system asterisk13-app-transfer asterisk13-app-url asterisk13-app-userevent asterisk13-app-verbose asterisk13-app-waitforring asterisk13-app-waitforsilence asterisk13-app-waituntil asterisk13-app-while asterisk13-app-zapateller asterisk13-bridge-builtin-features asterisk13-bridge-holding asterisk13-bridge-native-rtp asterisk13-bridge-simple asterisk13-bridge-softmix asterisk13-cdr asterisk13-cel-custom asterisk13-cel-manager asterisk13-chan-alsa asterisk13-chan-bridge-media asterisk13-chan-console asterisk13-chan-dongle asterisk13-chan-mobile asterisk13-chan-motif asterisk13-chan-oss asterisk13-chan-phone asterisk13-chan-rtp asterisk13-chan-sip asterisk13-codec-a-mu asterisk13-codec-alaw asterisk13-codec-g722 asterisk13-codec-gsm asterisk13-codec-lpc10 asterisk13-codec-resample asterisk13-codec-ulaw asterisk13-curl asterisk13-format-g723 asterisk13-format-g726 asterisk13-format-gsm asterisk13-format-ilbc asterisk13-format-ogg-vorbis asterisk13-format-pcm asterisk13-format-siren14 asterisk13-format-siren7 asterisk13-format-sln asterisk13-format-wav asterisk13-format-wav-gsm asterisk13-func-base64 asterisk13-func-blacklist asterisk13-func-callcompletion asterisk13-func-channel asterisk13-func-config asterisk13-func-cut asterisk13-func-dialgroup asterisk13-func-dialplan asterisk13-func-groupcount asterisk13-func-hangupcause asterisk13-func-holdintercept asterisk13-func-iconv asterisk13-func-jitterbuffer asterisk13-func-module asterisk13-func-periodic-hook asterisk13-func-pitchshift asterisk13-func-shell asterisk13-func-sysinfo asterisk13-func-talkdetect asterisk13-func-uri asterisk13-func-version asterisk13-func-vmcount asterisk13-func-volume asterisk13-pbx-loopback asterisk13-pbx-spool asterisk13-pjsip asterisk13-res-adsi asterisk13-res-agi asterisk13-res-clialiases asterisk13-res-clioriginate asterisk13-res-convert asterisk13-res-hep asterisk13-res-hep-pjsip asterisk13-res-hep-rtcp asterisk13-res-limit asterisk13-res-manager-presencestate asterisk13-res-monitor asterisk13-res-musiconhold asterisk13-res-mutestream asterisk13-res-parking asterisk13-res-phoneprov asterisk13-res-pjproject asterisk13-res-pjsip-phoneprov asterisk13-res-realtime asterisk13-res-rtp-asterisk asterisk13-res-rtp-multicast asterisk13-res-security-log asterisk13-res-smdi asterisk13-res-sorcery asterisk13-res-speech asterisk13-res-srtp asterisk13-res-timing-timerfd asterisk13-res-xmpp asterisk13-sounds asterisk13-util-smsq asterisk13-util-streamplayer asterisk13-voicemail

  • give the right permissions to the script:

chmod 755 /root/asterisk-install.sh

  • launch the script and wait for packages installation to be completed:

sh /root/asterisk-install.sh

  • when finished reboot the router
6 Likes

Part Two A: configuration files (overwrite the default configuration files)

nano /etc/asterisk/asterisk.conf
note: if you haven't installed nano (opkg install nano) use vi

[directories](!)
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /usr/lib/asterisk
astdbdir => /usr/lib/asterisk
astkeydir => /usr/lib/asterisk
astdatadir => /usr/lib/asterisk
astagidir => /usr/lib/asterisk/agi-bin
astspooldir => /root/spool/asterisk
astrundir => /var/run/asterisk
astlogdir => /root/spool/asterisk
astsbindir => /usr/sbin

[options]

verbose = 5
debug = 5
execincludes = yes
languageprefix = yes
maxcalls = 10
transmit_silence = yes
defaultlanguage = en
documentation_language = en_US
hideconnect = yes
;internal_timing = yes

[compat]
pbx_realtime=1.6
res_agi=1.6
app_set=1.6

nano /etc/asterisk/modules.conf


[modules]

autoload=yes
noload => res_timing_pthread.so
noload => pbx_gtkconsole.so
noload => res_musiconhold.so
noload => chan_alsa.so
noload => chan_console.so
noload => pbx_ael.so
load => pbx_spool.so
noload => chan_motif.so
noload => res_timing_timerfd.so
load => chan_dongle.so
noload => chan_iax2.so
noload => chan_mobile.so
noload => res_pjsip_transport_websocket.so
noload => cdr_syslog.so
noload => res_hep_rtcp.so
noload => res_hep_pjsip.so

nano /etc/asterisk/dongle.conf

[general]

interval=15

[defaults]

context=from-pstn
group=1
rxgain=5
txgain=-3
autodeletesms=yes
resetdongle=yes
u2diag=-1
usecallingpres=yes
callingpres=allowed_passed_screen
disablesms=no
language=en
smsaspdu=yes
mindtmfgap=45
mindtmfduration=40
mindtmfinterval=200
callwaiting=auto
disable=no
initstate=start
exten=+123456789 ;; put here your phone number
dtmf=relax

[dongle0]
audio=/dev/ttyUSB1 ;; check /dev/ttyUSBx with DMESG 
data=/dev/ttyUSB2 ;; check /dev/ttyUSBx with DMESG

nano /etc/asterisk/xmpp.conf

[general]

[asterisk]
type=client
serverhost=your-server-address
username=username
secret=your-password
priority=25
port=5222
usetls=no
usesasl=no
status=available
statusmessage="Available"
timeout=15
keepalive=yes
sendtodialplan=yes ;; this will take send unsolicited incoming xmpp messages into the dialplan
context=incoming-xmpp ;; this sets the context those incoming messages are sent to
;; note: for xmpp server on OpenWrt see https://openwrt.org/docs/guide-user/services/xmpp.server

nano /etc/asterisk/voicemail.conf

[general]

mailcmd=/usr/bin/msmtp receiver@mail.provider.com

[voicemail]

240 => 1234,root,receiver@mail.provider.com,attach=yes
  • notes: in this example 240 is the mailbox number, mailbox password is 1234
1 Like

Part Two B: configuration files (overwrite the default configuration files)

nano /etc/asterisk/sip.conf

 [general]
 transport=udp
 bindport=5060
 bindaddr=0.0.0.0
 nat=yes
 language=en
 allowguest=no
 srvlookup=no
 disallow=all
 allow=ulaw
 allow=alaw
 allow=gsm
 dateformat=%F %T
 alwaysauthreject=yes
 localnet=192.168.1.0/255.255.255.0 ;; change this according to your LAN configuration
 localnet=127.0.0.0/255.255.255.0
 tcpbindaddr=0.0.0.0
 tcpenable=yes
 jbenable=yes
 jbforce=yes
 jbmaxsize=250
 jbimpl=adaptive
 jbtargetextra=40
 jblog=no
 
 [200] ; internal extension ; SIP phones must be connected to LAN
 user=200
 type=friend
 secret=password_change_me
 host=dynamic
 qualify=yes
 nat=yes
 insecure=invite,port
 context=from-internal
 
 [201] ; internal extension ; SIP phones must be connected to LAN
 user=201
 type=friend
 secret=password_change_me
 host=dynamic
 qualify=yes
 nat=yes
 insecure=invite,port
 context=from-internal
 
;;put here your SIP Voip provider configurations, remove comments (;) to enable after editing:
;;note: change 0123456789 with your voipnumber
;;this is a general example, see your providers guides for the actual configurations
 
;register => 0123456789:voippassword@voip.provider.address.com:5060/0123456789
 
;[0123456789]
;username=0123456789 
;type=friend
;srvlookup=yes
;secret=voippassword
;realm=voip.provider.address.com
;nat=yes
;qualify=yes
;dtmfmode=auto
;insecure=invite,port
;host=voip.provider.address.com
;fromuser=0123456789
;fromdomain=voip.provider.address.com
1 Like

Part Two C: configuration files (overwrite the default configuration files)

  • basic extensions configuration (SIP, GSM and SMS)

nano /etc/asterisk/extensions.conf

[globals]

[general]
static=yes
writeprotect=yes
autofallthrough=yes

[from-internal]

;
;Chanspy Scanning
exten => 555,1,Chanspy(all,b)

;
;internal extension 200 - rings for 30 seconds
exten => 200,1,Dial(SIP/200,30)
exten => 200,2,Hangup()

;
;internal extension 201 - rings for 30 seconds
exten => 201,1,Dial(SIP/201,30)
exten => 201,2,Hangup()

;
; internal extension 98 voicemail management (password 1234 as per voicemail.conf)
exten => 98,1,Set(CHANNEL(language)=en)
exten => 98,n,VoiceMailMain(240@voicemail)
exten => 98,n,Wait(1)
exten => 98,n,Hangup()

;
; Ring group 600, ring all internal extensions for 30 seconds, if no one answers, the call goes to voicemail
exten => 600,1,Answer()
exten => 600,n,Set(CHANNEL(language)=en)
exten => 600,n,Ringing
exten => 600,n,Wait(1)
exten => 600,n,Dial(SIP/200&SIP/201,30)
exten => 600,n,Playback(vm-isunavail)
exten => 600,n,VoiceMail(240@voicemail)
exten => 600,n,Hangup()


[default]

; CALL OUT RULES ; see https://www.voip-info.org/asterisk-dialplan-patterns/
;
; GSM Dongle CALL OUT rules
; for US:
exten => _1NXXNXXXXXX,1,Dial(dongle/dongle0/${EXTEN})
; for Italy:
;exten => _0Z.,1,Dial(dongle/dongle0/${EXTEN})
;exten => _3.,1,Dial(dongle/dongle0/${EXTEN})

;
; SIP VOIP CALL OUT rules  (change 0123456789 with the voipnumber you have in sip.conf)
; for US:
exten => _1NXXNXXXXXX,1,Dial(SIP/${EXTEN}@0123456789)
; for Italy:
;exten => _0Z.,1,Dial(SIP/${EXTEN}@0123456789)
;exten => _3.,1,Dial(SIP/${EXTEN}@0123456789)

; SIP VOIP CALL IN rules (change 0123456789 with the voipnumber you have in sip.conf)
exten => 0123456789,1,Answer()
exten => 0123456789,n,Set(CHANNEL(language)=en)
exten => 0123456789,n,Ringing
exten => 0123456789,n,Wait(1)
exten => 0123456789,n,Dial(SIP/200&SIP/201,30,r)
exten => 0123456789,n,Playback(vm-isunavail)
exten => 0123456789,n,VoiceMail(240@voicemail)
exten => 0123456789,n,Hangup()

[from-pstn]

;
; GSM DONGLE CALL IN rules (change +123456789 with the exten number you have in dongle.conf)
exten => +123456789,1,NoOp(${CALLERID(NUM)})
exten => +123456789,n,Answer()
exten => +123456789,,n,Set(CHANNEL(language)=en)
exten => +123456789,n,Ringing
exten => +123456789,n,Wait(1)
exten => +123456789,n,Dial(SIP/200&SIP/201,30)
exten => +123456789,n,Playback(vm-isunavail)
exten => +123456789,n,VoiceMail(240@voicemail)
exten => +123456789,n,Hangup()

;
; all SMS's received on GSM dongle will be forwarded by email (change username@gmail.com as per /etc/msmtprc)
exten => sms,1,Noop(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})}) 
exten => sms,n,System(echo 'From: ${CALLERID(num)} <username@gmail.com>\nTo: <receiver@mail.provider.com>\nSubject:SMS received\nfrom: ${CALLERID(num)}\n${BASE64_DECODE(${SMS_BASE64})}' >> /tmp/sms.txt)
exten => sms,n,System(/usr/bin/msmtp username@gmail.com < /tmp/sms.txt &)
exten => sms,n,Wait(8)
exten => sms,n,System(/bin/rm -f /tmp/sms.txt) 
exten => sms,n,Wait(2)
exten => sms,n,Hangup() 
1 Like
  • Post install asterisk configurations:

/etc/init.d/asterisk disable

note: otherwise it might start too early

nano /etc/rc.local

#
/bin/sleep 10
/etc/init.d/asterisk start &
/bin/sleep 3
#
exit 0

reboot the router

Now you have an Asterisk Voip server up and running on your router

  • Asterisk commands
 /etc/init.d/asterisk start/stop/restart
 asterisk -vvvvr # asterisk cli
1 Like

Part three A: Shell script execution from a SIP voip call - IVR choice: 1 or 2

note: to be added to /etc/asterisk/extensions.conf under [default] section

; Shell script execution from a SIP voip call - IVR choice
; change 0123456789 with the voipnumber you have in sip.conf
;
exten => 0123456789,1,NoOp(${CALLERID})
exten => 0123456789,n,Answer()
exten => 0123456789,n,Ringing
exten => 0123456789,n,Set(TIMEOUT(digit)=7)
exten => 0123456789,n,Set(TIMEOUT(response)=21)
exten => 0123456789,n,Authenticate(1234,,4) ;; change 1234 with a password of your choice - 4 digits
exten => 0123456789,n,Background(1&activated&2&de-activated) ;; audio messages in /usr/share/asterisk/sounds
exten => 0123456789,n,WaitExten(5,2)
exten => 0123456789,n,Hangup()
;
exten => 1,1,Playback(activated)
exten => 1,2,System(/www/cgi-bin/start.cgi &) ;; shell script 1
exten => 1,3,Wait(2)
exten => 1,4,Hangup()
;
exten => 2,1,Playback(de-activated)
exten => 2,2,System(/www/cgi-bin/stop.cgi &) ;; shell script 2
exten => 2,3,Wait(2)
exten => 2,4,Hangup()

example line for the diaplan:

exten => s,n,System(/path/command)

Details:
System(command) - System command alone
System(command arg1 arg2 etc) - Pass in some arguments
System(command|args) - Use the standard asterisk syntax to pass in arguments

1 Like

to be continued soon ...

1 Like

Hello,
your tutorial very helpful, thank you very much.

Is there any step coming??
im using your tutorial to make my project

Yeah. There's the newer 19.07.0 rc1 and Asterisk 16.

Any additional input on this? Or should I start my own thread. My goals to run asterisk on the router and remotely access it ..

I followed Pilovis' guide and installed the stuff on my mipsel_mips32 router.
All went good except one thing which was my goal - asterisk13-chan-dongle. The openwrt-18.06.x feed's just missing this module for mipsel_mips32.

What is the reason and where can I find it? Thanks

Hi there,

Could be that the dependencies aren't available:

mod-usb-acm
kmod-usb-serial
kmod-usb-serial-option
libusb-1.0
usb-modeswitch

What router you got?

Dependencies you point are all in place.
Collected errors:

  • opkg_install_cmd: Cannot install package asterisk13-app-mp3.
  • opkg_install_cmd: Cannot install package asterisk13-chan-alsa.
  • opkg_install_cmd: Cannot install package asterisk13-chan-console.
  • opkg_install_cmd: Cannot install package asterisk13-chan-dongle.
  • opkg_install_cmd: Cannot install package asterisk13-chan-mobile

These 5 packages are sadly missing from the rmipsel_mips32 feed.
As for the router, a clone of Asus WL-500gP v2 ( brcm47xx/legacy) with 4/32 memory - D-link DIR-320 revA1.

Hi there,

Well, the problem is that the 18.06 package build bots use the SDK from ar7 (link) to build mipsel_mips32 packages. And this SDK for some reason unbeknownst to me doesn't have USB_SUPPORT nor AUDIO_SUPPORT. So the packages you mentioned above all vanish and aren't built.

So what can you do? You could build the packages yourself, with another SDK. The one that matches your router best should be in here. I downloaded it and indeed chan-dongle and chan-alsa etc are available in menuconfig. USB_SUPPORT and AUDIO_SUPPORT are both defined in this SDK.

2nd option is to go for OpenWrt 19.07. In there the mentioned packages are built by the build bots. Because on 19.07 the bots use brcm47xx/generic SDK to build mipsel_mips32 packages :laughing:

OpenWrt-19 comes with asterisk16. So I did a backward flip, found a LEDE version of the package and got it installed without errors. Voila:

OpenWrt*CLI> dongle show devices
ID Group State RSSI Mode Submode Provider Name Model Firmware IMEI IMSI Number
dongle0 1 Free 19 0 0 Beeline E1550 11.608.14.15.311 353... 25... +7905XXXXXXX

Work in progress...

Maybe that is worth a new topic then.

receiving a SMS message (Asterisk chan_dongle) and execute any command found (if any) in the SMS body message

1 Like

Chan Spy : listen in on a call, or whisper into a conversation.

If you have not installed it previously, you need to install app_chanspy module:

opkg update
opkg install asterisk13-app-chanspy

note: you need at least "beep.gsm" audio file in the asterisk sounds directory (see above).

Then simply add the following lines at the end of the file "/etc/asterisk/extensions.conf":

Chanspy Scanning
exten => 555,1,Chanspy(all,b)

note: put them under [from-internal] section

save and restart Asterisk.

Now by dialing 555 from another extension you can listen in on a call.

While spying, the following actions may be performed:

Dialing # cycles the volume level.
Dialing * will stop spying and look for another channel to spy on.
Dialing a series of digits followed by # builds a channel name to append to
(e.g. run ChanSpy(Agent) and dial 1234# while spying to jump to channel Agent/1234)

A number (161) to call to listen to the current time:

opkg update
opkg install asterisk13-app-sayunixtime
opkg install asterisk13-sounds
opkg install zoneinfo-core
opkg install zoneinfo-europe
; exact time now - call 161
exten => 161,1,Set(CHANNEL(language)=en)
exten => 161,n,SayUnixTime(,CET,AkMbdY)
exten => 161,n,Wait(2)
exten => 161,n,Hangup()

note: put them under [from-internal] section
you may want to change zoneinfo-europe and CET (Central European Time) to your timezone

Sometime you need to use audio files .sln you have created for another linux build, this is a simple way to convert .sln files to .gsm:

opkg update
opkg install sox

converting:

sox my_custom_message.sln my_custom_message.gsm

then put your custom files in the following directory:
/usr/share/asterisk/sounds/custom (asterisk 13).
/usr/lib/asterisk/sounds/custom (asterisk 11)

The dialplan (/etc/asterisk/extensions.conf) would be:

exten => 600,1,Answer()
exten => 600,n,Set(CHANNEL(language)=en)
exten => 600,n,Ringing
exten => 600,n,Wait(1)
exten => 600,n,Playback(./custom/please_wait)
exten => 600,n,Dial(SIP/200,30)
exten => 600,n,Wait(1)
exten => 600,n,Playback(./custom/leave_a_message)
exten => 600,n,VoiceMail(240@voicemail)
exten => 600,n,Hangup()

extra: convert wav files to sln:

sox message.wav -t raw -r 8000 -s -2 -c 1 message.sln

1 Like

if SMS memory in dongle is full

to enter asterisk CLI:

asterisk -vvvvr

Clear SMS sim memory:

OpenWrt*CLI> dongle cmd dongle0 AT+CPMS=\"SM\",\"SM\",\"SM\" 
OpenWrt*CLI> dongle cmd dongle0 AT+CMGD=1,4

Clear SMS dongle memory:

OpenWrt*CLI> dongle cmd dongle0 AT+CPMS=\"ME\",\"ME\",\"ME\" 
OpenWrt*CLI> dongle cmd dongle0 AT+CMGD=1,4
1 Like