hcitool deprecated upstream
t1nux opened this issue · 15 comments
It seems upstream does not include hcitool
anymore in bluez-utils [1]. Sooner or later people will realize this when they run into problems. Although there are legacy packages already for some distros (although not official), I think it might be a good idea to add support for an alternative method to communicate using bluetooth. bluetoothctl
is the upstream alternative and therefore might be a good candidate.
[1] https://www.spinics.net/lists/linux-bluetooth/msg69239.html
Thanks for the info, will check bluetoothctl.
An option that I was checking earlier was to switch the Bluetooth communication from hcitool to python socket module. This way the package would not be dependant on any external libraries. I haven't found any good examples yet, so I don't have any idea how easy it is to implement or will it even work.
You might want to take a look at the great work @frawau is doing.
https://github.com/frawau/aioblescan/tree/master/aioblescan
Good to know that it will work :) Will check basic configuration from there. Good work @frawau!
Unfortunately can't use socket module as by default Python does not support socket.AF_BLUETOOTH.
E.g. with rasbpian you will get this error
module 'socket' has no attribute 'AF_BLUETOOTH'
https://docs.python.org/3/library/socket.html#socket-families
Depending on the system and the build options, various socket families are supported by this module.
Apparently Python needs to be compiled with bluez headers to make it work.
Will check bluetoothctl
or some cross platform library e.g. https://github.com/TheCellule/python-bleson.
What version of Python are you using? I have not done anything special on the latest version of Raspbian and it works with Python3.
Ok, good to know that the problem was with my own environment. I used Python 3.6.0. I have an old Raspbian where I installed it manually, so that is likely then the problem. Will re-install newer Raspbian.
I will continue checking Bleson, as it is cross-platform and will provide also macOS and Windows support. Unfortunately it is still in early alpha, but @WayneKeenan seems to be actively developing it. It also uses socket module on Linux.
I guess, hciconfig
is also affected.
It's used inble_communication.py
, line 67:
subprocess.call('sudo hciconfig %s reset' % bt_device, shell=True, stdout=DEVNULL)
According to the arch linux wiki, btmgmt
is the new tool to use:
https://wiki.archlinux.org/index.php/bluetooth#Shell_command_is_missing_from_bluez-utils
Although raspberry pi stretch release does not include hcitool it can be retrieved using:
sudo apt-get install bluetooth bluez blueman bluez-hcidump
BUT
sudo apt-get install bluetooth bluez blueman bluez-hciconf
E: Unable to locate package bluez-hciconf
I would recommend having a look at https://github.com/open-homeautomation/miflora as a refernce. It's for another bluetooth LE device :)
Added first implementation with Bleson to own branch: https://github.com/ttu/ruuvitag-sensor/tree/bleson-ble-communication
Works with Linux. On Windows finds ble devices, but doesn't return any data. Haven't tried with macOS.
Must be installed with dependency-links as Bleson is installed from GitHub
$ pip install -e . --process-dependency-links
It seems that Bleson only provides one BLE advertisement packet per tag. The parameter on Bleson side is called "duplicates", but setting it to True appears to set "filter_duplicates" HCI interface parameter to true, which I presume disables duplicates.
After fixing that, the MAC addresses are reversed when they come out of BleCommunicationBleson.
Plesse raise an issue on Bleson stating what you would like, I'll see what I can do :)
Raised and created PR