Skip to content

Commit 48ce444

Browse files
committed
updated bt scripts #2
1 parent 9ef9cdd commit 48ce444

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

scripts/bt-expect.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
set timeout 120
44

55
set prompt "#"
6-
set address [lindex $argv 0]
76

87
spawn sudo bluetoothctl -a
98
expect -re $prompt
@@ -34,6 +33,9 @@ expect -re $prompt
3433
send "pairable on\r"
3534
sleep 1
3635

36+
expect -re "[NEW] Device\w(.+)\w"
37+
set address $expect_out(1,string)
38+
3739
expect -re "Enter PIN code: "
3840
send "3434\r"
3941

@@ -43,8 +45,15 @@ send "trust $address\r"
4345
sleep 2
4446

4547
expect -re "trust succeeded"
46-
sleep 3
48+
sleep 1
49+
50+
expect -re $prompt
51+
send "discoverable off\r"
52+
sleep 1
53+
54+
expect -re $prompt
55+
send "pairable off\r"
56+
sleep 1
4757

48-
send_user "\nShould be paired now.\r"
4958
send "quit\r"
5059
expect eof

scripts/bt-setup.sh

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,17 @@ echo "Activating bluetooth pairing mode"
2626

2727
sudo hciconfig hci0 sspmode 0
2828

29-
sudo btmgmt connectable yes
30-
sudo btmgmt discov yes
31-
sudo btmgmt pairable yes
32-
33-
sudo killall -9 bt-agent
34-
35-
echo "Bluetooth device is now discoverable"
36-
echo
3729
echo "Open ${bold}bluetooth settings${normal} on your phone to search for and ${bold}pair${normal} with this device"
3830
echo "If you have already paired it on your phone, please unpair it first, then pair again"
3931
echo
40-
printf "Waiting for connection.."
41-
42-
btdevice=
43-
while [[ -z "$btdevice" ]]
44-
do
45-
printf "."
46-
sleep 1
47-
btdevice=`sudo bt-device -l | grep -e \(.*\)`
48-
done
49-
50-
mac=`echo $btdevice | cut -d'(' -f2 | cut -d')' -f1`
5132

5233
/usr/bin/expect -f /home/pi/omnipy/bt-expect.sh
5334

54-
sudo btmgmt discov no
55-
sudo btmgmt pairable no
56-
5735
sudo hciconfig hci0 sspmode 1
5836

37+
btdevice=`sudo bt-device -l | grep -e \(.*\)`
38+
mac=`echo $btdevice | cut -d'(' -f2 | cut -d')' -f1`
39+
5940
echo
6041

6142
echo "${bold}Paired with $btdevice.${normal}"

0 commit comments

Comments
 (0)