Asterisk 1.8 with chan mobile on CentOS 6

From Wiki
Jump to: navigation, search

Assumptions

  • The system is Intel i686 or amd64 architecture with a fresh install of CentOS 6.
  • The system has network access to enable retrieval of RPM packages from the CentOS repositories.
  • root level access to the system is available.

Installation

All of the following packages are required:

# yum install kernel-devel bluez bluez-libs usbutils pygobject2 dbus-python

Retrieve and untar the Asterisk 1.8 source to /usr/src/:

# cd /usr/src
# wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-1.8-current.tar.gz ; tar xf asterisk-1.8-current.tar.gz

Use menuselect to enable chan_mobile:

# cd asterisk-1.8*
# ./configure && make menuselect

Compile and install Asterisk:

# make
# service asterisk stop ; make install ; service asterisk start

Verify that Asterisk is running.

# rasterisk

Bluetooth Pairing

Plug in the bluetooth adapters you wish to use. Restart the bluetooth system:

# service bluetooth restart

Use hcitool to confirm that the adapters are detected OK:

# hcitool dev
Devices:
	hci0	00:00:00:00:00:00
	hci1	11:11:11:11:11:11

Make a note of the bluetooth IDs of each adapter. If no adapters are visible, try:

# hciconfig hci0 up
# hciconfig hci1 up

...and so on.

Set the phone you wish to use to be discoverable. Use hcitool to scan for the device:

# hcitool scan
Scanning ...
	AA:AA:AA:AA:AA:AA	Test-phone
	BB:BB:BB:BB:BB:BB	Vodafone 340

Make a note of the bluetooth address.

Because the CLI Bluetooth agents for pairing are absent from the CentOS package, it's necessary to use our own:

# cd /root
# wget http://www.stocksy.co.uk/files/asterisk/simple-agent.py
# chmod +x simple-agent.py

Now, pair each device in turn using the simple-agent:

# /root/simple-agent.py hci0 AA:AA:AA:AA:AA:AA

You'll be prompted to enter a PIN:

RequestPinCode (/org/bluez/22380/hci1/dev_AA_AA_AA_AA_AA_AA)
Enter PIN Code: 4567
Release
New device (/org/bluez/22380/hci1/dev_AA_AA_AA_AA_AA_AA)

Repeat with each device you wish to pair, using a different USB adapter for each device:

# /root/simple-agent.py hci1 BB:BB:BB:BB:BB:BB

Asterisk Configuration

Asterisk must first be started with just the adapters configured, no phones. This is so that there is a spare adapter available to scan the devices and determine which channel needs to be used. Create the following /etc/asterisk/chan_mobile.conf:

# vi /etc/asterisk/chan_mobile.conf

[Adapter]
; Substitute ID of hci0 here
address = 00:00:00:00:00:00
id = box1-0

[Adapter]
; Substitute ID of hci1 here
address = 11:11:11:11:11:11
id = box1-1

Now load chan_mobile:

# rasterisk
> module load chan_mobile

  Loaded chan_mobile.so
  == Parsing '/etc/asterisk/chan_mobile.conf':   == Found
  == Registered channel type 'Mobile' (Bluetooth Mobile Device Channel Driver)
  == Registered application 'MobileStatus'
  == Registered application 'MobileSendSMS'
 Loaded chan_mobile.so => (Bluetooth Mobile Device Channel Driver)

Scan for your devices:

> mobile search
Address           Name                           Usable Type    Port
11:11:11:11:11:11 Test-phone                     Yes    Phone   13
22:22:22:22:22:22 vodafone-340                   Yes    Phone    2

Note the port number used by each phone.

Unload chan_mobile and exit the Asterisk console. Ignore the error message, it doesn't appear to be significant:

> module unload chan_mobile
Unloaded chan_mobile
  == Unregistered channel type 'Mobile'
  == Unregistered application 'MobileStatus'
  == Unregistered application 'MobileSendSMS'
[Jun  6 09:37:24] ERROR[22434]: chan_mobile.c:4102 do_sco_listen: ast_io_wait() failed for audio on adapter box1-0

Now, edit chan_mobile.conf and assign each phone to an adapter.

# vi /etc/asterisk/chan_mobile.conf

[Adapter]
address = AA:AA:AA:AA:AA:AA
id = box1-0

[Adapter]
address = BB:BB:BB:BB:BB:BB
id = box1-1

[test-phone]
address = 11:11:11:11:11:11
port = 13
context = from-test-phone
adapter = box1-0

[vodafone-340]
address = 22:22:22:22:22:22
port = 2
context = from-test-phone
adapter = box1-1

Load chan_mobile again and everything should pair up:

# rasterisk
> module load chan_mobile
> mobile show devices

ID              Address           Group Adapter         Connected State      SMS
test-phone      11:11:11:11:11:11 0     box1-0          Yes       Free       No 
vodafone-340    22:22:22:22:22:22 0     box1-1          Yes       Free       Yes

Incoming calls are sent to the from-test-phone context. Create this context in extensions.conf and reload the dial plan:

# vi /etc/asterisk/extensions.conf

[from-test-phone]
exten => s,1,Answer()
exten => s,n,Wait(1)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Playback(tt-weasels)
exten => s,n,Hangup

Calling any connected device will now result in hearing the tt-weasels announcement.

Outgoing calls can be placed using a simple script to generate call files:

# cd /root
# vi place-call.sh

#!/bin/sh
cp /root/place-call.conf /tmp/place-call.call
### Only needed if Asterisk not running as root
###chown asterisk:asterisk /tmp/place-call.call
mv /tmp/place-call.call /var/spool/asterisk/outgoing/
exit

# chmod +x place-call.sh
# vi place-call.conf

; Channel - where to send the call
channel: Mobile/test-phone/07789322122
; Context - where to execute applications from
context: from-test-phone 
; Extension - the extension to which the called party is connected
extension: s 
; WaitTime - how many seconds to wait for an answer before giving up
waittime: 120
; MaxRetries - how many times to try again if first attempt fails
maxretries: 2
; RetryTime - Time to wait before retrying
retrytime: 120
; Archive - retain call file after either a success or failure
archive: no

Run the script:

# /root/place-call.sh