-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdetect_vesc_bridge.py
More file actions
51 lines (41 loc) · 1.51 KB
/
detect_vesc_bridge.py
File metadata and controls
51 lines (41 loc) · 1.51 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
48
49
50
51
#!/usr/bin/env python3
"""
Simple ESP32 VESC Bridge Discovery Script
Minimal example to detect the bridge via mDNS.
"""
import socket
def discover_vesc_bridge():
"""Discover ESP32 bridge via mDNS and display information."""
hostname = "vesc-bridge.local"
port = 65102
print(f"Looking for ESP32 bridge: {hostname}")
print("-" * 50)
try:
# Resolve mDNS hostname to IP
addr_info = socket.getaddrinfo(hostname, None, socket.AF_INET, socket.SOCK_STREAM)
ip_address = addr_info[0][4][0]
print(f"✓ Found device!")
print(f" mDNS Name: {hostname}")
print(f" IP Address: {ip_address}")
print(f" Port: {port}")
# Verify connection
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(2)
if sock.connect_ex((ip_address, port)) == 0:
print(f" Status: ✓ Port {port} is open and reachable")
else:
print(f" Status: ⚠ Port {port} is not accessible")
sock.close()
return ip_address
except socket.gaierror:
print(f"✗ Could not resolve {hostname}")
print("\nTroubleshooting:")
print(" - Ensure device is powered on and connected")
print(" - Verify you're on the same network")
print(" - Check mDNS is working on your system")
return None
except Exception as e:
print(f"✗ Error: {e}")
return None
if __name__ == "__main__":
discover_vesc_bridge()