-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.sh
More file actions
executable file
·47 lines (43 loc) · 1.41 KB
/
monitor.sh
File metadata and controls
executable file
·47 lines (43 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
# Monitor ESP32 (/dev/ttyUSB0) and ESP12F hub (/dev/ttyUSB1) simultaneously.
# Hub output is filtered to DBG/PKT lines only; ESP32 shows everything.
# Usage: monitor.sh [esp32_port [hub_port]]
ESP32_PORT=${1:-/dev/ttyUSB0}
HUB_PORT=${2:-/dev/ttyUSB1}
python3 - "$ESP32_PORT" "$HUB_PORT" << 'EOF'
import serial, time, threading, sys
ESP32_PORT = sys.argv[1]
HUB_PORT = sys.argv[2]
def monitor(port, label, hub_filter=False):
try:
s = serial.Serial(port, 115200, timeout=0.5)
except Exception as e:
print(f"[{label}] could not open {port}: {e}", flush=True)
return
try:
while True:
try:
line = s.readline()
except serial.SerialException:
time.sleep(0.2)
continue
if not line:
continue
text = line.decode('utf-8', errors='replace').rstrip()
if not text:
continue
if hub_filter and not any(k in text for k in ('DBG,', 'PKT,')):
continue
print(f"[{label}] {text}", flush=True)
finally:
s.close()
t1 = threading.Thread(target=monitor, args=(ESP32_PORT, 'ESP32', False), daemon=True)
t2 = threading.Thread(target=monitor, args=(HUB_PORT, 'HUB', True), daemon=True)
t1.start()
t2.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\n[monitor] stopped")
EOF