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?