TUTORIAL chan_mobile and Bluetooth with PIAF: Reliable!

Derick

New Member
Joined
Nov 14, 2013
Messages
4
Reaction score
7
Hello folks.

I know or should I say I think or rather I guess that many people struggle with getting chan_mobile to work - reliable. I have been using chan_mobile with PIAF, in a business setting for about 2 years now WITHOUT any issues. I do recall that I've been struggling a lot at that time when I was working hard to get everything working and running smoothly. And because it was such a pitty to just get everything paired up and working, I've made notes, and I've saved them (this time).

I've decided to set up a new "PBX" for a home business environment, and I am so glad that I've saved the notes I've made - way back.

So this is MY setup - please note that it might be wrong - I am no professional, nor am I a PIAF super-user. This is just MY contribution, to the PIAF family - in hopes that I might just help someone.

MY SETUP
  • BLUETOOTH DONGLES (I use 4)
    Bluetooth dongle - I use IOGEAR USB 2.1 Bluetooth Micro Adapter (GBU421)
    NOTE: I've also purchased the IOGEAR Bluetooth 4.0 USB Micro Adapter (GBU521) - I have never got it working. I dod not spend lots of time trying. It doesn't work for me. I have tried cheaper dongles - IT DOESNT WORK either. The ones which seemed to work simply is not reliable
  • PHONES
    I've tried cheap Motorola handsets - the ones which worked, had bad voice quality. I've also tried cheap Motorola phones and I've also experienced bad voice quality - compared to:
    Samsung GT-S5300 and any Nokia phone. The nokia phones work fast and everytime. Very very reliable. I can say the same for the Samsung ones too (I guess I can say this for all android phones? The Samsung ones were the only ones with Android which I have tried and used). But really, I've tried a Nokia C5-00, Nokia 6210, Nokia 6310i and a couple of other Nokia's - and they simply just work.
  • PC / Computer Hardware
    I guess this wont really make a difference, but I'm running Pentium 4, 160GB hard drive, 1.5GB RAM
There are many posts on the internet showing you how to make chan_mobile work, but I'll outline how I got it working, and focus more on the issues I've experienced and the work-arounds / tips.
Before you start, make sure you have a solid PIAF system running. My most recent installation is PIAF 2.0.6.5.
Secondly, make sure that you have chan_mobile in your /usr/lib/asterisk/modules/ directory. If you dont know how to check this - then simply do this. When you're logged in via SSH, simply type

Code:
cd /usr/lib/asterisk/modules/
ls
This will give you a list of all modules.
Then, a couple of tips, or should I call it things-to-do in order to ensure that everything will be working as expected? Remember I might be wrong! But this is what is working for me.
  • Many, MANY posts instruct the reader to edit / modify the /etc/bluetooth/hcid.conf file - I have never been able to find this file! So just forget about it.
  • Bluetooth - make sure you can start bluetooth and stop bluetooth by typing
    Code:
    service bluetooth start
    and
    Code:
    service bluetooth stop
  • In order to ensure that the bluetooth service starts automatically on boot, issue the command
    Code:
    nano /etc/rc.local
    to edit the file whch you can use to initiate commands on boot / startup - and add the following line, IF it is not already there -
    Code:
    /etc/init.d/bluetooth start
Once you're set - do the following
Edit the file /etc/asterisk/chan_mobile.conf
You will notice that there are sample setup / configurations already. In short - the [adapter] config is your bluetooth adapter, and the [6310i] or sections below the "adapter" config - are your phones and headsets.
So the layout for the adapter should look similar to this
Code:
[adapter]
id=hci1
address=AA:AA:AA:AA:AA:AA

Explanation:
[adapter] // leave this as it is
id=hci1 // this is IMPORTANT and must be unique - this is the reference name for your bluetooth adapter
address=AA:AA:AA:AA:AA:AA // this is the MAC address of your adapter
The layout for the PHONE should look similar to this

Code:
[6310i]
address=AA:AA:AA:AA:AA:AA
port=13
context=incoming-mobile
adapter=hci1

[6310i] // name of your phone or whatever you want to type
address=AA:AA:AA:AA:AA:AA // MAC address of your phone's bluetooth adapter
port=13 // bluetooth port
context=incoming-mobile // unique contect name -> this is IMPORTANT for incoming calls
adapter=hci1 // adapter refernce name - i.e. tells WHICH adapter to use
Now - you will probably not have the required information (such as the port number etc) as yet - however I do want you to look at the file first, before proceeding with the following commands. So close the file now, and get the required information.
I'll assume your bluetooth service is now running
issue the shell command

Code:
hcitool dev

This will list all your bluetooth adapters. If you dont see anything similar to the following, then you have an issue with your ADAPTER. The chan_mobile settings is NOT related if you DONT see your adapter here.
You should see something like this. I'll list one adapter only.
Code:
Devices:
        hci0    AA:AA:AA:AA:AA:AA

Then in order to get the MAC address of the phone,

Code:
hcitool scan

Take note of the MAC address

Issue the command
Code:
asterisk -rvvvvvvvv
Once there, you HAVE to ensure that your chan_mobile.so module is running. Issue the following command to ensure that it is running
Code:
module load chan_mobile.so
Once there and if you didnt receive any errors when laoding this module, issue the following command
Code:
mobile search
Allow a couple of seconds for the adapter to search. Also its probably obvious that your phone's bluetooth should be on and discoverable at this stage, right? Good.
Once you see results, you will notice a port number next to the device listing. Remember thsi port number.
Stop the chan_mobile.so module
Code:
module unload chan_mobile.so
Press CTRL+C keys.
Issue the command
Code:
hcitool scan
And take note of the MAC address of the relevant PHONE
Edit your chan_mobile.conf file in your favorite editor or
Code:
nano /etc/asterisk/chan_mobile.conf
Enter the correct information.
REMEMBER:

Code:
[adapter]
id=hci1  --> replace hci1 with your OWN UNIQUE name or reference for this adapter
address=AA:AA:AA:AA:AA:AA  --> MAC address of your ADAPTER
Code:
[6310i]
address=AA:AA:AA:AA:AA:AA  --> MAC address of your phone
port=13  --> This is the port number you've got when you did the mobile search command
context=incoming-mobile  ->> this is IMPORTANT for incoming calls - see the explanation later
adapter=hci1  --> this must match your unique adapter reference
REMEMBER: According to what I understand - you can only use ONE phone per ONE adapter. So dont use the unique reference ID of the adapter for more than one phone, okay?
Save the file and exit. Dont load the chan_mobile.so module as yet.
Now paring.
Do the following.
Code:
cd /root
wget http://www.stocksy.co.uk/files/asterisk/simple-agent.py
chmod +x simple-agent.py
Then issue the command - but VERY VERY important
  • replace "hci0" with YOUR bluetooth adapter (you get this ID from the command "hctitool dev")
  • replace AA:AA:AA:AA:AA:AA with the MAC address of YOUR phone
Code:
/root/simple-agent.py hci0 AA:AA:AA:AA:AA:AA
STOP AND READ THIS:
This is the pairing part. You are busy with it now. I've experience many issues here.
With the Samsungs - it only asked if the pair key matched, and I said YES, and it paired. Witht he motorola, - geeee I cant even remember. But similar heavy issues. If you didnt experience issues, or dont experience issues, then I'm glad for you.
Load the chan_mobile.so module
Code:
 asterisk -rvvvvvvvvvvvv
module load chan_mobile.so
If you have paired successfully, you can validate this by:

Code:
 mobile show devices
You should see something similar to this

Code:
ID              Address          Group Adapter        Connected State      SMS
c5              XX:XX:XX:XX:XX:XX 0    hci0            [B]Yes[/B]      Free      No
With the Nokia's , it asked for a pair key. It doesnt give one. The pair key is 4567
I ope you're phone paired sccessfully. Remember to go into your phone's paired devices and AUTHENTICATE the newly paired device, otherwise it will ask you to authenticte the connection everytime your server wants to pair with your phone.
IF YOUR PHONE DID NOT PAIR OR IF YOU RECEIVED ERRORS - then I cant tell you what to do. HOWEVER, what I can suggest is, in order to keep your attempts fresh and clean and not flooded with probable or possible code snippets or attempts, delete your adapters profile by doing this:
Unload / stop the chan_mobile.so module as explained before and go to your basic command line
Code:
cd /var/lib/bluetooth/
then
Code:
ls
to list all the files / directories
go into the directory of the proffered ADAPTER and delete all files inside. Once done, delete the directory itself. Once don, plug out the relevant bluetooth adapter, put it back, and start the pairing process again.
As an example:
Code:
# cd /var/lib/bluetooth/
# cd XX:XX:XX:XX:XX:XX
# rm classes config did eir features lastseen lastused linkkeys manufacturers names profiles sdp
# cd ../
# rmdir XX:XX:XX:XX:XX:XX

This way you can be sure that the files / settings / profiles / linkkeys are deleted and you can restart the pairing process

Okay - I'll assume you have successfully paired.

You can test it by issuing the command amportal restart - when asterisk then restarts, your phone will automatically disconnect and then reconnect

IMPORTANT NOTE: If your phone connects and disconnects all of the time - then your PORT set in chan_mobile.conf is probably wrong.

-> I can not post more than 10000 characters - see the rest of the tutorial in the comments:
 

Derick

New Member
Joined
Nov 14, 2013
Messages
4
Reaction score
7
CONTINUING....

INCOMING AND OUTGOING CALLS

The following is just a guideline - use and change it as you please.

For OUTGOING CALLS, create a CUSTOM trunk from the FREEPBX interface (connectivity -> trunks -> add custom trunk)

Give the trunk a name, and at the "Custom Dial String" enter
Code:
Mobile/phone-profile-name-here/$OUTNUM$
replacing "phone-profile-name-here" with the name in [] brackets specified in the /etc/asterisk/chan_mobile.conf file

Once you've dont that, create an outbound rule as you would do with any outbound trunk, and test an outgoing call - it should now work.

For INCOMING CALLS, edit /etc/asterisk/extensions_custom.conf

At the bottom of the file, paste the following. Note that this is a brief example, you can build / edit it for your own dialplan

Code:
[incoming-mobile]
exten => s,1,Noop(Entering macro-from-mobile-custom-1 with DID = ${DID} and setting to: 0123456789)
exten => s,n,Set(__FROM_DID=0123456789)
exten => s,n,Goto(from-trunk,0123456789,1)

IMPORTANT
The "incoming-mobile" between the [] brackets above, must be replaced with the exact "context" of your phone, as defined in your "chan_mobile.conf file - I'll paste the sample configuration of the file below, for incase you're lost.

Code:
[6310i]
address=AA:AA:AA:AA:AA:AA
port=13
context=incoming-mobile
adapter=hci1

Replace the "0123456789" with the DID number you want to specify. This can be anything.

Once you've done that, create an INBOUND ROUTE in FreePBX using the DID set here.

Note: if everything is paired up and if you run asterisk -rvvvvvvv and place an incoming call to your mobile device, and you get a similar error to this:

Code:
 pbx.c:6640 __ast_pbx_run: Channel 'Mobile/idhere' sent to invalid extension but no invalid handler: context,exten,priority=incoming-mobile,s,1

then the incoming configuration set is wrong. Make sure that the "context" field in chan_mobile.conf matches the inbound route set in etc/asterisk/extensions_custom.conf

After that - you're done!! Remember to restart or reload or even just amportal restart.

Everything should work. I'll be please te get some feedback to know whether this post helped you or not.

Take care!!
 

Derick

New Member
Joined
Nov 14, 2013
Messages
4
Reaction score
7
I've found the following post useful

Code:
https://wiki.debian.org/BluetoothUser
 

Axel Fernandez

New Member
Joined
May 25, 2013
Messages
4
Reaction score
1
Thanks! Its a great post

Do you have any solution to send sms through that paired phone?

Thanks
 

safa0786

New Member
Joined
Mar 4, 2012
Messages
11
Reaction score
1
Thanks! Its a great post
But with New PBXinFlash Centos 7 keep giving Python 2.7 error when .we run /simple-agent.py.
Error :-
Traceback (most recent call last):
File "./simple-agent.py", line 86, in <module>
path = manager.DefaultAdapter()
File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 70, in __call__
return self._proxy_method(*args, **keywords)
File "/usr/lib64/python2.7/site-packages/dbus/proxies.py", line 145, in __call__
**keywords)
File "/usr/lib64/python2.7/site-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method "DefaultAdapter" with signature "" on interface "org.bluez.Manager" doesn't exist
 

Members online

Forum statistics

Threads
25,810
Messages
167,755
Members
19,240
Latest member
nikko
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top