mirror of
https://github.com/thetechprepper/emcomm-tools-os-community.git
synced 2026-09-17 15:41:44 -04:00
BTECH UV PRO - Replaced manual pairing method with an automated approach
This commit is contained in:
@@ -67,14 +67,14 @@ get_mac_or_exit () {
|
|||||||
|
|
||||||
update_ax25_conf() {
|
update_ax25_conf() {
|
||||||
|
|
||||||
[ -z "$ET_USER_CONFIG" ] && ET_USER_CONFIG="${HOME}/.config/emcomm-tools/user.json"
|
[ -z "$ET_USER_CONFIG" ] && ET_USER_CONFIG="${HOME}/.config/emcomm-tools/user.json"
|
||||||
|
|
||||||
CALLSIGN=$(cat ${ET_USER_CONFIG} | jq -r .callsign)
|
CALLSIGN=$(cat ${ET_USER_CONFIG} | jq -r .callsign)
|
||||||
|
|
||||||
if [ "${CALLSIGN}" = "N0CALL" ]; then
|
if [ "${CALLSIGN}" = "N0CALL" ]; then
|
||||||
echo -e "${RED}No callsign set. Run et-user first.${NC}"
|
error_message "No callsign set. Run et-user first."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GREP_OUT=$(grep ${AX25_PORT} ${AX25_CONF_FILE})
|
GREP_OUT=$(grep ${AX25_PORT} ${AX25_CONF_FILE})
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
@@ -85,7 +85,7 @@ update_ax25_conf() {
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${BLUE}Adding AX25 port for ${CALLSIGN}${NC}"
|
info_message "Adding AX25 port for ${CALLSIGN}"
|
||||||
echo "pkt1200 ${CALLSIGN} 1200 255 2 1200 Packet" >> ${AX25_CONF_FILE}
|
echo "pkt1200 ${CALLSIGN} 1200 255 2 1200 Packet" >> ${AX25_CONF_FILE}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ stop_all_services() {
|
|||||||
|
|
||||||
sleep 3
|
sleep 3
|
||||||
|
|
||||||
PS_OUT=$(ps -ef | grep [r]fcomm)
|
PS2_OUT=$(ps -ef | grep [r]fcomm)
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
info_message "Killing rfcomm process(es)..."
|
info_message "Killing rfcomm process(es)..."
|
||||||
sudo killall rfcomm
|
sudo killall rfcomm
|
||||||
@@ -116,7 +116,7 @@ case $1 in
|
|||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
PAIR_STATUS=$(bluetoothctl info "${MAC}" | grep "Paired:" | awk '{print $2}')
|
PAIR_STATUS=$(bluetoothctl info "${MAC}" | grep "Paired:" | awk '{print $2}')
|
||||||
if [ "${PAIR_STATUS}" == "yes" ]; then
|
if [ "${PAIR_STATUS}" == "yes" ]; then
|
||||||
error_message "Device with MAC=${MAC} is already paired."
|
error_message "Device with MAC ${MAC} is already paired."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -126,7 +126,7 @@ case $1 in
|
|||||||
echo -e "2. Goto Menu > Pairing and press OK"
|
echo -e "2. Goto Menu > Pairing and press OK"
|
||||||
read -p "3. Press [ENTER] when done."
|
read -p "3. Press [ENTER] when done."
|
||||||
|
|
||||||
echo -e "${BLUE}Searching for ${DEVICE_NAME}...${NC}"
|
info_message "Searching for ${DEVICE_NAME}..."
|
||||||
|
|
||||||
HCI_OUT=$(hcitool scan | grep "${DEVICE_NAME}")
|
HCI_OUT=$(hcitool scan | grep "${DEVICE_NAME}")
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
@@ -136,17 +136,34 @@ case $1 in
|
|||||||
|
|
||||||
MAC=$(echo ${HCI_OUT} | awk '{print $1}')
|
MAC=$(echo ${HCI_OUT} | awk '{print $1}')
|
||||||
|
|
||||||
# Update configuration file
|
# Update configuration file detected MAC address
|
||||||
sed -i "s|.*mac.*| \"mac\": \"${MAC}\"|g" ${ACTIVE_RADIO}
|
sed -i "s|.*mac.*| \"mac\": \"${MAC}\"|g" ${ACTIVE_RADIO}
|
||||||
|
|
||||||
echo -e "Now, run the ${YELLOW}bluetooth${NC} command in another terminal.\n"
|
# Generate an expect script to automatically pair our device.
|
||||||
|
PAIR_SCRIPT="/tmp/pair.sh"
|
||||||
|
|
||||||
echo -e "${BLUE}[bluetooth]# ${YELLOW}power on${NC}"
|
cat <<EOF > $PAIR_SCRIPT
|
||||||
echo -e "${BLUE}[bluetooth]# ${YELLOW}scan on${NC}\n"
|
#!/usr/bin/expect -f
|
||||||
echo -e "Wait until ${DEVICE_NAME} appears.\n"
|
|
||||||
echo -e "${BLUE}[bluetooth]# ${YELLOW}trust ${MAC}${NC}"
|
set device "${MAC}"
|
||||||
echo -e "${BLUE}[bluetooth]# ${YELLOW}pair ${MAC}${NC}"
|
set timeout 60
|
||||||
echo -e "${BLUE}[${DEVICE_NAME}]# ${YELLOW}quit${NC}"
|
|
||||||
|
spawn bluetoothctl
|
||||||
|
expect "Agent registered"
|
||||||
|
send "power on\r"
|
||||||
|
expect "Changing power on succeeded"
|
||||||
|
send "scan on\r"
|
||||||
|
expect "${MAC}"
|
||||||
|
send "pair ${MAC}\r"
|
||||||
|
expect "Pairing successful"
|
||||||
|
send "trust ${MAC}\r"
|
||||||
|
expect "trust succeeded"
|
||||||
|
send "exit\r"
|
||||||
|
expect eof
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod 700 ${PAIR_SCRIPT}
|
||||||
|
${PAIR_SCRIPT}
|
||||||
|
|
||||||
;;
|
;;
|
||||||
unpair)
|
unpair)
|
||||||
@@ -158,7 +175,7 @@ case $1 in
|
|||||||
|
|
||||||
PAIR_STATUS=$(bluetoothctl info "${MAC}")
|
PAIR_STATUS=$(bluetoothctl info "${MAC}")
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
error_message "No ${MAC} device found. Can't unpair."
|
error_message "No device with ${MAC} found. Can't unpair."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -168,7 +185,7 @@ case $1 in
|
|||||||
|
|
||||||
echo -e "${YELLOW}"
|
echo -e "${YELLOW}"
|
||||||
echo -e "You may also want to remove this device from your UV PRO"
|
echo -e "You may also want to remove this device from your UV PRO"
|
||||||
echo -e "under Menu > General Settings> Connection > Paired Devices."
|
echo -e "under Menu > General Settings > Connection > Paired Devices."
|
||||||
echo -e "${NC}"
|
echo -e "${NC}"
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Author : Gaston Gonzalez
|
# Author : Gaston Gonzalez
|
||||||
# Date : 27 March 2023
|
# Date : 27 March 2023
|
||||||
# Updated : 1 January 2025
|
# Updated : 3 January 2025
|
||||||
# Purpose : Install packet packages
|
# Purpose : Install packet packages
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ et-log "Installing AX.25 packages..."
|
|||||||
apt install \
|
apt install \
|
||||||
ax25-tools \
|
ax25-tools \
|
||||||
ax25-apps \
|
ax25-apps \
|
||||||
|
expect \
|
||||||
-y
|
-y
|
||||||
|
|
||||||
et-log "Installing rfcomm sudoers rules..."
|
et-log "Installing rfcomm sudoers rules..."
|
||||||
|
|||||||
Reference in New Issue
Block a user