Jump to content

Bluetooth Proximity: Another chapter...


Steven M Castano

Recommended Posts

So, I've been working for weeks if not months now on some bluetooth proximity options and I've made a TON of progress. So far I'm able to have a linux virtual machine reach out to a raspberry pi with a USB bluetooth adapter on it and get the RSSI signal value. With that I've created some basic math, thresholds and update times to compute a moving average of the last 30 values, which in my environment spans about 5 seconds.

 

It works GREAT actually.... I'm able to keep the bluetooth connected throughout almost my entire apartment, monitor the connect status for changes and when it does disconnect or reconnect, the ISY is update via the REST API and I'm able to turn off computer monitors, front hallway lights, etc... It's also VERY responsive... while I've seen iphones disconnect from WiFi for almost 20 minutes at a time... I was forced to set my ISY to "delay" thinking nobody was home for 20 minutes after seeing the last device to ensure it wasn't just a temp disconnect.

 

Also, there are times... after walking up to and into my door, wifi can take anywhere from 1 - 10 minutes to reconnect..... not very useful for throwing on the lights as you walk up to the door.

 

That being said, bluetooth has been a star from that perspective... the longest disconnects I see are for anywhere from 5 - 25 missed updates, which at the date I'm checking (6 times a second), translates to only 4 - 5 seconds. So I'm able to update the ISY seconds after walking out, reliably.... and, when I return home, there is a bluetooth antenna right behind my front door... it picks me up from easily 30 feet away and has everything turned back on for me before I can even get my keys out.

 

The situation I'm working on now is that, while this is all great for simple "home/not home".... I'm getting a little more ambitious now. I not only want to know if a device is anywhere in or near the apartment... but I want to know WHERE it is also. I've been working through the issues and have the python scripts fairly well written to at least give me one level of "near/not near". So I've got one setup under an end table in the living room and under a night table in the bedroom......

 

The problem I have is that the radios I've using don't seem to give me much leeway in signal strength ratings... the news one only show me a range of 0 to -10.... and even when basically putting the iphone right next to the bluetooth adapter, sometimes I only get a -1. Also, I stay around a ring of -1 to -5/6 when I'm in the same room, and even halfway across the apartment, but the drop off from -6 to -10 and then to disconnect is a very short distance.

 

Has anyone out there tested bluetooth USB radios? Any that have given good RSSI or LQ readings? I have an old RocketFish USB BT adapter that seems to work fairly well... it gives me a useful range of about 0 to -30/35 and is pretty consistent as you get closer and farther away, but I'm having trouble locating them again.

 

Any recommendations??

Link to comment

I'm going to work on getting the code into SVN or git at some point soon as it's getting fairly complex. I didn't want to sacrifice speed or size of the entire system at all so I've gone a little rouge on the overall design. Originally it started with a single Raspberry Pi running a small bash script and has now moved over to all python. I just couldn't get what I needed out of bash especially when I started with moving averages, signal "sanity" checks and multiple "sensors".....

 

What's it's become now is a main python script built from multiple small functions I've been developing over time, but the point here is that I'm running a linux virtual server and using the python-paramiko package to have my python scripts actually SSH out to the raspberry pi's where the USB bluetooth adapters are installed and collection the raw signal data. There is currently one pi by my front door, one in my master bedroom and one in the living room.

 

The main python script collects the raw data, stores the moving average and updates the ISY accordingly. Currently it's only telling the ISY if a device is seen by any of the bluetooth radios, but I'm working on storing and comparing the results from all three over the next few days.

 

I've determined what signals values mean I'm "near" each sense based on some VERY basic mapping I did tonight. Basically, I connected a LED to the GPIO pins and set it so that an average signal strength of -10 or below turns it on, over 10 turns it off and I adjusted it from there.... seems like that part is working great so far.

 

The part I'm working on right now, since I know how to tell if I'm "near" a device or not.... (and it still needs some fine tuning)... I'm creating ISY variables for each of my devices called: "Device1_BT_Location"

 

So I'll set that variable to a different number depending on my signal states:

0 means the script has no idea where I am

1 means I'm in the living room

2 means I'm in the master bedroom

 

So basically, I collect all the values and compare the results to my threshold... if only 1 value is "inside" the threshold, that's where I am and I will update the ISY.... if 2 values are inside the threshold, I'll elect to shoot the one with the best raw strength value and again update the variable.

 

What I have noticed is that, at times, my average drifts a little bit and I wind up "outside" of the threshold for a few seconds before it comes back down... most of the time this seems to be when I've got the iPhone in my hand and I'm assuming is due to covering the internal radio. Now the "fine-tuning" I was referring to means I either have to make the average look at a longer set of raw values which could make the location resolution "lag" a bit.... i.e. when entering a room, even those the raw values may be WELL inside of the threshold, it make take 30 seconds or so before the average comes down appropriately. Either that or I have to tolerate these "bounces" outside the threshold and possibly not consider a device as "out of the room" either until it's found in another room, or been out of a room for 2 - 5 minutes.

 

There is surely a lot that goes into this, and I've complicated it even farther by making the script totally multi-threaded so I can check all sensors simultaneously as well as adding at network server capable of listening via telnet on port 2323 so my monitoring systems can connect from time to time and get both health check results as well as momentary signal statics.

Link to comment

In my case, I might want to run three different sensors out around the house as I have a central wire-way along the edge of my furnace vent and can get a dongle on a piece of Cat 5 adapted from a USB hub connection pretty far away.

 

We don't tend to wear our phones around the house, but would like to know when they come into range from being out of range etc to handle some lighting and events.

 

I'm thinking that if I turn blue-tooth on in my car stereo, that a dongle out by the garage would know when the car came home or when it left.

 

Alan

Link to comment
In my case, I might want to run three different sensors out around the house as I have a central wire-way along the edge of my furnace vent and can get a dongle on a piece of Cat 5 adapted from a USB hub connection pretty far away.

 

We don't tend to wear our phones around the house, but would like to know when they come into range from being out of range etc to handle some lighting and events.

 

I'm thinking that if I turn blue-tooth on in my car stereo, that a dongle out by the garage would know when the car came home or when it left.

 

Alan

 

The car one is a great idea... no idea how to make it work, but I'm sure it could. The question is, how you get the car to know the BT done is there, usually the connections go the other way around.

 

As for my project with multiple sensors.... I'm having a TERRIBLE time getting it working. It seems like the original Raspberry Pi and RocketFish USB BT adapter work great. I'm able to take multiple RSSI readings per second, it's very accurate, picks up devices almost immediately and rarely disconnects.

 

The new problem is that I can't seem to replicate that... I've now tried two different sets of BT adapters and I'm starting to see the same issues/pattern emerging. It seems like there may be some limit to the number of devices an iPhone can handle, or maybe some issues with channels and such... I honestly don't know enough about it to debug it properly. The first one worked so well I thought it would be EASY to deploy more.

 

So, I've got two more raspberry pi's, both now with RocketFish BT adapters installed... I do get signal readings that are pretty consistent when working and I'm able to relate them to distances, so the "proximity" portion seems to work great. The problem is that with all 3 going, I eventually seem to lose to two new ones. Eventually they step accepting the "rfcomm" connections and I don't get any signal readings at all. At first it seemed like restarting the bluetooth service as well as "resetting" the USB connection would work to restart them. Also, it seems like it only didn't work after the iPhone had been disconnected for a while so I created a cron job to reset the USB and restart the bluetooth service every 15 minutes.

 

That didn't end up working for very long either. It eventually got to the point where virtually no connections would work... except the original one I've had for a few weeks now seems to keep working.... and I would have to actually turn bluetooth on the iPhone off and back on again. What I've tried now is to use them all on different bluetooth channels. Since the original working one runs great on channel 1, I moved the other to channels 3 and 13... all which come up usable with a working "rfcomm" service listed in a "sdptool browse" command.

 

Right now it seems like that's almost stable, but I wish there was some way of getting a clear understanding of what my problem is. Is there a max number of BT devices that can associate with an iPhone? Is it per phone? per channel? am I having hardware issues? incompatibility? BT version?

 

I even did a ton of reading on how to look at "hcidump" to watch a lot of the traffic go by but that didn't prove to be very easy to figure out either. I can run the tool and capture the traffic, I'm just not sure what I'm looking at!

Link to comment
  • 10 months later...

sorry to resurrect this thread but I was interesting in setting up Bluetooth proximity so the isy knows when me and my wife are home/away. I have wifi working ok, but like you said its not as dependable. I was specifically wondering what was needed to set this up besides a Bluetooth dongle, pi, Linux server and network module for isy. Thanks.

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...