The agent now drives the matrix in <1s via the resident responder instead of compiling+flashing a sketch (~95s). Pieces: - matrix-relay/: a tiny container (python-apps-base) running relay.py — a TCP:9999 → RouterBridge relay. The ZeroClaw daemon runs on the host for hardware access, but the RouterBridge python binding (arduino.app_utils) only ships in the App Lab image, so JUST the relay runs containerized, mounting the router socket + publishing :9999 to loopback. - config.template.toml: add matrix_pattern + matrix_text to the default risk profile's allowed_tools/auto_approve (the capability filter hides tools not listed — this was why matrix_text wasn't exposed to the agent). - skills/led-matrix: lead with "use matrix_text / matrix_pattern first"; only flash for custom frames (flashing overwrites the responder). NOTE skills load from each agent's workspace copy, not shared/skills — push to all workspaces. - provision-host-daemon.sh: flash the responder once + start the relay. Proven on-hardware: "show a heart" and "scroll GO CLAWS" both instant via the agent, no flash. Co-Authored-By: Claude Opus 4.8 <[email protected]>
65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
# matrix-relay — a tiny TCP:9999 → RouterBridge relay for the resident MCU sketch.
|
|
#
|
|
# The ZeroClaw daemon runs on the HOST (for full hardware access), but its
|
|
# matrix_pattern / matrix_text tools speak a simple line protocol to :9999, and
|
|
# the actual MCU is reached via the Arduino RouterBridge (msgpack-rpc over
|
|
# /run/arduino-router.sock) whose python binding (arduino.app_utils) only ships
|
|
# in the App Lab container image. So we run JUST this relay in a minimal
|
|
# container that mounts the router socket and publishes :9999 to the host.
|
|
#
|
|
# Protocol (one line per connection):
|
|
# ping -> pong
|
|
# matrix <0-7> -> Bridge.call("matrix_set", id) preset animation
|
|
# text <words...> -> Bridge.call("matrix_text", str) scroll text
|
|
# gpio_write <p> <v>-> Bridge.call("digitalWrite", p, v)
|
|
# gpio_read <p> -> Bridge.call("digitalRead", p) -> value
|
|
import socket
|
|
import threading
|
|
from arduino.app_utils import Bridge # RouterBridge client (container-only binding)
|
|
|
|
PORT = 9999
|
|
|
|
|
|
def handle(conn):
|
|
try:
|
|
data = conn.recv(256).decode().strip()
|
|
parts = data.split()
|
|
cmd = parts[0].lower() if parts else ""
|
|
if cmd == "ping":
|
|
conn.sendall(b"pong\n")
|
|
elif cmd == "matrix" and len(parts) >= 2:
|
|
Bridge.call("matrix_set", int(parts[1]))
|
|
conn.sendall(b"ok\n")
|
|
elif cmd == "text" and len(parts) >= 2:
|
|
Bridge.call("matrix_text", " ".join(parts[1:]))
|
|
conn.sendall(b"ok\n")
|
|
elif cmd == "gpio_write" and len(parts) >= 3:
|
|
Bridge.call("digitalWrite", int(parts[1]), int(parts[2]))
|
|
conn.sendall(b"ok\n")
|
|
elif cmd == "gpio_read" and len(parts) >= 2:
|
|
conn.sendall(f"{Bridge.call('digitalRead', int(parts[1]))}\n".encode())
|
|
else:
|
|
conn.sendall(b"error: invalid command\n")
|
|
except Exception as e:
|
|
try:
|
|
conn.sendall(f"error: {e}\n".encode())
|
|
except Exception:
|
|
pass
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def main():
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
s.bind(("0.0.0.0", PORT))
|
|
s.listen(5)
|
|
print(f"matrix-relay listening on :{PORT}", flush=True)
|
|
while True:
|
|
conn, _ = s.accept()
|
|
threading.Thread(target=handle, args=(conn,), daemon=True).start()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|