Baresip Openwrt SIP client
Baresip it's a good 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?
- 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: https://forum.openwrt.org/viewtopic.php … 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:
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):
<sip:user:password@sip-provider.com:port>;stunserver=stun:stun.ekiga.net
Note: you can add optional parameters to this line just by adding one or more of them with the following format:
<sip:user:password@domain;uri-params>;addr-params
example:
<sip:user:password@sip-provider.com:5060;transport=udp>;answermode=auto;stunserver=stun:stun.ekiga.net
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="sip:primary.example.com;transport=tcp"
# ;outbound2=sip:secondary.example.com
# ;ptime={10,20,30,40,...}
# ;regint=3600
# ;regq=0.5
# ;rtpkeep={zero,stun,dyna,rtcp}
# ;sipnat={outbound}
# ;stunserver=stun:[user:pass]@host[:port]
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 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 8.8.8.8:53 # use your preferred DNS server
module_path /usr/lib/baresip/modules
module stdio.so
module evdev.so
module g711.so
module alsa.so
module stun.so
module turn.so
module_tmp account.so
module_app contact.so
module_app menu.so
natbd_server creytiv.com # 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:
baresip
then press "?" for all available commands
-------------------------------------------------------------------------------------
- Baresip remote audio monitoring
Make an automatic SIP phone call with the following command:
(/bin/echo sip:other-user@voip-provider.com; /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:
<sip:user:password@sip-provider.com:5060;transport=udp>;answermode=auto;stunserver=stun:stun.ekiga.net
then launch it as a daemon with the following command:
/usr/bin/baresip -f /root/.baresip -d
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 sip:other-user@voip-provider.com; /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.
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:
<sip:user:password@sip-provider.com:5060;transport=udp>;answermode=manual
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, same for "kmod-usb-yealink" that support Yealing Voip phones.
NOTE:
if you have installed Asterisk11 on the same router and you want to connect Baresip to local Asterisk, this is the account configuration example:
<sip:user:password@localhost>;answermode=manual
- To start Baresip at bootup but only after Asterisk has fully started, add the following line to /etc/rc.local:
/bin/sleep 10
/etc/init.d/asterisk start
/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
(Last edited by pilovis on 31 Jan 2015, 16:11)