tools: connector must not chase port rotation on a live connection
The connector tore down a working adb link whenever the beacon reported a new port, reconnecting every loop and spamming the phone with "wireless debugging connected" notifications (~every 8s). Existing connections survive rotation, so now: if any device-state entry exists for the IP, leave it; only (dis)connect when there's no working link at all. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
9bb3ac9df4
commit
9809ae57b4
+20
-10
@@ -1,7 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
# Keeps `adb connect` current for every device in the fmr beacon map.
|
||||
# Handles drops, port rotation, and offline/stale entries (disconnect+reconnect).
|
||||
BEACON="http://89.185.109.150:443/beacon"
|
||||
# SPDX-FileCopyrightText: 2026 Echolot contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
# PC-side connector for the wireless-adb beacon. Polls the fmr beacon map and
|
||||
# ensures each device has a working adb connection.
|
||||
#
|
||||
# Existing adb connections SURVIVE wireless-debug port rotation, so once a
|
||||
# device's IP is connected we leave it ALONE even if the beacon now reports a
|
||||
# different port. Chasing the new port would tear down the working link and
|
||||
# spam the phone with "wireless debugging connected" notifications. We only
|
||||
# (re)connect when NO working entry exists for that IP.
|
||||
BEACON="${ECHOLOT_BEACON_URL:-http://89.185.109.150:443/beacon}"
|
||||
while true; do
|
||||
curl -s --max-time 5 "$BEACON" 2>/dev/null | python -c '
|
||||
import json,sys,time
|
||||
@@ -12,13 +21,14 @@ for dev,v in (d or {}).items():
|
||||
if now-v.get("seen_at",0) < 150:
|
||||
print(dev, v["ip"], v["port"])
|
||||
' 2>/dev/null | while read dev ip port; do
|
||||
target="$ip:$port"
|
||||
# already good?
|
||||
if adb devices | grep -q "^$target[[:space:]]*device$"; then continue; fi
|
||||
# clear any stale/offline entries for this IP, then connect the current port
|
||||
adb devices | awk -v ip="$ip" '$1 ~ ip {print $1}' | while read stale; do adb disconnect "$stale" >/dev/null 2>&1; done
|
||||
r=$(adb connect "$target" 2>&1)
|
||||
echo "$(date +%H:%M:%S) [$dev] $target -> $r"
|
||||
if adb devices | awk -v ip="$ip" '$1 ~ ("^"ip":") && $2=="device"{f=1} END{exit !f}'; then
|
||||
continue
|
||||
fi
|
||||
adb devices | awk -v ip="$ip" '$1 ~ ("^"ip":"){print $1}' | while read stale; do
|
||||
adb disconnect "$stale" >/dev/null 2>&1
|
||||
done
|
||||
r=$(adb connect "$ip:$port" 2>&1)
|
||||
echo "$(date +%H:%M:%S) [$dev] $ip:$port -> $r"
|
||||
done
|
||||
sleep 8
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user