-
Notifications
You must be signed in to change notification settings - Fork 9
/
mobi-pair
executable file
·81 lines (72 loc) · 2.01 KB
/
mobi-pair
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#this script attempts to pair a Mobilinkd TNC with the Pi.
#04MARCH2022 KM4ACK
EXISTING=`bluetoothctl paired-devices | grep Mobilinkd`
TMP=/run/user/$UID/mobi.txt
#see if we already have a TNC paired
if [ -n "$EXISTING" ]; then
clear;echo;echo
cat <<EOF
A Mobilinkd TNC is already paired with this pi.
Remove the existing pairing and try again.
EOF
sleep 3
exit 1
fi
if ! hash expect 2>/dev/null; then
echo "We are missing a dependency....expect"
echo "Hang on while it is installed"
echo "You can press ctrl+c to exit"
sleep 3
sudo apt update
sudo apt install -y expect
fi
#create connect script in RAM memory. (Called later from this script)
cat << "MYFILE" > /run/user/$UID/connect
#!/usr/bin/expect -f
set prompt "#"
set address [lindex $argv 0]
spawn sudo bluetoothctl
expect -re $prompt
send "scan on\r"
send_user "\nStandby\r"
sleep 10
send_user "\nStill working\r"
send "scan off\r"
expect "Controller"
send "pair $address\r"
sleep 5
send "1234\r"
sleep 3
send_user "\nShould be paired now.\r"
send "quit\r"
expect eof
MYFILE
chmod +x /run/user/$UID/connect
#give user some feedback
echo;echo; clear
cat <<EOF
####################################################################
# Please stand by while the pairing is attempted. #
# This process takes approximately 60 seconds to complete. #
####################################################################
EOF
#get the TNC of the mobilinkd
echo "Discovering nearby Mobilinkd device....please wait"
hcitool scan > $TMP
echo "Discovery complete. TNC found.";echo
MAC=`grep -i TNC /run/user/$UID/mobi.txt | awk '{print $1}'`
#verify we have a MAC address to work with
if [ -z "$MAC" ]; then
echo "TNC not found. Can't continue!"
echo "Confirm that the TNC is on and has"
echo "a fast flashing blue light."
sleep 5
exit 1
fi
echo "Starting the pairing process....please stand by"
#call the connect script
/run/user/$UID/connect $MAC >/dev/null 2>&1
echo;echo "The pairing was probably successful"
echo "Start the Mobilinkd modem again"
sleep 3