Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Bluetooth automatic pairing on Linux [closed]

I want to use any mobile phone to connect to a IoT device via Bluetooth Classic with the serial port protocol (SPP). The IoT device has no screen and no keyboard, and it's supposed to accept connections automatically as long as the connecting phone knows a secret PIN (ie, I don't want to be forced to ssh into the IoT device to set up pairing every time a new mobile phone tries to connect).

These are the commands that I've run so far on the IoT device:

# Make the device discoverable:
hciconfig hci0 piscan

# Register SPP:
sdptool add --channel=22 SP

# Start rfcomm:
rfcomm -r watch /dev/rfcomm0 22

Unfortunately, I couldn't find any way to set up a PIN, and pairing fails when I try to connect with a mobile phone. In addition, the device is only discoverable for a short interval.

How do I configure the IoT device's Bluetooth stack (running a recent Bluez) to auto pair with any phone that knows a given PIN, and how do I make the discovery period eternal?

like image 474
Jon Smark Avatar asked Sep 02 '25 05:09

Jon Smark


1 Answers

If anyone happens upon this question, to use (much of) the BlueZ "BT Management Sockets" C API directly from bash, try:

btmgmt --help

btmgmt add-device, btmgmt find, btmgmt discov, etc.

like image 163
AndyT Avatar answered Sep 04 '25 19:09

AndyT