0

I am using rfcomm to connect to an Arduino nano (HC-06 bluetooth module) from my RPI 4B+. It works flawlessly and the two devices are able to communicate with no issues. I need to be able to connect several of these same bluetooth devices over bluetooth and communicate with them serially. Right now, I have to manually connect each device like this:

sudo rfcomm connect 0 98:D3:41:FD:6B:EB Connected /dev/rfcomm0 to 98:D3:41:FD:6B:EB on channel 1 Press CTRL-C for hangup

And I can communicate perfectly with each device very easily using python:

import serial s = serial.Serial("/dev/rfcomm0", 9600) s.write(bytes("0",'utf-8'))

This works fine for one device, but I would like each device to connect automatically on startup without myself having to initialize anything. How can I use rfcomm to connect and communicate with multiple devices over serial? I simply want my rpi to pair with each device on startup and be ready for communication.

1 Answer 1

1

I think the Python Socket module can do this https://docs.python.org/3.3/library/socket.html.

Not many documented examples, maybe this socket client would be a good example to follow: http://blog.kevindoran.co/bluetooth-programming-with-python-3/

There is also a useful API in the Blue Dot library:

https://bluedot.readthedocs.io/en/latest/btcommapi.html#bluetoothclient

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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