Configuring Serial Node for Bluetooth Communication

Hello,

I am connecting Arduino to Rapberry Pi over bluetooth. On Raspberry Pi if I create rfcomm channel via sudo rfcomm hci0 MAC_HERE 1, I can use serial input node in Node-RED and get data as /dev/rfcomm0 appears when configuring the node. However, if the connection is established via python socket module, there is no /dev/rfcomm0 is created.

So the question is how should I configure the serial node so I can see the transmitted data on Node-RED when using python socket module?

If python had already directly grabbed the port then Node-RED can’t also get hold of it. The /dev/rfcomm0 version is the one to use

Hi dceejay,

I need to figure out how to bind that socket to virtual port /dev/rfcomm0. Unfortunately I could not find useful bluetooth node that I can use after pairing.

Not sure what you mean. It’s a serialport so use the serialport node

Sorry for the confusion. Let me explain in detail.

rfcomm is a deprecated command line of BlueZ which is the official linux bluetooth protocol stack.
The command of sudo rfcomm hci0 00:0E:12:34:56:67 1 does the following:

  • Creates an rfcomm channel at port 1.

  • Binds that channel to virtual /dev/rfcomm0 port/device.

In that case we can grab /dev/rfcomm0 by using the serial input node from Node-RED and read the data. However, I want to avoid using rfcomm command line tool because it is deprecated.

The second way to do that is utilizing python socket module. However, socket module does not create virtual port/device as /dev/rfcomm0, hence we cannot grab it by using Node-RED Serial Input node. Here we can do three things:

  1. Find a way to bind created python socket to /dev/rfcomm0 (I am also working on this, first we need to manually create that port.).
  2. Find a node from Node-RED that can grab, rfcomm connection which is not virtually bound to that serial port.
  3. Find a bluetooth node from Node-RED which can do all.

The 2nd and 3th methods are the reason why I posted my question here.

Ah right,
I've not been following the internals of the Bluetooth stack. Presumably if it is now a socket then it must bind to a network port in some way ? pan0 etc ? so you may be able to use the TCP or UDP nodes ? Or maybe you can add the device to a network bridge (outside of Node-RED) so that it then is visible as a network device ? Just hypothesising here of course.

Presumably if it is now a socket then it must bind to a network port in some way ?

Exactly. However I couldn't figure this out from the documentation of socket module. I will try the nodes you mentioned and provide a feedback asap.

Maybe something like Bluetooth Programming with Python 3 - Kevin Doran

I am pretty aware of that module, however:

This project is not under active development.

as stated at their GitHub.. Also, the module itself do not add anything different than socket module regarding creating rfcomm connection. The module offers additional services such as discovering devices etc., however I would suggest using D-BUS API as documented in official BlueZ repo which I am currently using to pair my devices.

OK - good luck !