OpenWrt Forum Archive

Topic: [How To] Asterisk 11+GSM/SMS channel+Google Voice+OpenWRT SIP Client

The content of this topic has been archived between 25 Apr 2018 and 5 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Check also my previous How-to's:

[How To] Cheap Digital Stereo WiFi Internet Radio & MP3 Player:

[How To] Control a simple DIY relay board via internet Web page or SMS: … 91#p258891

[How To] Web SMS server with OpenWRT:


How To create a Voip gateway with OpenWrt Barrier_Breaker + Asterisk11
(don't use chaos calmer, it sucks, many asterisk 11 modules are missing!)


After reading and testing hundreds of incorrect and/or incomplete How-To's on this subject, I decided to create a serious one!

The Voip gateway has the following features:

SIP extensions (voip phones)
SIP channels (voip providers)
GSM channel (mobile phone line in/out)
SMS channel (mobile SMS in/out)
Voicemail (welcome audio messages + mini-sendmail to send recorded audio messages as mail attachements)

Hardware I used:
TP-Link TL-WR710n
Huawei e169 3G USB dongle
1 GB USB flash ext4 formatted (Overlay)
4 ports external powered USB Hub

Note: use only an external powered USB HUB (5V 1A or more), the Huawey dongle requires 0.5 A, the router itself is not capable of handling such a high current.

You can find my DEMO configuration files and other interesting stuffs @ my site: REMOVED  ( under /software/openwrt/)

in the DEMO configuration files I used Italian language setting (it,IT), you can change it to match your desidered language (ex. en,EN) by editing /etc/asterisk/ configuration files.

The audio sound files (many languages) are here: , untar and put them on '/var/lib/asterisk/sounds'.

---- [How to] --------------------------------------------------------------------

- External USB Overlay Instructions - OpenWrt Barrier Breaker - (single partition ext4 formatted USB Flash):

opkg update
opkg install kmod-usb-uhci
opkg install kmod-usb-ohci
opkg install kmod-usb2
opkg install kmod-usb-core kmod-usb-storage usbutils block-mount kmod-fs-ext4

Mount the filesystem:

mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1

Copy contents from /overlay to usb device:

tar -C /overlay -cvf - . | tar -C /mnt/sda1 -xf -

Generate fstab file:

block detect > /etc/config/fstab

Edit fstab file:

vi /etc/config/fstab

change the target to '/overlay'
change enabled option from '0' to '1'

Do not change UUID or other settings!

Reboot and check if everything is OK with the "df -kh" command:

root@OpenWrt:~# df -kh
Filesystem                Size      Used Available Use% Mounted on
rootfs                  802.4M    512.3M    232.5M  69% /
/dev/root                 2.3M      2.3M         0 100% /rom
tmpfs                    14.1M      1.4M     12.7M  10% /tmp
/dev/sda1               802.4M    512.3M    232.5M  69% /overlay
overlayfs:/overlay      802.4M    512.3M    232.5M  69% /
tmpfs                   512.0K         0    512.0K   0% /dev

Install the following packages:

opkg update
opkg install mini-sendmail

opkg install asterisk11 asterisk11-app-authenticate asterisk11-app-chanisavail asterisk11-app-chanspy asterisk11-app-directed_pickup asterisk11-app-disa asterisk11-app-exec

opkg install asterisk11-app-mixmonitor asterisk11-app-read asterisk11-app-readexten asterisk11-app-record asterisk11-app-sayunixtime asterisk11-app-senddtmf

opkg install asterisk11-app-sms asterisk11-app-stack asterisk11-app-system asterisk11-app-verbose asterisk11-app-waituntil asterisk11-app-while asterisk11-chan-dongle

opkg install asterisk11-codec-a-mu asterisk11-codec-alaw asterisk11-codec-gsm asterisk11-codec-resample asterisk11-curl asterisk11-format-gsm asterisk11-format-sln

opkg install asterisk11-format-wav asterisk11-format-wav-gsm asterisk11-func-blacklist asterisk11-func-channel asterisk11-func-cut asterisk11-func-devstate

opkg install asterisk11-func-extstate asterisk11-func-global asterisk11-func-groupcount asterisk11-func-shell asterisk11-func-uri asterisk11-pbx-spool asterisk11-res-agi

opkg install asterisk11-res-clioriginate asterisk11-res-xmpp asterisk11-sounds asterisk11-voicemail asterisk11-res-timing-timerfd

Download and copy (overwrite the existing files) the following DEMO configuration files on /etc/asterisk :

note: edit them with your own settings!

disable autostart of asterisk from init.d with the command:
/etc/init.d/asterisk disable

instead put the following lines in your "/etc/rc.local" file:

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
/bin/sleep 10
/etc/init.d/asterisk start
exit 0

note: to avoid problems asterisk has to be started only after the network is up and running (delay=10 seconds).

Internal DEMO extensions (see extensions.conf):

200: (rings for 20 seconds then hangs up if no answer)
user=200 - password=P@ssword

201: (goes to voicemail after 20 seconds if no answer)
user=201 - password=P@ssword

98: to manage voicemail from the phone

Note: you can change passwords by editing sip.conf and voicemail.conf


Command to get the Asterisk CLI:
asterisk -vvvr

useful asterisk CLI commands:

OpenWrt*CLI> voicemail show users
OpenWrt*CLI> sip show registry
OpenWrt*CLI> sip show peers
OpenWrt*CLI> dongle show devices

more to follow ... smile

(Last edited by pilovis on 13 Nov 2015, 13:24)

Excellent   I've been looking for a good Asterisk How-To.   I'm going to try this with a cordless SIP phone and Openwrt router in Spain

UPDATE 29/01/2015

If you experience audio scattering on SIP channel or on MOH (Music On Hold), install also res-timing-timerfd module:

opkg update
opkg install asterisk11-res-timing-timerfd

to enable timing-timerfd edit "/etc/asterisk/modules.conf" and add the following line:

load =>

IMPORTANT NOTE: do not enable res-timing-timerfd if you use chan_dongle

(Last edited by pilovis on 9 Jun 2015, 16:13)

Baresip Openwrt SIP client

Baresip it's a nice program but official documentation is hardly inexistent and sucks, like many small linux programs, as usual I had to figure out how to configure and use it.
How the hell do they create programs without writing a decent documentation?  mad  mad

- Prerequisites:

1) install Alsa and USB audio support
2) connect an USB audio adapter with a speaker and a microphone or a USB phone / headset (with microphone)
note: you might also use a USB webcam with internal microphone or just a USB microphone, in both cases you don't need an USB audio adapter but you won't have any speaker (one way audio)
3) adjust audio levels of speaker and microphone with command: alsamixer

note: see my other "How To" for detailed instructions how to configure USB audio: … 63#p225463

- Installation and configuration of Baresip on Barrier Breaker (Baresip doesn't work on Attitue Adjustment: broken audio!):

opkg update
opkg install kmod-usb-hid
opkg install kmod-hid kmod-hid-generic
opkg install baresip baresip-mod-alsa baresip-mod-cons baresip-mod-evdev baresip-mod-g711
opkg install baresip-mod-stdio baresip-mod-uuid

Launch baresip once to generate the default configuration files on /root/.baresip:


after a few seconds stop it with ctrl+c
then you need to edit the configuration files

cd /root/.baresip

first edit "accounts" file

delete everything and insert the following line (use the values of your SIP accont):


Note: you can add optional parameters to this line just by adding one or more of them with the following format:


list of optional URI params:

#    ;transport={udp,tcp,tls}

list of optional addr-params:

#    ;answermode={manual,early,auto}
#    ;audio_codecs=speex/16000,pcma,...
#    ;auth_user=username
#    ;mediaenc={srtp,srtp-mand,srtp-mandf,dtls_srtp,zrtp}
#    ;medianat={stun,turn,ice}
#    ;outbound=";transport=tcp"
#    ;
#    ;ptime={10,20,30,40,...}
#    ;regint=3600
#    ;regq=0.5
#    ;rtpkeep={zero,stun,dyna,rtcp}
#    ;sipnat={outbound}
#    ;stunserver=stun:[user:pass]@host[:port]


if you have installed Asterisk11 on the same router and you want to connect Baresip to local Asterisk, this is the account configuration example:

then edit  "config" file

delete everything and insert the following lines:

#comments added by pilovis
poll_method             epoll
input_device            /dev/input/event0                        #eventually adapt input device path for your system
input_port              5555
sip_trans_bsize         128
audio_player            alsa,default                                  # audio speaker device
audio_source            alsa,default                                 # audio microphone device
audio_alert             alsa,default                                   # audio ring device
# if you want to use more than one audio device you need to use: alsa,default:CARD=devicename
# to discover device name use command: aplay -L
# -----------------------------------------------------------
audio_srate             8000-48000
audio_channels          1-2
rtp_tos                 184
rtcp_enable             yes
rtcp_mux                no
#jitter_buffer_delay     15-35  # uncomment this line only in case you use an external voip provider and you experience high ping latence
rtp_stats               no
dns_server                                       # use your preferred DNS server
module_path             /usr/lib/baresip/modules
natbd_server    # I'm not sure this line is necessary when you set "stunserver" option on user account
                                                   # and/or for local accounts: <user:password@localhost>
natbd_interval          600             # same as above, you might try to comment "#" both lines and test if baresip works
# eof

Launch Baresip:


then press "?" for all available commands


- Baresip remote audio monitoring

Make an automatic SIP phone call with the following command:

(/bin/echo; /bin/sleep 60; /bin/echo q) | /usr/bin/baresip -f /root/.baresip -e d

Note: "sleep 60; echo q" set the total call duration time at 60 seconds including ring time, after that "quit" command is sent to baresip, even if the remote party has not answered the call yet.

When the remote party answers the phone, he/she hears the ambient audio captured from the local microphone, also if he/she talks, his/her voice is sent to the local speaker (if connected and active).


- Launch Baresip as a daemon and configure it to auto answer all incoming calls

first configure baresip for auto answer all incoming calls by editing the "/root/.baresip/accounts" file as the following:


then launch it as a daemon with the following command:

/usr/bin/baresip -f /root/.baresip -d

note: "-f /root/.baresip" tells Baresip where to find configuration file, "-d" sends Baresip to background as a daemon, to have a complete option list use "baresip --help".

then try to call your local sip account, baresip won't ring but will answer the call and will start streaming the local audio to you (remote caller), same as above, if you talk,  people near to the openwrt router will hear your voice through the speaker (speakerphone mode)

NOTE: if you use baresip as a daemon and you also want to issue an automatic call from local (openwrt) to remote (eg.: your mobile), you should change the previous auto call command to the following:

(/bin/echo; /bin/sleep 60; /bin/echo b) | /usr/bin/baresip -f /root/.baresip -e d

basically here we are sending "b" command (HANGUP CALL) to baresip instead of "q" (QUIT BARESIP) because we want to keep baresip running in background.

If you want to use a USB Voip phone or a USB headset but you want to have a separate speaker that rings for the incoming calls, you need an extra USB audio adapter for the speaker, alsa will recognize it with a different device name, then you just need to modifiy "config" file as the following:

audio_player            alsa,default:CARD=headset_devicename
audio_source            alsa,default:CARD=headset_devicename
audio_alert             alsa,default:CARD=other_devicename

note: to find the two device names launch command: aplay -L 

- USB Keypad

if you connect an USB numeric keypad to your router, you can use it to answer the incoming calls (Enter Key) and/or to dial phone numbers followed by "Enter" key to start the call.
To hangup/cancel the call press "Del" key.
Unfortunately the "#" key is not implemented, nor available with any shortcut sad

Note: if you want to use the keypad to accept incoming calls by pressing "Enter", you need to modify the account configuration file as the following:


If you use a USB Phone you don't need the USB audio adapter.

if you install "kmod-usb-cm109" you can use some (old) USB Voip phones with support of their integrated keys, like
KIP 1000, G-talk , Atcom au100, Allied-Telesis Corega USBPH01.

- To start Baresip at bootup but only after Asterisk has fully started, add the following lines to /etc/rc.local:

/bin/sleep 10
/etc/init.d/asterisk start
/bin/sleep 5
/usr/bin/baresip -f /root/.baresip -d &&

exit 0

Don't use /etc/init.d/baresip enable or start, cause is broken (config path missing) and will not start at bootup nor will launch baresip daemon mad mad

addendum 07/02/2015

If you want to control/monitor Baresip running as a backgroud daemon you need to enable console interface mode (UI console),

first edit Baresip "config" file and uncomment (remove "#") the following line under UI modules section:


then restart Baresip and you can telnet to 5555 port:

telnet baresip_IP 5555

you do not need to use any password to login.
Baresip_IP is the IP address of your router
h+return for help

Security: NEVER expose port 5555 of Baresip console to the Internet or outside of your private LAN!

UI console mode may also be usefull to control baresip daemon running in background, examples:

to quit baresip daemon:
echo q | telnet localhost 5555

to hangup a call:
echo b | telnet localhost 5555

(Last edited by pilovis on 9 Jun 2015, 16:14)

Google Voice configuration - Openwrt Asterisk 11

UPDATE 02/01/2016

Install missing packages:

opkg update
opkg install libsasl2 libssh libopenssl
opkg install asterisk11-chan-motif
opkg install asterisk11-res-xmpp

edit /etc/asterisk/motif.conf

delete everything and put the following lines:

context=from-internal ; Default context that incoming sessions will land in


edit /etc/asterisk/modules.conf

add the following line:

load =>

edit /etc/asterisk/xmpp.conf

delete everything and put the following lines:


statusmessage="I am available"

edit /etc/asterisk/extensions.conf

add the following lines:


exten => google,1,NoOp()
exten => google,2,Answer()
exten => google,3,SendDTMF(1)
exten => google,4,Set(crazygooglecid=${CALLERID(name)})
exten => google,5,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
exten => google,6,Set(CALLERID(all)=${stripcrazysuffix})
exten => google,7,Dial(SIP/200,20,D(:1))
exten => google,8,Hangup()


; outgoing Google Voice
exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN},,r)
exten => _+1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN},,r)

edit /etc/asterisk/rtp.conf

uncomment the following line:


edit /etc/asterisk/sip.conf

add the following lines under [general] section:


use yours values for the fields:
and SIP/extension (example: SIP/100)


Do not forget to enable "Access for less secure apps" from this page:

(you need to login to your Google account)

(Last edited by pilovis on 2 Jan 2016, 10:42)

Asterisk SMS2mail

Configuration to receive SMS from chan_dongle and forward them by email

opkg update
opkg install asterisk11-func-base64
opkg install mini-sendmail

Edit "etc/asterisk/extensions.conf"

add the following lines at the end of the file:


; SMS2email
exten => sms,1,Noop(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
exten => sms,2,System(echo 'From: ${CALLERID(num)} <>\nTo: <>\nSubject:Received SMS\nFrom: ${CALLERID(num)}\n${BASE64_DECODE(${SMS_BASE64})}' >> /var/log/asterisk/sms.txt)

exten => sms,3,System(/usr/sbin/mini_sendmail -p25 < /var/log/asterisk/sms.txt)
exten => sms,4,System(rm -f /var/log/asterisk/sms.txt)
exten => sms,5,Hangup()

(Last edited by pilovis on 31 Jan 2015, 16:24)

If you want to use your custom audio messages in Asterisk do the following.

- Install sox:

opkg update
opkg install sox

create custom directory:

mkdir /usr/lib/asterisk/sounds/custom

- Command to convert wav to sln for Asterisk (Openwrt needs 2 minutes or more to convert a file):

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

note: the source audio files to be converted should be recorded in wav 16 bit (Microsoft) PCM format.

then move converted file "message.sln" to /usr/lib/asterisk/sounds/custom.

- Example of extension.conf:
exten => s,n,Playback(./custom/message)

(Last edited by pilovis on 26 Mar 2015, 06:35)

Another interesting functionality to add to to our OpenWRT PBX:

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 asterisk11-app-chanspy

Also, you need at least "beep.ulaw" audio file in /usr/lib/asterisk/sounds directory.

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


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

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 <chanprefix>
(e.g. run ChanSpy(Agent) and dial 1234# while spying to jump to channel Agent/1234)

(Last edited by pilovis on 8 Feb 2015, 14:48)

Another nice one smile

Make a phone call to your router and execute a system (Linux shell) command inside OpenWRT

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

opkg update
opkg install asterisk11-app-system

example line for the diaplan:

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

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

(Last edited by pilovis on 4 Feb 2015, 15:59)

I've just discovered that Chan_dongle is broken on Asterisk 11 sad

When I wrote the first How-to I was using a Barrier Breaker (Ar71xx) snapshot and chan_dongle was working well, now I'm using Barrier Breaker final (BRCM63XX) + Asterisk 11 + chan_dongle and I have the following one way audio problem:

GSM -> Voip    is ok, clear audio;
Voip -> GSM    noise instead of channel audio

My system is , Vodafone Station - Huawei EchoLife HG553 - 64 Mbytes RAM + USB external Overlay, dongle connected through a powered HUB.

I tried to change codecs and enable or disable res_timing without any success.

I tested Huawei E169 & K3765, found same problem on both dongles.

This problem arose about a year ago, but up to now nobody seems to have taken care of this issue mad

UPDATE: go on reading this 3D, you'll find the solution for this problem.

(Last edited by pilovis on 9 Jun 2015, 16:18)


if you note that Baresip after some time loses registration and does not register anymore, try to change the registration configuration file as the following:


note: the above is a single line.

Instead, if asterisk is in on the same router, change the registration configuration file as the following:


Also, you can try to add to the (Baresip) user configuration of local Asterisk (/etc/asterisk/sip.conf ) the following lines:

nat=no # if Asterisk is on a remote server use nat=yes

(Last edited by pilovis on 16 Apr 2015, 16:14)

If forum have Thanks button, i will click 1000 times for your post. You have many good [How to].

hoatienii wrote:

If forum have Thanks button, i will click 1000 times for your post. You have many good [How to].

If coders had written “decent” documentations for their programs, my HOW-TOs wouldn’t be necessary wink
Maybe a day they'll learn that the documentation is as much important as the coding, a good program but with a lack of documentation becomes a bad program, hardly usable and consequently hardly used.

Thank you smile


(Last edited by pilovis on 5 Feb 2015, 21:25)

If you use Voip on your router I would suggest you to always enable QoS.

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

opkg update
opkg install luci-app-qos

then add the following two rules to the luci Network>QoS configuration page:

first rule)

target = priority
source host =all
Destination host = all
Service = all
Protocol = all
Ports = 5060,5061,5222
Number of bytes: leave it empty
Comment = SIP and Google Voice

second rule)

target = priority
source host =all
Destination host = all
Service = all
Protocol = all
Ports = 10000:20000
Number of bytes: leave it empty
Comment = Asterisk RTP stream

Leave other default rules as they are, insert just your download and upload internet connection speed (be conservative -10%).

Save & Apply, then reboot.

(Last edited by pilovis on 4 Feb 2015, 15:06)

Some useful infos:

Asterisk needs minimum 30 Mbytes of ram to run smoothly on OpenWRT,
Baresip needs about 16 Mbytes, (total 46 Mbytes for both)
Asterisk uses from 8 to 20% of CPU power (@ 300 Mhz),
Baresip uses from 10 to 20% of CPU
Asterisk launches multiple concurrent istances (PIDs), about 25!
Baresip launches one istance when idle, up to three istances when in a call.

Each "g711u/a codec" SIP channel needs 128 kbit/s (up/down) bandwidth to work smootly, 80 Kbit/s is the minimum.
Each "g729 codec" SIP channel (if available) needs 48 Kbit/s bandwidth to work smootly, 32kbit/s is the minimum.

Do not expect asterisk to handle more than one or two concurrent calls on OpenWRT wink

To monitor CPU and ram usage, install htop

opkg install htop

(Last edited by pilovis on 4 Feb 2015, 16:06)

I run without baresip, only asterisk 11 with extroot and swap on sd card, 3 concurrent calls are fine from CPU usage perspective.
21 sip peer registered

tp-link wr710n EU

I plan to go for WT3020 soon to get rid of swap on sd card.

(Last edited by gently on 4 Feb 2015, 16:32)

gently wrote:

I run without baresip, only asterisk 11 with extroot and swap on sd card, 3 concurrent calls are fine from CPU usage perspective.
21 sip peer registered

tp-link wr710n EU

I plan to go for WT3020 soon to get rid of swap on sd card.

Tp-link TL-WR710n EU is a very good router to run OpenWRT and Asterisk but it has only 32 Mbytes of ram, swap might help a lot but Flash memories have limited lifetime due to writing/erase wear-out problem.
A solution could be to connect an USB2Sata adapter and use a real Hard Disk with Extroot and Swap on it.

In your case I would suggest you to use two different SD cards, one for extroot and the other for Swap, if the Swap SD becomes unusable due to wear-out, you just need to put in a new one, swap formatted, eventually adjust fstab and reboot the router.
Otherwise with just one SD card you may lose the entire filesystem.

Note that also internal router flash memory suffers from wear-out problem, but if you have extroot, your internal flash is completely safe because you won't never write anything to it wink , except in case you reflash Openwrt too many times to your router.
In the past I permanently damaged two Fonera routers just by reflashing them 5 or 6 times!

Keep in mind that any process, like "logging", that writes too frequently to the router internal flash memory, may reduce lifespan of it, log services that write too much should be disabled after the set-up of the router has been completed.

(Last edited by pilovis on 4 Feb 2015, 18:41)

thanks for the hint about lifetime of the sticks, you are correct, that is why I want to upgrade to WT3020 and avoid using swap.

for disaster recovery I have a $15/year VPS server on the Internet smile

why chan_donge is sucks?

it works flawlessly for me

The chan_dongle doesn't work on Barrier Breaker nor on Chaos Calmer for BCM63xx, one way audio, no matter what dongle you use (I tested E169 and K3765 Huawei dongles).

(Last edited by pilovis on 8 Feb 2015, 14:50)

Can you linksys pap2 for this [how to]? If ok, i will buy this

(Last edited by hoatienii on 9 Feb 2015, 04:59)

My last message of this [How To] is to warn you about the reliability of Asterisk with Baresip on OpenWRT.
I do not want to delude you, but do not expect a very reliable and stable system, Baresip easily lost the SIP registration and when this happens, it usually does not reconnect again, you need to reboot the router or kill the process and restart it.
Also, the audio quality of Baresip with OpenWRT is very bad compared to other SIP clients using the same codecs.

If you have an old unused router, it is ok to play with it and OpenWRT Voip, but do not waste money to buy a new router to make a PBX on it, if you want a reliable PBX, use Raspberry (same cost of a router), or better, an old PC/laptop with a full linux distro.

(Last edited by pilovis on 16 Feb 2015, 14:30)

please blame baresip only smile

uptime of my asterisk was 250 days, ~2000 calls (not much, home use). no issues at all!

You might be right, onestly I didn't test Asterisk alone without Baresip, maybe Baresip is causing Asterisk to unregister so frequently.

I'm trying to use chan_dongle on Barrier Breaker, my chipset’s router is AR71xx so I hope the one way issue is not present… but I have some doubts.

My dongle is Huawei E180. Voice is enable. And I’m using a powered USB Hub.

At time this time, I’m having two issues with outgoing calls (incoming not tested yet):

-    The dongle stuck on Dialing state each time I want to make a call… until a dongle reset
-    I can hear from the GSM => VoIP (even if the dongle is in the Dialing state), but not in the other side

Any idea to help me?