more ble installer refinements

This commit is contained in:
agessaman 2025-10-13 21:30:08 -07:00
parent b8c673498a
commit a88686207d
2 changed files with 20 additions and 2 deletions

View file

@ -21,9 +21,26 @@ async def check_pairing_and_connect(address, name, pin=None):
try:
print(f"Checking pairing status for {name} ({address})...", file=sys.stderr, flush=True)
# Check if device is available/visible first
print(f"Checking if device {address} is available...", file=sys.stderr, flush=True)
# Quick scan to verify device is still visible
try:
from bleak import BleakScanner
print("Scanning for device availability...", file=sys.stderr, flush=True)
devices = await BleakScanner.discover(timeout=5.0)
device_found = any(device.address.upper() == address.upper() for device in devices)
if device_found:
print(f"Device {address} is visible and available", file=sys.stderr, flush=True)
else:
print(f"Device {address} not found in scan - may be busy or out of range", file=sys.stderr, flush=True)
except Exception as e:
print(f"Could not scan for device availability: {e}", file=sys.stderr, flush=True)
# Try to connect without PIN first (with timeout)
try:
print(f"Attempting to connect to {name} ({address}) without PIN...", file=sys.stderr, flush=True)
print(f"Connection timeout set to 25 seconds...", file=sys.stderr, flush=True)
# Create the connection with a reasonable timeout
meshcore = await asyncio.wait_for(

View file

@ -305,12 +305,13 @@ handle_ble_pairing() {
if command -v bluetoothctl &> /dev/null; then
print_info "Ensuring device is disconnected before pairing check..."
bluetoothctl disconnect "$device_address" 2>/dev/null || true
sleep 2
print_info "Waiting for device to become available..."
sleep 5 # Increased wait time for device to become available
fi
# Check pairing status first (with timeout to prevent hanging)
local pairing_output
if pairing_output=$(timeout 30 python3 "$temp_script" "$device_address" "$device_name" 2>/tmp/ble_pairing_error); then
if pairing_output=$(timeout 45 python3 "$temp_script" "$device_address" "$device_name" 2>/tmp/ble_pairing_error); then
local pairing_status=$(echo "$pairing_output" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['status'])" 2>/dev/null)
if [ "$pairing_status" = "paired" ]; then