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
|
||||
@@ -12,7 +12,7 @@ class CommandHandler:
|
||||
def __init__(self):
|
||||
self.COMMANDER_COMMANDS_URL = f"{settings.COMMANDER_ROOT_URL}/command"
|
||||
self._check_commander_health()
|
||||
|
||||
|
||||
def _check_commander_health(self):
|
||||
try:
|
||||
response = requests.get(f"{settings.COMMANDER_ROOT_URL}/test/health")
|
||||
|
||||
47
manage.sh
47
manage.sh
@@ -1,13 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
######################
|
||||
## SCRIPT INIT
|
||||
######################
|
||||
DRONE_INTERFACE=$(yq '.commander.drone_interface' < 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_WPA_SUPP_CONF=$(yq '.commander.net_wpa_supp' < 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() {
|
||||
networkctl list
|
||||
}
|
||||
@@ -21,6 +34,13 @@ connect_using_wpa_supp() {
|
||||
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 () {
|
||||
sudo dhclient $DRONE_INTERFACE
|
||||
}
|
||||
@@ -47,14 +67,9 @@ kill_everything() {
|
||||
|
||||
|
||||
|
||||
pids_dir='./pids'
|
||||
if [[ ! -d "$pids_dir" ]]; then
|
||||
mkdir $pids_dir
|
||||
fi
|
||||
|
||||
|
||||
|
||||
######################
|
||||
## NETWORK
|
||||
######################
|
||||
if [ "$1" == "list-network" ]; then
|
||||
list_related_network_interface_status
|
||||
|
||||
@@ -66,6 +81,9 @@ elif [ "$1" == "connect-drone" ]; then
|
||||
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 "will wait forever until drone is on and connected to repeater"
|
||||
wait_for_drone
|
||||
echo "ok"
|
||||
|
||||
elif [ "$1" == "disconnect-drone" ]; then
|
||||
wpa_supp_pid_file="$pids_dir/wpa_supp_pid.txt"
|
||||
@@ -83,12 +101,13 @@ elif [ "$1" == "get-dhcp" ]; then
|
||||
elif [ "$1" == "kill-dhcp" ]; then
|
||||
dhcp_ip_pid_file="$pids_dir/dhcp_ip_pid.txt"
|
||||
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"
|
||||
fi
|
||||
|
||||
|
||||
######################
|
||||
## DEV
|
||||
######################
|
||||
elif [ "$1" == "start-jupyter" ]; then
|
||||
start_jupyter > logs/jupyter.log 2>&1 &
|
||||
jupyter_pid=$!
|
||||
@@ -120,9 +139,9 @@ elif [ "$1" == "stop-cs" ]; then
|
||||
elif [ "$1" == "stop-all" ]; then
|
||||
kill_everything
|
||||
|
||||
|
||||
|
||||
######################
|
||||
## DRONE
|
||||
######################
|
||||
elif [ "$1" == "start-commander" ]; then
|
||||
start_commander_service $2 > logs/commander.log 2>&1 &
|
||||
commander_pid=$!
|
||||
@@ -133,11 +152,12 @@ elif [ "$1" == "start-commander" ]; then
|
||||
elif [ "$1" == "stop-commander" ]; then
|
||||
commander_pid_file="$pids_dir/commander_pid.txt"
|
||||
if [ -f "$commander_pid_file" ]; then
|
||||
pkill -P $(cat $commander_pid_file)
|
||||
sudo killport 8889
|
||||
pkill -P $(cat $commander_pid_file)
|
||||
echo "stopped commander"
|
||||
fi
|
||||
|
||||
|
||||
elif [ "$1" == "prepare-flight" ]; then
|
||||
./manage.sh connect-drone
|
||||
./manage.sh get-dhcp
|
||||
@@ -153,6 +173,9 @@ elif [ "$1" == "finish-flight" ]; then
|
||||
elif [ "$1" == "start-talking" ]; then
|
||||
talk_to_drone
|
||||
|
||||
######################
|
||||
## INFO
|
||||
######################
|
||||
else
|
||||
echo "Invalid command. Please use one of:
|
||||
- list-network
|
||||
|
||||
Reference in New Issue
Block a user