[how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_dongle

sezione dedicata ai sistemi operativi alternativi Open Source

[how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_dongle

Messaggio da leggereda root » 30/12/2014, 23:18

Check also my previous How-to's:

[How To] Cheap Digital Stereo WiFi Internet Radio & MP3 Player:
(https://forum.openwrt.org/viewtopic.php?id=49013)

and
[How To] Control a simple DIY relay board via internet Web page or SMS:
https://forum.openwrt.org/viewtopic.php?pid=258891#p258891

and
[How To] Web SMS server with OpenWRT:
https://forum.openwrt.org/viewtopic.php?id=60910

------------------------------------------------------

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/)

notes:
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: http://downloads.asterisk.org/pub/telephony/sounds/ , 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 :
REMOVED

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
password=1234

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 ... :)

Immagine
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: Openwrt + Asterisk11 + GSM/SMS channel (chan_dongle)

Messaggio da leggereda root » 29/01/2015, 13:08

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? :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: https://forum.openwrt.org/viewtopic.php?pid=225463#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.voip.eutelia.it


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.voip.eutelia.it

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 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 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.voip.eutelia.it

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 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.
Unfortunately the "#" key is not implemented, nor available with any shortcut :(

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

Immagine

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

Immagine

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.

Immagine ImmagineImmagine

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 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:

#module cons.so

then restart Baresip and you can telnet to 5555 port:

telnet baresip_IP 5555

note:
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
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: Openwrt + Asterisk11 + GSM/SMS channel (chan_dongle)

Messaggio da leggereda root » 30/01/2015, 1:41

Google Voice configuration - Openwrt Asterisk 11

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:

[default](!)
disallow=all
allow=ulaw
context=from-internal ; Default context that incoming sessions will land in


[google]
context=incoming-motif
disallow=all
allow=ulaw
connection=google

edit /etc/asterisk/modules.conf

add the following line:

load => chan_motif.so

edit /etc/asterisk/xmpp.conf

delete everything and put the following lines:

[general]

[google]
type=client
serverhost=talk.google.com
username=you@gmail.com
secret=yourpassword
priority=25
port=5222
usetls=yes
usesasl=yes
status=available
statusmessage="I am available"
timeout=5


edit /etc/asterisk/extensions.conf

add the following lines:

[incoming-motif]

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()



[from-internal]

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

edit /etc/asterisk/rtp.conf

uncomment the following line:

icesupport=true


edit /etc/asterisk/sip.conf

add the following lines under [general] section:

tcpbindaddr=0.0.0.0
tcpenable=yes



Note:
use yours values for the fields:
you@gmail.com
yourpassword
and SIP/extension (example: SIP/100)
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: Openwrt + Asterisk11 + GSM/SMS channel (chan_dongle)

Messaggio da leggereda root » 31/01/2015, 3:38

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:

[from-pstn]

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

exten => sms,3,System(/usr/sbin/mini_sendmail -fsms-openwrt@domain.com -ssmtp.mail.com -p25 myself@mail.com < /var/log/asterisk/sms.txt)
exten => sms,4,System(rm -f /var/log/asterisk/sms.txt)
exten => sms,5,Hangup()
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 02/02/2015, 22:09

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)
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 02/02/2015, 22:09

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":

[from-internal]

;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)
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 02/02/2015, 22:10

Another nice one :)

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 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
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 05/02/2015, 23:20

This is the final device:

WiFi and LAN connections
Asterisk 11 SIP/Google Voice + local SIP client
1+1 FXO/FXS analog RJ11 ports
1 analog RJ11 GSM gateway (because chan_dongle on openwrt sucks)
1 external ring device (speaker)
1 USB keypad to control local SIP client
1 USB phone connected to local SIP client (just audio, no embedded keys support)
1 PSTN cordless analog phone (not shown)

- Keypad:
I/O keys control relay output (led lighting on-off controlled by OpenWRT)
M/S keys control music streaming Start and Stop ( :D almost useless gadget to listen to internet radio stations on the phone - using madplay and triggerhappy)
L key is for Line out
Enter key accepts incoming calls
Del key Hangs Up a call
0-9 and * keys are for numbers dialing and DTMF tones when in a call
# key is missing :(

Note: when a call gets in, the led light switches on

P.S.: all components I used are old recovered TRASHWARE :D

Immagine
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 08/02/2015, 0:45

Addendum:

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:

<sip:user:password@sip-provider.com:port;transport=udp>;answermode=manual;regint=120;rtpkeep=stun;stunserver=stun:stun.voip.eutelia.it

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

<sip:user:password@localhost>;answermode=manual

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

qualify=yes
nat=no # if Asterisk is on a remote server use nat=yes
insecure=invite,port
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Re: [how to] Openwrt + Asterisk 11 + GSM/SMS channel chan_do

Messaggio da leggereda root » 08/02/2015, 0:46

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.
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 347
Iscritto il: 10/04/2012, 10:55
Località: Ovada

Prossimo

Torna a OpenWRT e sistemi operativi vari

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron