first and working ethernet

This commit is contained in:
2025-07-26 21:48:13 -04:00
commit 473f9013c0
58 changed files with 3405 additions and 0 deletions

137
test_ethernet.py Normal file
View File

@@ -0,0 +1,137 @@
#!/usr/bin/env python3
"""
Test ethernet connectivity for RP2040-ETH
"""
import socket
import subprocess
import sys
import time
# RP2040-ETH configuration
HOST = '192.168.1.200'
PORT = 1000
def ping_test():
"""Test basic connectivity with ping"""
print(f"1. Testing ping to {HOST}...")
try:
result = subprocess.run(['ping', '-c', '3', HOST],
capture_output=True, text=True, timeout=10)
if result.returncode == 0:
print("✓ Ping successful!")
print(result.stdout)
return True
else:
print("✗ Ping failed")
return False
except subprocess.TimeoutExpired:
print("✗ Ping timeout")
return False
except Exception as e:
print(f"✗ Ping error: {e}")
return False
def tcp_test():
"""Test TCP connection"""
print(f"\n2. Testing TCP connection to {HOST}:{PORT}...")
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex((HOST, PORT))
if result == 0:
print("✓ TCP connection successful!")
# Send a test command
print(" Sending test command 'GREEN'...")
sock.send(b"GREEN")
# Try to receive response
try:
response = sock.recv(1024)
print(f" ✓ Received response: {response.decode()}")
except socket.timeout:
print(" - No response received (timeout)")
sock.close()
return True
else:
print(f"✗ TCP connection failed (error code: {result})")
sock.close()
return False
except Exception as e:
print(f"✗ TCP error: {e}")
return False
def arp_test():
"""Check ARP table for the device"""
print(f"\n3. Checking ARP table for {HOST}...")
try:
# For macOS/Linux
result = subprocess.run(['arp', '-n'], capture_output=True, text=True)
if HOST in result.stdout:
print(f"✓ Device found in ARP table")
# Extract the relevant line
for line in result.stdout.split('\n'):
if HOST in line:
print(f" {line}")
return True
else:
print("✗ Device not found in ARP table")
return False
except Exception as e:
print(f"✗ ARP check error: {e}")
return False
def port_scan():
"""Quick port scan to see what's open"""
print(f"\n4. Scanning common ports on {HOST}...")
common_ports = [80, 443, 22, 23, 1000, 2000, 8080]
open_ports = []
for port in common_ports:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(0.5)
result = sock.connect_ex((HOST, port))
if result == 0:
open_ports.append(port)
print(f" ✓ Port {port} is open")
sock.close()
if not open_ports:
print(" ✗ No common ports are open")
return len(open_ports) > 0
def main():
print("RP2040-ETH Ethernet Test Suite")
print("==============================\n")
results = {
'ping': ping_test(),
'tcp': tcp_test(),
'arp': arp_test(),
'ports': port_scan()
}
print("\n\nSummary:")
print("--------")
passed = sum(results.values())
total = len(results)
for test, result in results.items():
status = "✓ PASS" if result else "✗ FAIL"
print(f"{test.upper():8} {status}")
print(f"\nTotal: {passed}/{total} tests passed")
if passed == 0:
print("\nTroubleshooting:")
print("1. Check ethernet cable is connected")
print("2. Verify IP address matches your network (192.168.1.x)")
print("3. Check if RP2040-ETH is powered on")
print("4. Use serial monitor to see debug output from the device")
print("5. Ensure your computer is on the same network subnet")
if __name__ == "__main__":
main()