fix: Add serial port discovery for Meshtastic multi-port systems

When multiple serial ports are detected (e.g., /dev/ttyACM0 and /dev/ttyUSB0),
the Meshtastic SDK's auto-detect fails. This adds a /meshtastic/ports endpoint
to list available ports and populates the device dropdown, auto-selecting the
first port when multiple exist.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Smittix
2026-01-28 22:24:00 +00:00
parent adb848ddf6
commit a08d5911c2
2 changed files with 76 additions and 1 deletions
+32
View File
@@ -57,6 +57,38 @@ def _message_callback(msg: MeshtasticMessage) -> None:
pass
@meshtastic_bp.route('/ports')
def list_ports():
"""
List available serial ports that may have Meshtastic devices.
Returns:
JSON with list of available serial ports.
"""
if not is_meshtastic_available():
return jsonify({
'status': 'error',
'ports': [],
'message': 'Meshtastic SDK not installed'
})
try:
from meshtastic.util import findPorts
ports = findPorts()
return jsonify({
'status': 'ok',
'ports': ports,
'count': len(ports)
})
except Exception as e:
logger.error(f"Error listing ports: {e}")
return jsonify({
'status': 'error',
'ports': [],
'message': str(e)
})
@meshtastic_bp.route('/status')
def get_status():
"""