@@ -257,9 +257,12 @@ <h3>Hardware HSM <span class="badge advanced">advanced</span></h3>
257257 < div id ="fields-hsm " class ="fields hidden ">
258258 < div class ="field ">
259259 < label > Serial port path</ label >
260- < input type ="text " id ="hsm-serial-port " placeholder ="/dev/ttyUSB0 " autocomplete ="off " spellcheck ="false " style ="width:100%; padding:0.65rem; background:#111; border:1px solid #333; border-radius:6px; color:#e0e0e0; font-family:monospace; font-size:0.9rem; ">
260+ < div style ="display:flex; gap:0.5rem; align-items:center; ">
261+ < input type ="text " id ="hsm-serial-port " placeholder ="/dev/ttyACM0 " autocomplete ="off " spellcheck ="false " style ="flex:1; padding:0.65rem; background:#111; border:1px solid #333; border-radius:6px; color:#e0e0e0; font-family:monospace; font-size:0.9rem; ">
262+ < button type ="button " onclick ="detectEsp32() " style ="padding:0.65rem 1rem; background:#2a2a2a; border:1px solid #444; border-radius:6px; color:#e0e0e0; cursor:pointer; white-space:nowrap; font-size:0.85rem; "> Detect</ button >
263+ </ div >
264+ < p id ="hsm-detect-msg " style ="font-size:0.78rem; opacity:0.6; margin-top:0.25rem; "> </ p >
261265 </ div >
262- < p style ="font-size:0.78rem; opacity:0.45; margin-top:0.25rem; "> The ESP32 must be connected to this port before starting the bridge binary. Common paths: < code > /dev/ttyUSB0</ code > , < code > /dev/ttyACM0</ code > .</ p >
263266 </ div >
264267
265268 <!-- PIN for encryption at rest -->
@@ -454,6 +457,26 @@ <h2>Device Password</h2>
454457 return { focus : ( ) => input . focus ( ) , reset : ( ) => { input . value = '' ; suggestions . classList . remove ( 'visible' ) ; } } ;
455458 }
456459
460+ async function detectEsp32 ( ) {
461+ const msg = document . getElementById ( 'hsm-detect-msg' ) ;
462+ msg . textContent = 'Scanning...' ;
463+ try {
464+ const r = await fetch ( '/api/hsm/detect' ) ;
465+ const devices = await r . json ( ) ;
466+ if ( devices . length === 0 ) {
467+ msg . textContent = 'No ESP32 devices found. Check the USB connection.' ;
468+ } else if ( devices . length === 1 ) {
469+ document . getElementById ( 'hsm-serial-port' ) . value = devices [ 0 ] . port ;
470+ msg . textContent = 'Found: ' + devices [ 0 ] . product + ' at ' + devices [ 0 ] . port ;
471+ } else {
472+ document . getElementById ( 'hsm-serial-port' ) . value = devices [ 0 ] . port ;
473+ msg . textContent = 'Found ' + devices . length + ' devices. Using ' + devices [ 0 ] . port ;
474+ }
475+ } catch ( e ) {
476+ msg . textContent = 'Detection failed: ' + e . message ;
477+ }
478+ }
479+
457480 function selectMode ( mode ) {
458481 currentMode = mode ;
459482 document . querySelectorAll ( '.mode-card' ) . forEach ( c =>
0 commit comments