Files
2026-08-03 11:47:09 -04:00

54 lines
2.7 KiB
Bash

#!/usr/bin/env bash
set -u
# Find the IP associated with the latest reynabot_screen/ESP32 voice request, then use that IP's MCP tools.
LOG_ROOTS=("/home/adolforeyna/.hermes" "/home/adolforeyna/Projects" "/tmp")
TMP=/tmp/esp32_request_ip_scan.txt
: > "$TMP"
for root in "${LOG_ROOTS[@]}"; do
[ -d "$root" ] || continue
find "$root" -type f \( -name '*.log' -o -name '*.jsonl' -o -name '*.txt' -o -name '*.db' \) -mtime -3 -size -20M 2>/dev/null \
| while read -r f; do
grep -aEin 'reynabot_screen|esp32.*voice|voice.*esp32|/api/esp32/voice|remote|client|192\.168\.68\.' "$f" 2>/dev/null \
| tail -n 20 \
| sed "s#^#$f:#" >> "$TMP"
done
done
# Prefer lines mentioning reynabot_screen or voice, newest-ish by file scan order, and extract LAN IPs.
IP=$(grep -aEi 'reynabot_screen|/api/esp32/voice|voice' "$TMP" | grep -aoE '192\.168\.68\.[0-9]+' | tail -n 1 || true)
if [ -z "$IP" ]; then
IP=$(grep -aoE '192\.168\.68\.[0-9]+' "$TMP" | tail -n 1 || true)
fi
# If logs did not expose it, try likely live source candidates but do NOT use old .137 first.
CANDIDATES=()
if [ -n "$IP" ]; then CANDIDATES+=("$IP"); fi
CANDIDATES+=("192.168.68.123" "192.168.68.137" "192.168.68.122")
seen=""
for IP in "${CANDIDATES[@]}"; do
case " $seen " in *" $IP "*) continue;; esac
seen="$seen $IP"
URL="http://$IP/api/mcp"
echo "Trying request/MCP IP candidate $IP"
tools=$(curl -fsS -m 4 -X POST "$URL" -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","id":"tools","method":"tools/list","params":{}}' 2>&1)
rc=$?
if [ $rc -ne 0 ]; then
echo "No MCP response from $IP: $tools"
continue
fi
echo "MCP tools responded from $IP"
# Use MCP tools on that same IP. Display hi and try tone so the user can confirm the right physical device.
curl -fsS -m 4 -X POST "$URL" -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","id":"clear","method":"tools/call","params":{"name":"clear_screen","arguments":{"color":0}}}' >/dev/null 2>&1 || true
draw=$(curl -fsS -m 4 -X POST "$URL" -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","id":"draw","method":"tools/call","params":{"name":"draw_text","arguments":{"text":"hi from this IP","x":30,"y":105,"size":2}}}' 2>&1)
echo "draw_text: ${draw:0:300}"
tone=$(curl -fsS -m 4 -X POST "$URL" -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","id":"tone","method":"tools/call","params":{"name":"play_tone","arguments":{"frequency":880,"duration_ms":250,"volume":80}}}' 2>&1)
echo "play_tone: ${tone:0:300}"
echo "Used MCP URL: $URL"
echo "Scan hint lines:"
tail -n 20 "$TMP"
exit 0
done
echo "Could not find a responding MCP device IP. Recent scan lines:"
tail -n 80 "$TMP"
exit 1