#!/usr/bin/env python3 """ Test client for RP2040-ETH WS2812 Network Control Sends color commands to the RP2040-ETH board """ import socket import sys import time # RP2040-ETH configuration HOST = '192.168.1.200' # The RP2040-ETH IP address PORT = 1000 # The port used by the RP2040-ETH def send_command(sock, command): """Send a command and receive response""" print(f"Sending: {command}") sock.send(command.encode()) # Wait for response sock.settimeout(1.0) try: response = sock.recv(1024) print(f"Received: {response.decode()}") except socket.timeout: print("No response received") def main(): # Create a TCP socket with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: try: # Connect to server print(f"Connecting to {HOST}:{PORT}") sock.connect((HOST, PORT)) print("Connected!") # Demo sequence commands = [ "RED", "GREEN", "BLUE", "WHITE", "RGB:255,128,0", # Orange "RGB:128,0,255", # Purple "RGB:0,255,128", # Cyan-green "OFF" ] for cmd in commands: send_command(sock, cmd) time.sleep(2) # Wait 2 seconds between commands except ConnectionRefusedError: print(f"Connection refused. Make sure the RP2040-ETH is running and accessible at {HOST}:{PORT}") except Exception as e: print(f"Error: {e}") if __name__ == "__main__": if len(sys.argv) > 1: # Allow custom command from command line with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.connect((HOST, PORT)) send_command(sock, sys.argv[1]) else: # Run demo sequence main()