24 lines
1.2 KiB
Bash
Executable File
24 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# Gibt die Adresse der erreichbaren Lichtzentrale aus: zuerst playbot (Pi), sonst das Handy (WLED-App):
|
|
# feste Adresse in der Fritz!Box, dann mDNS. Unterwegs erreicht der Mac playbot über das Tailnet (rpi.ts.robbis.space).
|
|
# Andere Pi-Adressen zum Testen: LZ_PI_URLS="http://... http://..." finden.sh
|
|
for url in ${LZ_PI_URLS:-http://playbot.local:8090 http://192.168.178.145:8090 http://rpi.ts.robbis.space:8090} \
|
|
${LZ_HANDY_URLS:-http://lichtzentrale-handy.fritz.box:8090}; do
|
|
if curl -s -m 2 -o /dev/null -w '%{http_code}' "$url/api/version" | grep -q 200; then
|
|
echo "$url"; exit 0
|
|
fi
|
|
done
|
|
# Handy: dns-sd beendet sich nicht von selbst, darum nach 3 Sekunden abbrechen
|
|
tmp=$(mktemp)
|
|
dns-sd -L lichtzentrale-handy _lichtzentrale._tcp local. > "$tmp" 2>/dev/null &
|
|
pid=$!
|
|
sleep 3
|
|
kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null
|
|
target=$(grep -o 'reached at [^ ]*' "$tmp" | head -1 | sed 's/reached at //; s/\.:/:/')
|
|
rm -f "$tmp"
|
|
if [ -n "$target" ] && curl -s -m 3 -o /dev/null -w '%{http_code}' "http://$target/api/version" | grep -q 200; then
|
|
echo "http://$target"; exit 0
|
|
fi
|
|
echo "Keine Lichtzentrale erreichbar (weder playbot noch Handy)" >&2
|
|
exit 1
|