'How to automatically pair an iPhone to a unix machine using bluetooth without having to click connection confirmation dialogs on the unix device?

I have a raspberry pi that is running Raspbian on a Raspberry Pi 4 B.

One of the requirements is to try to initiate a bluetooth internet connection from a hot spot served by an iOS device and to have it automatically connect to the iOS device's hot spot, but without any user intervention other than plugging in power to the pi, and clicking a button with the 12-digit hexadecimal code in a app on the user's phone that is initiating the hot spot.

I have managed to do this in separate pieces but not without some kind of dialog popping up or multiple button presses from the iphone. I have the following script, it sometimes works but sometimes does not:

sudo /usr/bin/bluetoothctl remove $1
sudo /usr/bin/bluetoothctl power on
sudo /usr/bin/bluetoothctl discoverable on
sudo /usr/bin/bluetoothctl pairable on
sudo /usr/bin/bluetoothctl agent NoInputNoOutput
sudo /usr/bin/bluetoothctl default-agent
sudo /usr/bin/bluetoothctl scan on
sudo /usr/bin/bluetoothctl pair $1
sudo /usr/bin/bluetoothctl trust $1
sudo /usr/bin/bluetoothctl connect $1
cd /bin


BT_MAC_ADDR=F4:5C:89:8B:10:E8
bt-pan client -r $BT_MAC_ADDR

bt-pan is a python application that tries to establish a connection to a hot spot from a connected device, I believe.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source