Bluetooth Issues

Hey Everyone,

I am currently working on a bot to track its way to a blue tooth source using the rssi.
SO far I have the Ai brain working, but I can not seem to get the bluez libs imported
into the python 3.4.

I can ping the device through the console just fine.

hcitool scan

But i need to have a script that runs in a thread to keep my bot updated on the
return value.
Does anyone have any best practices or guides that would help me with this issue?
I have been searching for a solution for a few days and have returned null in all my searches.

Thanks,
--Nicholas

piborg's picture

I do not know if you came across this project, but it provides some Python libraries and an example of querying RSSI values:
https://github.com/karulis/pybluez
This post might also be helpful:
http://stackoverflow.com/questions/22443896/measuring-proximity-with-blu...

While not ideal, another solution is to wrap the commands you are currently using:

import os

rawFile = os.psopen('hcitool scan')
rawText = rawFile.readlines()
rawFile.close()

print rawText

From this point you can then use Python to find the correct value from the rawText variable and extract it.
There is an example of this on our site for ping times: https://www.piborg.org/pingmonitor

Those look really promising, thanks!

Currently just trying to get a simple test script working.
The bluez is currently fighting me at every pass.
Need to get it working properly.

## Update:
So I did get a simple text script working.
However, I can only get it working in python 2.7
and not 3.4+. So, need to get that updated, otherwise
the Web GUI is unusable. Since I need to have the socket server
module.

--Nicholas

Edit: Added text.
Edit 2: Added more text.

piborg's picture

That I can help with ^_^

Python 2.7 does have the socket server library, but there is a subtle difference between Python 2.x and Python 3.x.

Python 2.x:
import SocketServer
https://docs.python.org/2.7/library/socketserver.html
Python 3.x:
import socketserver
https://docs.python.org/3.4/library/socketserver.html

I got that back up and working.
So I built a leash script to query for a specific bluetooth enabled device from the inquiry-with-rssi.py.
It is build as a class that runs a query every second until termination.
I still need to modify the code so I can try and have the AI update its rssi every 1/10 or if possible
1/60 of a second.

Then it all comes down to seeing if my math is correct and try to have the bot travel to my location
all by itself.

Ill make the alpha code public for anyone that wants it when the bot is more done.
Unfortunately, python is not my main language, so it looks a lot like c and c++ code.

-- Nicholas

So a new problem came up.
I can not get my phone to stay connected to the PI via bluetooth.
Did you ever come across this??

-- Nicholas

piborg's picture

Glad to hear you are making progress :)

I would suggest that what is happening is that the phone is trying to save battery.
What I expect it does is if there have not been any messages for a while it disconnects on its own.

It might be worth adding some code to your RSSI checking thread so that it sends a message to the phone occasionally.
Hopefully that will be enough to keep the connection alive.

That was the issue it seems. My phone was on power save mode and would disappear from the
world space.

So now that the AI has eyes, need to get the override buttons working on the webpage.
-- Nicholas

Images: 
Subscribe to Comments for "Bluetooth Issues "