-
-
Save higstar/f07614088f7b545ce8fbbd98e213493a to your computer and use it in GitHub Desktop.
Bluetoothctl automation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
set prompt "#" | |
set address [lindex $argv 0] | |
spawn sudo bluetoothctl -a | |
expect -re $prompt | |
send "default-agent\r" | |
expect "Default agent request successful" | |
send "remove $address\r" | |
expect "Device" | |
set timeout 120 | |
send "scan on\r" | |
expect "Discovery started" | |
send_user "\nWaiting for $address to appear...\r" | |
expect "$address" | |
send_user "\nDone waiting\r" | |
send "scan off\r" | |
expect -re $prompt | |
send "pair $address\r" | |
expect { | |
"PIN code:" { | |
send "1234\r" | |
send_user "\nShould be paired now.\r" | |
expect "Paired: yes" | |
} | |
"Failed to pair:" { | |
send_user "\nFailed to pair :(\r" | |
} | |
} | |
send "quit\r" | |
expect eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Removed my pet hate...hard coded sleeps.
Seems to be relatively stable.
I would like to add in an automatic binding (sudo rfcomm bind $available_port $address) but need to figure out how to get $available_port.