We figured we would share this information with our readers incase they were interested in Bluetooth for Asterisk and the capabilities it will open up to their system. Just think, the server will know when you’re in the room or out of the office and other fancy things.
First you should make sure that your Bluetooth Dongle works with Asterisk, and that your Cellular Phone is known to work with Asterisk and Bluetooth. You can verify all this information over at the Voip-Info Chan_Mobile page.
- Asterisk PBX
- Bluetooth Support (Motherboard or Dongle)
- Cellular Phone with Bluetooth support
- Bluez Bluetooth Libraries and Development Headers
So, first we have to install some pre-requisite software. We’ll assume that you already have Linux installed, your kernel is compiled, Asterisk is installed and working, and that you have a basic familiarity with Linux commands. We’ve written this tutorial for Ubuntu, using FreePBX so instructions may change based on your OS or Asterisk Configuration GUI.
So, lets get down to business shall we.
First, install Bluez Utilities on your Server
# apt-get install bluez-utils bluez-hcidump
Now Configure Bluez to work with your server and dongle. We won’t go into depth on this as it mostly “just works” but there are ample tutorials and documentation if your dongle is a little finiky on your system.
Now, open up the file hcid.conf in the Bluetooth configuration directory, and match the contents to the following.
# nano /etc/bluetooth/hcid.conf
Erase the contents, and replace it with this
# HCId options
name “Our PBX System”;
iscan enable; pscan enable;
Note you can also experiment with making Asterisk a handsfree headset, but we won’t go over this in this tutorial. The following lines can be added to your hcid.conf in replacement of the “Our PBX System” device mentioned above if you want to try this:
Now that our bluetooth is configured, we can go back to configuring Asterisk to work with Chan Mobile for Bluetooth Support. We’ll assume you already have Asterisk 1.6 running on your machine for this to work. If not, compile it and instal it!
Now, Enter the directory with your Asterisk-Addons 1.6 source.
# cd /opt/asterisk/asterisk-addons-1.6.0/
Issue your configure line
# make distclean
# ./configure –with-bluetooth
Now, issue the configure menu tree
# make menuselect
Now, on the left hand side, hit the down arrow button until you get to the Channel Drivers section. On the right hand side, you should see “chan_mobile” with a little “*” next to it telling us it’s enabled.
If you don’t, pretty right on your arrow keys, and then press the enter key to select chan_mobile. Exit the configuration menu by pressing F12 to save your changes.
Now, build Asterisk-Addons 1.6 as you normally would
# make install
This will place chan_mobile.so into /usr/lib/asterisk/modules so the next time you start Asterisk it will be available.
We’re pretty much done the “difficult” stuff now, and just need to go on and start bluetooth on our system and then configure Asterisk to work with it.
So, start up bluetooth
# /etc/init.d/bluetooth start
Now, lets make sure that Bluetooth is running and sees our devices
# hcitool dev
This should output some information like this:
Make a note of the “hardware” address in a text file or somewhere handy because we will need it later. The hardware address is the one that looks like a MAC address. In this case it’s “00:50:B6:80:34:DD” note that your system will be different.
Now, lets edit Asterisk’s mobile configuration file
# nano /etc/asterisk/mobile.conf
Add your Bluetooth Adapter to the file like this, using the Hardware ID from the hcitool command you ran above. There should already be an entry that looks similar to this (with an id=blue) just replace the hardware ID in this entry with yours.
Now exit and save the file.
Before we forget, we should add bluetooth to the startup options of the server if it’s not already there. Do so like this;
# update-rc.d bluetooth defaults
Now, in order for other devices to be able to see your server and vice-versa we have to make it discoverable. That’s done with the following command.
# dbus-send –system –type=method_call –print-reply –dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.SetMode string:discoverable
The fun begins right about now. Go and get your mobile phone. Turn bluetooth on on the phone. You should see your Asterisk PBX in the list of discoverable devices. Double click on it to add it to your device, and input the security key of 1234 when prompted.
Note that on our windows mobile 6.1 devices, after adding the Asterisk PBX to our bluetooth list, we also had to click on it and then hit refresh services list a few times until it showed us “Bluetooth Headset” as a list of supported options. We selected it on the screen, and closed the bluetooth configuration on our HTC Tytn II (Kaiser) test devices.
Now it’s time to make your phone discoverable so the PBX can attach to it. Go back to your phone, and find the option to enable bluetooth discovery. Turn it on.
Now from the Asterisk Server Command Line we should be able to issue this command to search for our Bluetooth Mobile Phone.
# hcitool scan
It should show you a list of results like this
In our example, we’ll only be connecting to Phone2. One finicky thing we noticed is that if you want to connect more than one mobile phone at a time, you need a dongle to match. So, for example if you want to connect 5 bluetooth mobile phones, you would also need 5 bluetooth dongles, and 5 free USB ports (or a USB HUB) to get it all working. We’ve never tried with more than 2 bluetooth phones, so your mileage may vary.
If you don’t see your phone, something is wrong – try the above steps again to see if it fixes it.
Now continue on by stopping Asterisk PBX, and reloading it to take advantage of our new chan_mobile module.
# /etc/init.d/asterisk stop
Now start Asterisk in debug mode so you can verify everything is working.
# asterisk -vvvvvvvvvvvvvgc
Now type this command on the Asterisk CLI to find your mobile devices
*CLI> mobile search
You should see something similar to the following
Address Name Usable Type Port
00:17:83:6F:BD:51 Phone2 Yes Phone 2
00:13:33:44:4d:23 Phone1 Yes Phone 5
The above is a listing of all Bluetooth devices available to your Asterisk PBX.
- The Address Field is the Device Identifier Code (MAC Address)
- The Name Field holds the name of the device (Phone1)
- The Usable Field tells us if the phone is Usable by Asterisk or not (Yes/No)
- The Type Field tells us if it’s a Phone (FXO) or a Headset (FXS) device
- The Port Field tells us which port the phone is using
Make a note of this information and continue on to the next step.
Now, exit Asterisk by typing “stop now” on the command line
*CLI> stop now
You’ll be back at the CLI now.
In our example, we’ll be using Phone2 to configure to work with Asterisk.
Go back and edit your mobile configuration file in /etc/asterisk to look similar to this
# nano /etc/asterisk/mobile.conf
Add something similar to the following below the adapter configuration you added earlier in the tutorial.
If you are configuring a headset, the line would look something like this instead
address=xx:xx:xx:xx:xx:xx ; the address of the headset
port=x ; the port number
type=headset ; tells asterisk it is a headset
adapter=blue ; adapter to use
Now you can start asterisk again. I would start it in debug mode so you can verify your phone is connected.
# asterisk -vvvvvvvvvvvvvvvgc
You should see messages similar to the following on the Asterisk Console letting you know your device has connected to Asterisk
— Bluetooth Device TytnII has connected.
— Bluetooth Device TytnII initialised and ready.
And if you issue the show devices command
*CLI> mobile show devices
You should see something like this
ID Address Group Adapter Connected State SMS
TytnII 00:17:83:6F:BD:51 0 blue Yes Free No
This means your phone is now connected to Asterisk. Depending on the context you put it in, if a call comes in to your cellular phone and you are within proximity of your Asterisk server it should route over to your one of your SIP extensions. Asterisk will automatically pair and unpair with your mobile phone as you come in and out of range respectively. Cool huh?
It is worth it to mention this warning from the original article as well: “Important: Watch what your cell phone is doing the first few times. Asterisk wonâ€™t make random calls but if chan_mobile fails to hang up for some reason and you get a huge bill from your telco, donâ€™t blame me.”
Hope you enjoyed this tutorial, let us know if you have any comments or other fun ideas to do with chan_mobile, bluetooth and Asterisk in the comments!