Home » Cellular Services » Bluetooth Proximity Detection for Automatic Call Forwarding

The Most Versatile VoIP Provider: FREE PORTING

Bluetooth Proximity Detection for Automatic Call Forwarding

blankTime flies. It's been over six years since we introduced Bluetooth Proximity Detection to the Asterisk® community. Suffice it to say, the last tutorial was getting a little long in the tooth. Because we can't seem to get enough programming torture lately, we decided to revisit Follow Me Phoning by taking it to a whole new level with a fresh look at the setup procedure using the latest version of CentOS™ and PBX in a Flash 2™. This entire project takes less than 15 minutes.

If you're new to all of this, what we're talking about is the ability to stroll out of your home or office and have your telephone calls follow you on your cellphone automatically... without touching anything. And, when you return, the home or office phones start ringing again just as if you never left. Won't your boss or spouse be thrilled? What makes all of this possible, of course, is Bluetooth which happens to be running on your PBX in a Flash™ server and on your iPhone®, or Android® phone, or even Windows® Phone 7.

Our plan today is simple enough. We want to design a phone system so that, when you walk into your home or office, the phones ring in the office when there's an incoming call. And, when you walk out of your home or office carrying your WonderPhone with Bluetooth, calls to your home or office extension will start ringing on your cellphone. If you're using one of our turnkey PIAF2™ systems, this project should take you about 15 minutes to complete once you have a compatible USB Bluetooth adapter in hand.

blank

System Requirements. As mentioned, you'll need a Linux-based Asterisk server. We recommend PBX in a Flash 2 which uses the latest and greatest CentOS 6.2™. It makes a virtually flawless communications server and includes all of the Linux utilities you'll need to get this working. Other than your Asterisk server, the only other hardware you'll need is a dLink™ DBT120 Bluetooth Adapter or any Bluetooth 2.0 EDR-compatible USB device will do. DBT120's run $30-$40 from most electronics stores. The clones cost a dollar or two on eBay. The ones with the black, semi-circular tops work fine. You choose. If you're using some other Linux flavor that doesn't include the Bluetooth utilities, consult our original article for installation instructions.

blank

USB Bluetooth Adapter Installation. Boot up your Asterisk server if it is not already running and log in as root. Plug your USB Bluetooth adapter into an available USB slot. Now issue the following command:

/etc/init.d/bluetooth start

If you're alerted that some other application isn't running, we don't care. Now let's be sure the system has found your bluetooth adapter. Issue the following command from the Linux CLI:

hcitool dev

Assuming you get a response telling you the system found device hci0 with the MAC address of the adapter, you have successfully installed your USB Bluetooth adapter. So let's press on.

Configuring Linux Bluetooth Software to Start Automatically. You don't want to have to manually start up your Linux Bluetooth application each time you reboot your server. The easiest way to automatically start it is to issue the following command while still logged into your server as root:

chkconfig --level 345 bluetooth on

Deciphering Your Cellphone's Bluetooth MAC Address. We're going to be communicating with your Wonderphone to determine when you're in and when you're out. In order to do that, we need the MAC address of the phone's Bluetooth Adapter. Here's how to find it. Move your cellphone within 10 feet or so of your Asterisk server. Then put your phone into Bluetooth Discovery Mode by making it Visible for discovery. Every phone does this a little differently but you get the idea. HINT: Be sure Bluetooth is set to ON. Once you've done that, your phone will report that it is Discoverable. Put the cell phone down near your Asterisk server and jump back over to your Asterisk server console. Issue the following command, and you may have to try it several times until you get the MAC address of your cellphone's Bluetooth Adapter:

hcitool scan

Your system will whir away for a few seconds and then will report back the Bluetooth MAC address and name assigned to the adapter. It may be your name, or it may be the name or model of your cellphone. Write both of them down. We'll need the MAC address in a minute.

Proximity Detection Design. Now we've got all the hardware information we need to make proximity detection work. We'll download the Proximity Detection software in a minute. But first, sit down with a pencil and write down the other information you'll need to configure the Proximity Detection software. To make the software as flexibile as possible, we've reworked the code a bit since the original article. With the new code, it's possible to manage multiple extensions of multiple people with multiple cellphones. So what you'll need is the extension numbers of the people that want to use this and the cellphone numbers of those people. For example, you may want to forward extension 200 to 6782345678 and extension 202 to 6783456789. Just make sure that the forwarding numbers are in the correct format for the default outbound dialing rules on your Asterisk server. If your server expects numbers to always begin with a 9 or a 1, be sure to include it in the dial string, or the calls won't be completed when they are forwarded. Obviously, you'll also need the MAC address for each of your cellphone's Bluetooth adapters so just repeat the drill above with each cellphone until you have all of the MAC addresses. Finally, you'll need to assign an 8-character (or less) name to each user. So make yourself a nice little chart:

WARD 00:1D:64:C9:58:BA 200 6782345678
MARY 00:2D:54:C9:59:AB 201 6783456789

Today's installment assumes you are using a single Asterisk server both for your phone system AND proximity detection. The only drawback with the current design is that the cellphones need to be placed close to that server when you arrive at your home or office. You can experiment on the distance the cellphones can be away from the server. Different Bluetooth adapters and cellphones have slightly different ranges. The bottom line is you always want to leave the cellphones close enough to the server with the USB Bluetooth adapter so that the proximity detection works reliably all the time.

Proximity Detection Software Installation. All that remains to be done is to download and configure the proximity detection script and then put it in motion on your Linux machine. Log into your Asterisk server as root and move to the /root directory to download and unzip the script:

cd /root
wget http://nerdvittles.com/trixbox123/proximity.zip
unzip proximity.zip
chmod +x proximity

If you're going to be setting up proximity detection for multiple people, just make copies of the proximity script, e.g. cp proximity proximity1. Then edit each of the scripts and fill in the data from the little chart you made: nano -w proximity

deviceuser=WARD
devicemac=00:4B:63:D5:62:AB
myextension=200
mycellphone=6783456789

Save your changes and exit the editor: Ctrl-X, Y, then Enter.

Setting Up the Crontab Jobs. The last step is to set up a crontab entry for each script so that it gets run once a minute during whatever hours each day you want to monitor your cellphones. While still logged in as root, edit /etc/crontab: nano -w /etc/crontab. Insert a line like the following at the bottom of the existing file. This code would monitor your cellphone from 6 a.m. to 9 p.m. each day. To monitor your phone 24 hours a day, replace 6-21 with an additional asterisk.

* 6-21 * * * root /root/proximity > /dev/null

Repeat the drill for the other phones you want to monitor substituting the correct script names, and you're done. Save your changes and exit the editor: Ctrl-X, Y, then Enter.

Incidentally, if you ever want to disable the Proximity Detection System, just edit the crontab file and comment out the lines you want to disable by inserting # at the beginning of the line(s). Then try a test call. If it happens that your calls are still being forwarded to your cellphone, you can cancel the forwarding from any Asterisk extension by dialing *74.

Alternatives. Since our original articles on proximity detection were released, some alternatives have appeared on the horizon. Perhaps the most important one is Google Voice. Using a free Google Voice account with a phone number in your choice of area codes, it's now possible to designate up to six phone numbers to ring in addition to the phones you have connected to your Google Voice number using either a PIAF2™ server or a $50 OBi device. In some cases, this may alleviate the need for proximity detection because you can simply pick up your office or home phone when it's available and answer your cellphone when you're away since both will be ringing. One advantage of the Google Voice approach is that inbound calls to your cellphone will display the CallerID of the caller rather than the CallerID of the trunk being used to forward calls to your cellphone. Either way works, and it's nice to have alternatives. Enjoy!

Originally published: Monday, February 6, 2012


blankSupport Issues. With any application as sophisticated as Asterisk, you're bound to have questions. Blog comments are a terrible place to handle support issues although we welcome general comments about our articles and software. If you have particular support issues, we encourage you to get actively involved in the PBX in a Flash Forums. It's the best Asterisk tech support site in the business, and it's all free! We maintain a thread with Information, Patches and Bug Fixes for Incredible PBX. Please have a look. Unlike some forums, ours is extremely friendly and is supported by literally hundreds of Asterisk gurus and thousands of ordinary users just like you. You won't have to wait long for an answer to your question.


 

Special Thanks to Our Generous Sponsors


FULL DISCLOSURE: ClearlyIP, Skyetel, Vitelity, DigitalOcean, Vultr, VoIP.ms, 3CX, Sangoma, TelecomsXchange and VitalPBX have provided financial support to Nerd Vittles and our open source projects through advertising, referral revenue, and/or merchandise. As an Amazon Associate and Best Buy Affiliate, we also earn from qualifying purchases. We’ve chosen these providers not the other way around. Our decisions are based upon their corporate reputation and the quality of their offerings and pricing. Our recommendations regarding technology are reached without regard to financial compensation except in situations in which comparable products at comparable pricing are available from multiple sources. In this limited case, we support our sponsors because our sponsors support us.

blankBOGO Bonaza: Enjoy state-of-the-art VoIP service with a $10 credit and half-price SIP service on up to $500 of Skyetel trunking with free number porting when you fund your Skyetel account. No limits on number of simultaneous calls. Quadruple data center redundancy. $25 monthly minimum spend required. Tutorial and sign up details are here.

blankThe lynchpin of Incredible PBX 2020 and beyond is ClearlyIP components which bring management of FreePBX modules and SIP phone integration to a level never before available with any other Asterisk distribution. And now you can configure and reconfigure your new Incredible PBX phones from the convenience of the Incredible PBX GUI.

blankVitalPBX is perhaps the fastest-growing PBX offering based upon Asterisk with an installed presence in more than 100 countries worldwide. VitalPBX has generously provided a customized White Label version of Incredible PBX tailored for use with all Incredible PBX and VitalPBX custom applications. Follow this link for a free test drive!
 

blankSpecial Thanks to Vitelity. Vitelity is now Voyant Communications and has halted new registrations for the time being. Our special thanks to Vitelity for their unwavering financial support over many years and to the many Nerd Vittles readers who continue to enjoy the benefits of their service offerings. We will keep everyone posted on further developments.
 



2 Comments

  1. Thanks for this educative tutorial. I just want to ask that could this same command work for trixbox v2.8.0.4? and redhat-Linux version. If i follow it step by step will i achieve the same result? I am not a Linux person, but thanks to God and free educators like you. I got it installed and it’s working fine. Now i want to route my calls to to my mobile phone, so that through it I could make calls and be called.

  2. I’d love to give this a go with Incredible PBX on the Raspberry Pi. Will it work? If so, any suggested Bluetooth adapters (the D-Link seems a bit rare, these days)?

    [WM: Works fine. See the latest article for an eBay link to inexpensive (under $1) Bluetooth adapters.]

Comments are closed.