BlueBoss v2.0 – Bluetooth Proximity Alerting

Summary: Bluetooth is now found in a variety of devices and enable the user to use wireless accessories.  The Bluetooth protocol allows a user to “discover” any device that is in proximity to your Bluetooth radio.  Why not see who is in proximity to you?  Why not have the presence of a device execute programs or alert you?

Andy Konkol – http://copyandwaste.com

Download:

Hardware:

  • Bluetooth radio (USB dongle)

  • SMA Female Jack

  • SMA male to N-male pigtail

  • 2.4 GHz antenna (with N-female connector)

Software:

Bluetooth and Hardware:
Bluetooth was designed for devices to communicate wirelessly over short distances.  However, with a very simple hardware modification you can extend the range of your Bluetooth radio with standard 2.4ghz antennas used in wireless networking (802.11 a/b/g).

Modifying Bluetooth dongles to accept external antennas is documented all over the Internet.  In principle it is very easy: find the antenna lead and solder on a connector/antenna.  I purchased a very cheap Bluetooth USB dongle on eBay and opened the casing.  After finding the antenna trace on the circuit board I soldered on a SMA Female connector to it.  After soldering the antenna jack in place I slipped a 3 inch chunk of heatshrink and heated it to cover the exposed circuit board.  Now I had a Bluetooth radio that accepts external antennas. Adding an antenna simply increases the range of your radio, allowing you to “see” devices from a farther distance.

To connect an external antenna to the dongle I needed to use a connector converter called a pigtail.  I used a SMA male to N-male pigtail.  I connected one end of the pigtail to my dongle and the other to an omni-directional 9dbi panel antenna that had an N-female connector.

 IMG_2070 IMG_2071

 

Software:
To take advantage of my newly modified hardware I needed to download the Coding4Fun Toolkit.  Included in the toolkit is an API for Bluetooth devices.  This API allows you to do a wide variety of things with your Bluetooth radio but I focused on two methods from the ServiceAndDeviceDiscovery library: DiscoverAllDevices and DiscoverDeviceByName.

DiscoverAllDevices allows you to “scan” the airwaves on the 2.4 GHz band and report back what devices your radio sees.

DiscoverDeviceByName allows you to scan for a particular device with a specified name and report back if it is present or not.

   1: private bool DevicePresent()
   2:         {
   3:             BluetoothDeviceServicesManager workerBTMgr = new BluetoothDeviceServicesManager();
   4:             Device workerDevice = workerBTMgr.DiscoverDeviceByName(_watchItem.DeviceName);
   5:  
   6:             if (workerDevice != null)
   7:             {
   8:                 return true;
   9:             }
  10:             else
  11:             {
  12:                 return false;
  13:             }
  14:  
  15:         }
  16:  
  17:         public void Run(String Operation)
  18:         {
  19:             switch (Operation)
  20:             {
  21:                 case "SingleDevice":
  22:                     if (DevicePresent())
  23:                     {
  24:                         _parentForm.Invoke(_parentForm.AddToDeviceSeenList, new object[] {_watchItem});
  25:                     }
  26:                     else
  27:                     {
  28:                         _parentForm.Invoke(_parentForm.RemoveFromDeviceSeenList, new object[] { _watchItem });
  29:                     }
  30:                     break;
  31:                 case "AllDevices":
  32:                     BluetoothDeviceServicesManager workerBTMgr = new BluetoothDeviceServicesManager();
  33:                     List Devices = workerBTMgr.DiscoverAllDevices();
  34:                     _parentForm.Invoke(_parentForm.ThreadUpdateDiscoverBox, new object[] { Devices });
  35:                     break;
  36:             }
  37:  
  38:         }

 

Both of these methods require that the device you are scanning for is in discoverable mode (which most manufacturers enable by default).  Using the two methods described above I was able to tell if a device is in proximity. And ultimately enabling me create alerts and execute programs based on what device is present.

To perform device discovery and not have my UI lag I had to create two worker threads.  One worker thread to discover all devices and display it under my devices listbox, and another to discover devices by name specified in the “watchlist.”  I am not an expert at multi-threaded programs but I managed to implement them without any major headaches.

 

User Interface:

Since the “Add to watchlist” and “Edit” buttons essentially do the same thing, I decided to overload a windows form.  I also wanted to keep track of the parent form and disable it when the WatchItemForm was shown.

The second overload allows me to fill in the form control’s text based on the data that is already set for the WatchItem that has been selected (the Edit button). 

   1: public WatchItemForm(Form1 f, String DeviceName)
   2:         {
   3:             InitializeComponent();
   4:             this._parentForm = f;
   5:             lblDeviceName.Text = DeviceName;
   6:  
   7:         }
   8:  
   9:         public WatchItemForm(Form1 f, WatchItem item)
  10:         {
  11:             InitializeComponent();
  12:             this._parentForm = f;
  13:  
  14:             lblDeviceName.Text = item.DeviceName;
  15:             tbxAlertMessage.Text = item.AlertMessage;
  16:             tbxPicturePath.Text = item.ImagePath;
  17:             tbxProgramPath.Text = item.ProgramPath;
  18:             this._parentForm.Enabled = true;
  19:             
  20:         }

I wanted to have a pop up notify window similar to outlook and was able to find Robert Misiak’s NotifyWindow. This is a very simple library which allows you to create pop up notify windows very easily. I edited NotifyWindow to include a “picturepath” variable as well as picturebox on the form. As you can see creating a NotifyWindow is quite easy:

   1: public void NotifyDeviceWindow(WatchItem x)
   2: {
   3:     NotifyWindow nw;
   4:     nw = new NotifyWindow();
   5:     //validate Alert Message
   6:     if (x.AlertMessage == null)
   7:     {
   8:         nw.Text = x.DeviceName;
   9:     }
  10:     else
  11:     {
  12:         nw.Text = x.AlertMessage;
  13:     }
  14:     //validate picture
  15:     if (x.ImagePath != null)
  16:     {
  17:         FileInfo imgfile = new FileInfo(x.ImagePath);
  18:         if (imgfile.Exists)
  19:         {
  20:             nw.PicturePath = x.ImagePath;
  21:         }
  22:         else
  23:         {
  24:             MessageBox.Show("Image does not exist");
  25:         }
  26:     }
  27:     nw.Notify();
  28:  
  29:     if (x.ProgramPath != null)
  30:     {
  31:         RunProcess(x.ProgramPath);
  32:     }
  33: }

Process Flow/Software Operation:

  1. User clicks the “Discover” button, a thread is spawned which enumerates all Bluetooth devices in proximity
  2. Thread finishes and updates the Devices listbox
  3. User selects a discovered device and clicks “Add to watchlist” A watch item form is spawned and asks you for an alert message, a picture path, and an executable path
  4. User clicks save , a WatchItem object is created and added to the watchList object
  5. A timer starts and every 10 seconds a thread is spawned to discover that device by name
  6. If the device is discovered, it is added to the “deviceSeenList” and a notify alert is sent and the executable is executed.
  7. If that device is still present after the next timer click, no notification is sent, If that device is not present it is removed from the “deviceSeenList”

Screenshots:

bb-main bb-watchitem bb-notify

Continue reading » · Rating: · Written on: 06-23-08 · 2 Comments »

What’s next?

I haven’t bought a pre-made computer in more than 10 years.  I think I have finally gotten to a point where I don’t want to muck around with commodity computer hardware.  It’s time to buy a pre-made machine.  I use a wide variety of operating systems at home and at work.  The idea of a virtual desktop is very appealing to me…. a single machine where I can have windows, bsd, linux, and mac os x would be great.  I’ve done some research on “hackintosh” and to be honest… for the first time… it’s a diy project I don’t want to do. So I’ve pretty much decided that I need to buy a mac and a copy of parallels.  Now what kind of mac do I want? Macbook pro, Mac pro, or an iMac?

 

Mac pro is just way too much money  but upgrading would be easy.

iMac is a pretty closed device where replacing common things like hard disks could be a project… but the screen is so nice!

Macbook Pro would be pretty awesome but lacks some of the power I would like for virtualization.

 

It looks more and more that I should just get an iMac and stfu.  Maybe I’ll get one…

imac_narrowweb__300x4422

Continue reading » · Rating: · Written on: 06-15-08 · 3 Comments »

4U2SEE LED Sign Revisited

I lost the source code I had originally for this sign.  Chris Gray left a comment about help and I ultimately ended up re-visiting code for the 4U2See.

 

Download CinderSerial

sign fixed with a hack…

The problem is that when I try to send a “file” to the sign,

c:\sequent.sys (on the sign) does nothget updated.  So you create a legit file with sigma editor, rename it without an extension.  Push the renamed file with sigma play.  This will update the sequent.sys

file on the sign.  Now run my program which sends a file named “A” to the sign and it should work.

 

Open Sigma Editor:

——————

1) Click new file

2) enter in “working?”

3) Save to computer as “A.nmg”

4) Exit Sigma editor

5) Rename file to “A” (no extension)

Open Sigma Player:

——————

6) Click on List Manage

7) Expand My Play List

8) Select all files in the right hand pane and delete them

9) Click the add button and find the “A” file in step 5

10) Send to sign

Compile my program (CinderSerial)

———————————

1) Type in text you want to be displayed

2) Select a color

3) (display mode isnt implemented yet)

4) Click submit

Continue reading » · Rating: · Written on: 06-14-08 · 20 Comments »

BlueBoss- Bluetooth Proximity Alerting

Chances are that your boss, director, or CTO is using bluetooth on their phone.  Since they are using bluetooth you can scan the 2.4ghz radio band and look for devices that are within the proximity of your bluetooth dongle(radio).  This application scans that band for devices that are within your proximity and allows you to receive a pop-up message from the system tray when a known  device is in the area.  More importantly you can configure applications to be run, like….. “firefox www.yourcompanieswebsite.com”  when  say… your boss’s bluetooth enabled phone is in the proximity.

You do not have to be paired with any bluetooth device to be able to discover it with the Coding 4 Fun bluetooth API.  Although using this method of discovery is not guaranteed I have found it to work in a variety of phones.  To increase the range of my radio I modified my dongle to accept an external antenna.  With this hardware I can get a range of about 50 feet tested.

Hardware:

  • Bluetooth Dongle – $1.99
  • SMA Female connector – Free (had one)
  • SMA to N-Male pigtail – $6.99
  • 9dbi Panel Antenna – Free (had one)

IMG_2067 IMG_2068 IMG_2071 IMG_2073

Software:

All you have to do is press “Discover” when the bluetooth device is in proximity and Add it to the Watchlist.  You may specify an alert message, a picture to display, and/or a program to run.  A worker thread is spawned when the Discover button is pressed:

   1: private void btnDiscover_Click(object sender, EventArgs e)
   2: {
   3:     btnDiscover.Text = "scanning";
   4:     btnDiscover.Enabled = false;
   5:  
   6:     m_EventStopThread.Reset();
   7:     m_EventThreadStopped.Reset();
   8:  
   9:     // create worker thread instance for discovering all devices
  10:     m_WorkerThread2 = new Thread(new ThreadStart(this.DiscoverWorkerThread));
  11:     m_WorkerThread2.Name = "Discovering Worker Thread";    // looks nice in Output window
  12:     m_WorkerThread2.Start();
  13:  
  14:     lbxDevices.Items.Clear();
  15:  
  16: }

 

On Form load, a timer is enabled for 10 seconds, when that timer “ticks” a DiscoverByName is performed by a worker thread:

   1: private void tmrMain_Tick(object sender, EventArgs e)
   2:        {
   3:            //read xml config >> watchList
   4:            //timer went off, foreach watchitem spawn worker thread to poll device
   5:            foreach(WatchItem tmp in watchList.WatchItems)
   6:            {
   7:                // reset events
   8:                m_EventStopThread.Reset();
   9:                m_EventThreadStopped.Reset();
  10:  
  11:                // create worker thread instance
  12:                m_WorkerThread = new Thread(new ParameterizedThreadStart(this.WorkerThreadFunction));
  13:                m_WorkerThread.Name = "Worker Thread Discover By Name";
  14:                m_WorkerThread.Start(tmp);
  15:  
  16:            }
  17:        }

From the “Worker” class, which actually does the polling and callback to the parent form delegate:

   1: private bool DevicePresent()
   2: {
   3:     BluetoothDeviceServicesManager workerBTMgr = new BluetoothDeviceServicesManager();
   4:     Device workerDevice = workerBTMgr.DiscoverDeviceByName(m_WatchItem.DeviceName);
   5:  
   6:     if (workerDevice != null)
   7:     {
   8:         return true;
   9:     }
  10:     else
  11:     {
  12:         return false;
  13:     }
  14:  
  15: }
  16:  
  17: public void Run()
  18: {
  19:     if (DevicePresent())
  20:     {
  21:         try
  22:         {
  23:             m_form.Invoke(m_form.m_NotifyDevicePresent, new object[] { m_WatchItem });
  24:         }
  25:         catch (Exception ex)
  26:         {
  27:             MessageBox.Show(ex.Message.ToString());
  28:             
  29:         }
  30:     }
  31:  
  32: }

bb-main  bb-watchitem

Once you have added a device to the watchlist a worker thread is spawned and tries to discover that device every 15 seconds or so.

 

bb-notify

Some code I used:

Download BlueBoss v1.0

Continue reading » · Rating: · Written on: 06-08-08 · No Comments »