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.

asked May 5, 2020 at 21:32

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

answered Jul 12, 2020 at 16:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.