Skip to content
Advertisement

Bluetooth Serial Port on Raspberry Pi & something weird happened when using IDE and terminator to run python files

I am doing a project using the Bluetooth serial port. It is about the message communication between cellphones and the Rpi.

I typed ‘sudo rfcomm watch hci0’ on the Terminator.

The code on Python is simple: only assign the port address (‘/dev/rfcomm0’) and readline().

At first, things went right until I disconnected and reconnected. It said, “Cannot create Rfcomm TTY: Address already in use“. I guess it is because I didn’t close the serial port, so I added ‘ser.close()’. And then it worked. I ran it on Thonny (the IDE for Python on Rpi).

However, when I tried running the Python script on the Terminator, weird things happened. Initially, all things went right but when I disconnected the Bluetooth connection, it was stuck and if I tried reconnecting, it told me “Cannot create Rfcomm TTY: Address already in use” again.

So, what is the difference between running the script on IDE and on Terminator? It really confused me a lot because I am planning to make the script running automatically after rebooting.

Also, could someone tell me how to solve the error, “Cannot create Rfcomm TTY: Address already in use“, in a better way?

Thank you!

I want to add more explanation.

When I use IDE to run the script: enter image description here

It worked well when I disconnected and reconnected.

But when I use Terminator to run the script (“sudo Python3 xxxxxx.py”): enter image description here

It failed when I tried reconnecting. And the terminator got stuck and then ran abnormally when I disconnected and reconnected.

Advertisement

Answer

hciattach, hciconfig, hcitool, hcidump, rfcomm, sdptool, ciptool, and gatttool were deprecated by the BlueZ project in 2017. If you are following a tutorial that uses them, there is a chance that it might be out of date.

The Bluedot library supports creating a server to communicate RFCOMM serial data. More details at: https://bluedot.readthedocs.io/en/latest/btcommapi.html#bluetoothserver

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement