10

Since bluez 5.44, the rfcomm binaries contained in bluez-utils (amongst others like hcitool) are considered deprecated and are from now on only included in the bluez-utils-compat package provided by the AUR.

Is there a similar command-line application to bind a bluetooth device to a serial port using the rfcomm kernel module or do I have to use PyBluez or similar libs from now on?

If the latter happens to be the case, which Python 3 libraries would you recommend ?

And if somebody knows, please tell me why so many of the bluez-utils are considered deprecated all of a sudden. I couldn't find anything about that.

The ArchWiki recommends implementing the rfcomm functionality using the new D-Bus Profile 1 API.

2

I have recently found the bluez-tools project, which aims to implement the lost functionality using Bluez current D-Bus api.

Bluez-tools is available on ArchLinux from the community repository. I have not tested this and the github page states, that it is still in beta. But according to the documentation, bt-serial should be able to replace the old bluez rfcomm and bt-adapter+bt-agent+bt-device have the functionality of hcitool.

1

I have found another possible solution. I found this by digging through someone's git hub repo. This uses python3 built in socket module.

Prerequisites:

  1. You have a working adapter at address <adapter address>.
  2. You have your target Bluetooth device at <device address>.
  3. The device is pinned.

That is, the same point that rfcomm can be used.


$python3
>>> import socket
>>> sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
>>> adapter = '00:11:22:33:44:55' #<adapter address>
>>> device = '55:44:33:22:11:00' #<device address>
>>> sock.bind((adapter, 1))
>>> sock.connect((device, 1))
## If not pinned it will ask you. You can use/adapt the bluez simple-agent for headless pinning
>>> sock.send(b'hello\n')
>>> sock.recv(100)
>>> sock.close()
  • It's nice to know that Python natively supports Bluetooth serial communication. Thanks for replying to this relatively old question. – eike Dec 5 '18 at 22:34
0

i want to note about this problem:

  1. that this github project contains some of rfcomm functionality. (based on bluez test files).
  2. bluez project itself still contains rfcomm.c file, that can be easily compiled with:

    gcc -lbluetooth rfcomm.c -orfcomm -DVERSION=xyz

... just one file, no need for compiling whole bluez project. where xyz is version of downloaded bluez tar.xz source code (5.46 is now). before downloading, one should first check own bluetoothd -vand download matching source. bluez-libs is only dependency for compile success.

I needed rfcomm for armv7 (raspberry 2) and there is no aur package for rfcomm, and this was only way, but it works well.

Still not sure why rfcomm is deprecated, without good alternative, and how to talk to bluetooth as it was serial port other way. Because even you are python expert plus DBUS expert ... (like above mentioned project's owner probably is)... still only fifo was provided this way, not real character device in /dev/... that all other programs (like arduino) can see and work with.

  • 2
    1. The project page states "Just to avoid re-implementing some old code that uses these tools", which means the author would suggest following a different approach when using bluez for new projects. 2. There are many ways to compile rfcomm myself, what I am searching for is the reason for its deprecation and a supported alternative. – eike Sep 26 '17 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.