Improved messaging and included wifi timeout

This commit is contained in:
Eric Ratliff
2026-01-24 13:24:00 -06:00
parent 7684db62ab
commit 26c1441acb

View File

@@ -293,68 +293,114 @@ if ! command -v adb &> /dev/null; then
exit 1
fi
echo "Checking for Control Hub connection..."
INSTALLED=false
# Try USB first
if [ "$FORCE_WIFI" != "true" ]; then
USB_COUNT=$(adb devices | grep -v "List" | grep "device$" | wc -l)
USB_COUNT=$(adb devices 2>/dev/null | grep -v "List" | grep -E "device$|unauthorized$" | wc -l)
if [ "$USB_COUNT" -gt 0 ]; then
# Check if authorized
if adb devices 2>/dev/null | grep -q "unauthorized"; then
echo ""
echo "════════════════════════════════════════════════════════════════"
echo " USB Device Found but Unauthorized"
echo "════════════════════════════════════════════════════════════════"
echo ""
echo "A Control Hub is connected via USB but not authorized."
echo ""
echo "To fix:"
echo " 1. Check the Control Hub screen"
echo " 2. Allow USB debugging when prompted"
echo " 3. Run this script again"
echo ""
exit 1
fi
echo "✓ Control Hub connected via USB"
if adb install -r "$APK_PATH"; then
if adb install -r "$APK_PATH" 2>&1; then
INSTALLED=true
fi
elif [ "$FORCE_USB" = "true" ]; then
echo ""
echo "Error: No USB device found (--usb specified)"
echo "════════════════════════════════════════════════════════════════"
echo " No USB Device Found"
echo "════════════════════════════════════════════════════════════════"
echo ""
echo "No Control Hub detected via USB (--usb specified)."
echo ""
echo "Make sure:"
echo " • Control Hub is powered on"
echo " • USB cable is connected"
echo " • USB debugging is enabled"
echo ""
echo "Check connection: adb devices"
echo ""
exit 1
fi
fi
# Try WiFi if USB didn't work
if [ "$INSTALLED" = "false" ] && [ "$FORCE_USB" != "true" ]; then
echo "Connecting to Control Hub via WiFi ($CONTROL_HUB_IP:$CONTROL_HUB_PORT)..."
adb connect "$CONTROL_HUB_IP:$CONTROL_HUB_PORT" 2>&1 | grep -v "cannot connect" || true
sleep 2
if adb devices | grep -q "$CONTROL_HUB_IP"; then
echo "No USB connection. Trying WiFi at $CONTROL_HUB_IP:$CONTROL_HUB_PORT..."
# Try to connect with timeout
adb connect "$CONTROL_HUB_IP:$CONTROL_HUB_PORT" &>/dev/null &
ADB_CONNECT_PID=$!
# Wait up to 5 seconds for connection
for i in {1..10}; do
if ! kill -0 $ADB_CONNECT_PID 2>/dev/null; then
break
fi
sleep 0.5
done
# Kill if still running
kill $ADB_CONNECT_PID 2>/dev/null || true
# Check if connected
if adb devices 2>/dev/null | grep -q "$CONTROL_HUB_IP"; then
echo "✓ Connected via WiFi"
if adb install -r "$APK_PATH"; then
if adb install -r "$APK_PATH" 2>&1; then
INSTALLED=true
fi
else
echo "✗ Could not connect to Control Hub"
fi
fi
if [ "$INSTALLED" = "false" ]; then
echo ""
echo "════════════════════════════════════════════════════════════════"
echo " Error: Could Not Connect to Control Hub"
echo " No Control Hub Found"
echo "════════════════════════════════════════════════════════════════"
echo ""
echo "Connection options:"
echo "Could not detect a Control Hub via USB or WiFi."
echo ""
echo "1. USB (Recommended)"
echo " • Plug Control Hub into computer"
echo " • Run: $0 --usb"
echo "APK was built successfully at:"
echo " $APK_PATH"
echo ""
echo "2. WiFi Direct"
echo " • Connect to 'FIRST-xxxx-RC' network"
echo " • Run: $0 --wifi"
echo " • Default IP: 192.168.43.1"
echo "To install later:"
echo ""
echo "3. Custom Network"
echo " • Find Control Hub IP on your network"
echo " Run: $0 -i YOUR_IP"
echo "Option 1: USB Connection"
echo " 1. Connect Control Hub via USB"
echo " 2. Run: adb install -r \"$APK_PATH\""
echo ""
echo "Debug:"
echo " • Check devices: adb devices"
echo " • Test connection: adb connect $CONTROL_HUB_IP:$CONTROL_HUB_PORT"
echo "Option 2: WiFi Connection"
echo " 1. Connect to Control Hub WiFi network"
echo " 2. Run: adb connect 192.168.43.1:5555"
echo " 3. Run: adb install -r \"$APK_PATH\""
echo ""
exit 1
echo "Option 3: Run this script again when connected"
echo " ./deploy-to-robot.sh"
echo ""
echo "Option 4: Custom IP"
echo " ./deploy-to-robot.sh -i YOUR_IP"
echo ""
echo "════════════════════════════════════════════════════════════════"
echo ""
exit 0
fi
echo ""