improve manage.sh & add step to connect-drone: wait for drone before dhcp
This commit is contained in:
18
README.md
Normal file
18
README.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Preparations before Flight
|
||||||
|
* turn uadis hotpot on
|
||||||
|
* plugin xiaomi repeater "_plus" to powers source
|
||||||
|
* connect rpi to power source
|
||||||
|
* wait for boot and ams vpn connection
|
||||||
|
* until connected devices @uadis increment +1 with device name "uad"
|
||||||
|
|
||||||
|
* manual setup:
|
||||||
|
* ssh into
|
||||||
|
* cd tello-commander
|
||||||
|
* source venv/bin/activate
|
||||||
|
* ./manage.sh connect-drone
|
||||||
|
* ifconfig: check if wlan1 is up
|
||||||
|
* ./manage.sh start-commander
|
||||||
|
* start drone
|
||||||
|
* until repeater lights blue without blinking
|
||||||
|
* ./manage.sh get-dhcp
|
||||||
|
* ./manage start-talikng
|
||||||
47
manage.sh
47
manage.sh
@@ -1,13 +1,26 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
######################
|
||||||
|
## SCRIPT INIT
|
||||||
|
######################
|
||||||
DRONE_INTERFACE=$(yq '.commander.drone_interface' < settings/admin.yml)
|
DRONE_INTERFACE=$(yq '.commander.drone_interface' < settings/admin.yml)
|
||||||
DRONE_WPA_SUPP_CONF=$(yq '.commander.drone_wpa_supp' < settings/admin.yml)
|
DRONE_WPA_SUPP_CONF=$(yq '.commander.drone_wpa_supp' < settings/admin.yml)
|
||||||
NET_INTERFACE=$(yq '.commander.net_interface' < settings/admin.yml)
|
NET_INTERFACE=$(yq '.commander.net_interface' < settings/admin.yml)
|
||||||
NET_WPA_SUPP_CONF=$(yq '.commander.net_wpa_supp' < settings/admin.yml)
|
NET_WPA_SUPP_CONF=$(yq '.commander.net_wpa_supp' < settings/admin.yml)
|
||||||
ENV_FOR_DYNACONF=$(yq '.commander.env_for_dynaconf' < settings/admin.yml)
|
ENV_FOR_DYNACONF=$(yq '.commander.env_for_dynaconf' < settings/admin.yml)
|
||||||
|
|
||||||
|
pids_dir='./pids'
|
||||||
|
if [[ ! -d "$pids_dir" ]]; then
|
||||||
|
mkdir $pids_dir
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
######################
|
||||||
|
## COMMAND FUNCTIONS
|
||||||
|
######################
|
||||||
list_related_network_interface_status() {
|
list_related_network_interface_status() {
|
||||||
networkctl list
|
networkctl list
|
||||||
}
|
}
|
||||||
@@ -21,6 +34,13 @@ connect_using_wpa_supp() {
|
|||||||
sudo wpa_supplicant -D nl80211 -i $DRONE_INTERFACE -c network/$DRONE_WPA_SUPP_CONF
|
sudo wpa_supplicant -D nl80211 -i $DRONE_INTERFACE -c network/$DRONE_WPA_SUPP_CONF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wait_for_drone() {
|
||||||
|
while ! ping -c1 192.168.10.1 &>/dev/null; do
|
||||||
|
echo "Drone is offline. Waiting.."; sleep 2
|
||||||
|
done
|
||||||
|
echo "Drone is available, can ask for dhcp"; sleep 1
|
||||||
|
}
|
||||||
|
|
||||||
get_dhcp_ip () {
|
get_dhcp_ip () {
|
||||||
sudo dhclient $DRONE_INTERFACE
|
sudo dhclient $DRONE_INTERFACE
|
||||||
}
|
}
|
||||||
@@ -47,14 +67,9 @@ kill_everything() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
pids_dir='./pids'
|
######################
|
||||||
if [[ ! -d "$pids_dir" ]]; then
|
|
||||||
mkdir $pids_dir
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## NETWORK
|
## NETWORK
|
||||||
|
######################
|
||||||
if [ "$1" == "list-network" ]; then
|
if [ "$1" == "list-network" ]; then
|
||||||
list_related_network_interface_status
|
list_related_network_interface_status
|
||||||
|
|
||||||
@@ -66,6 +81,9 @@ elif [ "$1" == "connect-drone" ]; then
|
|||||||
wpa_supp_pid=$!
|
wpa_supp_pid=$!
|
||||||
echo "started wpa supplicant to connect drone network with PID $wpa_supp_pid"
|
echo "started wpa supplicant to connect drone network with PID $wpa_supp_pid"
|
||||||
echo $wpa_supp_pid > $pids_dir/wpa_supp_pid.txt
|
echo $wpa_supp_pid > $pids_dir/wpa_supp_pid.txt
|
||||||
|
echo "will wait forever until drone is on and connected to repeater"
|
||||||
|
wait_for_drone
|
||||||
|
echo "ok"
|
||||||
|
|
||||||
elif [ "$1" == "disconnect-drone" ]; then
|
elif [ "$1" == "disconnect-drone" ]; then
|
||||||
wpa_supp_pid_file="$pids_dir/wpa_supp_pid.txt"
|
wpa_supp_pid_file="$pids_dir/wpa_supp_pid.txt"
|
||||||
@@ -83,12 +101,13 @@ elif [ "$1" == "get-dhcp" ]; then
|
|||||||
elif [ "$1" == "kill-dhcp" ]; then
|
elif [ "$1" == "kill-dhcp" ]; then
|
||||||
dhcp_ip_pid_file="$pids_dir/dhcp_ip_pid.txt"
|
dhcp_ip_pid_file="$pids_dir/dhcp_ip_pid.txt"
|
||||||
if [ -f "$dhcp_ip_pid_file" ]; then
|
if [ -f "$dhcp_ip_pid_file" ]; then
|
||||||
pkill -P $(cat $dhcp_ip_pid_file)
|
sudo pkill -P $(cat $dhcp_ip_pid_file)
|
||||||
echo "killed dhcp client"
|
echo "killed dhcp client"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
######################
|
||||||
## DEV
|
## DEV
|
||||||
|
######################
|
||||||
elif [ "$1" == "start-jupyter" ]; then
|
elif [ "$1" == "start-jupyter" ]; then
|
||||||
start_jupyter > logs/jupyter.log 2>&1 &
|
start_jupyter > logs/jupyter.log 2>&1 &
|
||||||
jupyter_pid=$!
|
jupyter_pid=$!
|
||||||
@@ -120,9 +139,9 @@ elif [ "$1" == "stop-cs" ]; then
|
|||||||
elif [ "$1" == "stop-all" ]; then
|
elif [ "$1" == "stop-all" ]; then
|
||||||
kill_everything
|
kill_everything
|
||||||
|
|
||||||
|
######################
|
||||||
|
|
||||||
## DRONE
|
## DRONE
|
||||||
|
######################
|
||||||
elif [ "$1" == "start-commander" ]; then
|
elif [ "$1" == "start-commander" ]; then
|
||||||
start_commander_service $2 > logs/commander.log 2>&1 &
|
start_commander_service $2 > logs/commander.log 2>&1 &
|
||||||
commander_pid=$!
|
commander_pid=$!
|
||||||
@@ -133,11 +152,12 @@ elif [ "$1" == "start-commander" ]; then
|
|||||||
elif [ "$1" == "stop-commander" ]; then
|
elif [ "$1" == "stop-commander" ]; then
|
||||||
commander_pid_file="$pids_dir/commander_pid.txt"
|
commander_pid_file="$pids_dir/commander_pid.txt"
|
||||||
if [ -f "$commander_pid_file" ]; then
|
if [ -f "$commander_pid_file" ]; then
|
||||||
pkill -P $(cat $commander_pid_file)
|
|
||||||
sudo killport 8889
|
sudo killport 8889
|
||||||
|
pkill -P $(cat $commander_pid_file)
|
||||||
echo "stopped commander"
|
echo "stopped commander"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
elif [ "$1" == "prepare-flight" ]; then
|
elif [ "$1" == "prepare-flight" ]; then
|
||||||
./manage.sh connect-drone
|
./manage.sh connect-drone
|
||||||
./manage.sh get-dhcp
|
./manage.sh get-dhcp
|
||||||
@@ -153,6 +173,9 @@ elif [ "$1" == "finish-flight" ]; then
|
|||||||
elif [ "$1" == "start-talking" ]; then
|
elif [ "$1" == "start-talking" ]; then
|
||||||
talk_to_drone
|
talk_to_drone
|
||||||
|
|
||||||
|
######################
|
||||||
|
## INFO
|
||||||
|
######################
|
||||||
else
|
else
|
||||||
echo "Invalid command. Please use one of:
|
echo "Invalid command. Please use one of:
|
||||||
- list-network
|
- list-network
|
||||||
|
|||||||
Reference in New Issue
Block a user