Is it possible for this code to be modified to include Bluetooth Low Energy devices as well? https://code.google.com/p/pybluez/source/browse/trunk/examples/advanced/inquiry-with-rssi.py?r=1
I can find devices like my phone and other bluetooth 4.0 devices, but not any BLE. If this cannot be modified, is it possible to run the hcitool lescan and pull the data from hci dump within python? I can use the tools to see the devices I am looking for and it gives an RSSI in hcidump, which is what my end goal is. To get a MAC address and RSSI from the BLE device.
Thanks!
As I said in the comment, that library won't work with BLE.
Here's some example code to do a simple BLE scan:
I had to piece all of that together by looking at the
hcitool
andgatttool
source code that comes with Bluez. The code is completely dependent onlibbluetooth-dev
so you'll have to make sure you have that installed first.A better way would be to use dbus to make calls to
bluetoothd
, but I haven't had a chance to research that yet. Also, the dbus interface is limited in what you can do with a BLE connection after you make one.EDIT:
Martin Tramšak pointed out that in Python 2 you need to change the last line to
print(':'.join("{0:02x}".format(ord(x)) for x in data[12:6:-1]))
You could also try pygattlib. It can be used to discover devices, and (currently) there is a basic support for reading/writing characteristics. No RSSI for now.
You could discover using the following snippet:
DiscoveryService
accepts the name of the device, and the methoddiscover
accepts a timeout (in seconds) for waiting responses.devices
is a dictionary, with BL address as keys, and names as values.pygattlib is packaged for Debian (or Ubuntu), and in the Downloads section there is a .deb.