- Add n4 parameter to control server, LED bar receiver, and test script - Create segmented_movement pattern with alternating forward/backward movement - Pattern supports n1 (segment length), n2 (spacing), n3 (forward speed), n4 (backward speed) - Fix test script to send all messages instead of just the first one - Add segmented_movement to patterns_needing_params for proper parameter transmission - Pattern intelligently handles all cases: alternating, forward-only, backward-only, or static - Implements repeating segments with configurable spacing across LED strip
108 lines
3.6 KiB
Python
108 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Real-time ESP NOW traffic monitor for debugging pattern pausing issues.
|
|
Monitors both the ESP32-C3 USB CDC output and LED bar debug info.
|
|
"""
|
|
|
|
import serial
|
|
import time
|
|
import threading
|
|
import subprocess
|
|
import sys
|
|
import os
|
|
|
|
|
|
class ESPNowDebugger:
|
|
def __init__(self):
|
|
self.esp32_port = "/dev/ttyACM0"
|
|
self.running = False
|
|
|
|
def monitor_esp32_serial(self):
|
|
"""Monitor ESP32-C3 USB CDC output for ESP NOW debug info"""
|
|
try:
|
|
ser = serial.Serial(self.esp32_port, 115200, timeout=1)
|
|
print("🔌 Monitoring ESP32-C3 USB CDC output...")
|
|
|
|
while self.running:
|
|
try:
|
|
line = ser.readline().decode('utf-8').strip()
|
|
if line:
|
|
timestamp = time.strftime("%H:%M:%S")
|
|
print(f"[{timestamp}] ESP32-C3: {line}")
|
|
except serial.SerialTimeoutException:
|
|
continue
|
|
except Exception as e:
|
|
print(f"❌ ESP32-C3 monitor error: {e}")
|
|
break
|
|
|
|
ser.close()
|
|
except Exception as e:
|
|
print(f"❌ Failed to connect to ESP32-C3: {e}")
|
|
|
|
def check_lighting_controller_logs(self):
|
|
"""Check lighting controller logs for message sending"""
|
|
try:
|
|
# Monitor control server output for ESP NOW messages
|
|
print("🔌 Monitoring lighting controller ESP NOW messages...")
|
|
|
|
# Check if control server is running
|
|
proc = subprocess.run(['pgrep', '-f', 'lighting-controller'],
|
|
capture_output=True, text=True)
|
|
if not proc.stdout.strip():
|
|
print("❌ Control server not running!")
|
|
return
|
|
|
|
print("✅ Control server running, monitor logs manually")
|
|
print("💡 Tips:")
|
|
print(" - Watch control server terminal output")
|
|
print(" - Look for SPI/ESP NOW communication messages")
|
|
print(" - Check for timing gaps between messages")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error checking control server: {e}")
|
|
|
|
def run(self):
|
|
"""Start all monitoring threads"""
|
|
print("🔍 ESP NOW Communication Debugger")
|
|
print("=" * 50)
|
|
print()
|
|
|
|
# Check if ESP32-C3 is connected
|
|
if not os.path.exists(self.esp32_port):
|
|
print(f"❌ ESP32-C3 not found on {self.esp32_port}")
|
|
print("💡 Make sure ESP32-C3 is connected via USB")
|
|
return
|
|
|
|
print(f"✅ ESP32-C3 found on {self.esp32_port}")
|
|
print()
|
|
|
|
self.running = True
|
|
|
|
# Start ESP32-C3 monitoring thread
|
|
esp32_thread = threading.Thread(target=self.monitor_esp32_serial)
|
|
esp32_thread.daemon = True
|
|
esp32_thread.start()
|
|
|
|
# Monitor lighting controller
|
|
self.check_lighting_controller_logs()
|
|
|
|
print()
|
|
print("🔍 Monitoring active. Press Ctrl+C to stop...")
|
|
print("📝 Watch for:")
|
|
print(" - ESP NOW message transmission timing")
|
|
print(" - Any error messages or delays")
|
|
print(" - Status updates every 5 seconds")
|
|
print(" - Pattern interrupt patterns")
|
|
|
|
try:
|
|
while self.running:
|
|
time.sleep(1)
|
|
except KeyboardInterrupt:
|
|
print("\n🛑 Stopping debugger...")
|
|
self.running = False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
debugger = ESPNowDebugger()
|
|
debugger.run()
|