Time 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.
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.
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:
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:
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:
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:
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
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
Support 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.
Need help with Asterisk? Visit the PBX in a Flash Forum.
Or Try the New, Free PBX in a Flash Conference Bridge.
whos.amung.us If you're wondering what your fellow man is reading on Nerd Vittles these days, wonder no more. Visit our new whos.amung.us statistical web site and check out what's happening. It's a terrific resource both for us and for you.
New Vitelity Special. Vitelity has generously offered a new discount for PBX in a Flash users. You now can get an almost half-price DID and 60 free minutes from our special Vitelity sign-up link. If you're seeking the best flexibility in choosing an area code and phone number plus the lowest entry level pricing plus high quality calls, then Vitelity is the hands-down winner. Vitelity provides Tier A DID inbound service in over 3,000 rate centers throughout the US and Canada. And, when you use our special link to sign up, the Nerd Vittles and PBX in a Flash projects get a few shekels down the road while you get an incredible signup deal as well. The going rate for Vitelity's DID service is $7.95 a month which includes up to 4,000 incoming minutes on two simultaneous channels with terminations priced at 1.45¢ per minute. Not any more! For PBX in a Flash users, here's a deal you can't (and shouldn't) refuse! Sign up now, and you can purchase a Tier A DID with unlimited incoming calls for just $3.99 a month and you get a free hour of outbound calling to test out their call quality. To check availability of local numbers and tiers of service from Vitelity, click here. Do not use this link to order your DIDs, or you won't get the special pricing! After the free hour of outbound calling, Vitelity's rate is just 1.44¢ per minute for outbound calls in the U.S. There is a $35 prepay when you sign up. This covers future usage and any balance is fully refundable if you decide to discontinue service with Vitelity.
Some Recent Nerd Vittles Articles of Interest...