@@ -20,6 +20,13 @@ const COOLDOWN_MS = 7000; // Cooldown period for manual pin
2020const REPEATER_LISTEN_MS = 7000 ; // Listen for repeater echoes for 7 seconds
2121const STATUS_UPDATE_DELAY_MS = 100 ; // Brief delay to ensure "Ping sent" status is visible
2222const MAP_REFRESH_DELAY_MS = 1000 ; // Delay after API post to ensure backend updated
23+ const DEBUG_STARTUP_BANNER = `
24+ ╔═══════════════════════════════════════════════════════════╗
25+ ║ MeshCore GOME WarDriver - Debug Console Logs Active ║
26+ ║ Open DevTools Console to monitor ping activity ║
27+ ║ Look for [Debug] and [Repeater Tracker] messages ║
28+ ╚═══════════════════════════════════════════════════════════╝
29+ ` ;
2330const WARDROVE_KEY = new Uint8Array ( [
2431 0x40 , 0x76 , 0xC3 , 0x15 , 0xC1 , 0xEF , 0x38 , 0x5F ,
2532 0xA9 , 0x3F , 0x06 , 0x60 , 0x27 , 0x32 , 0x0F , 0xE5
@@ -460,11 +467,19 @@ function buildPayload(lat, lon) {
460467 return `${ PING_PREFIX } ${ coordsStr } ${ suffix } ` ;
461468}
462469
470+ // ---- Helper Functions ----
471+ function formatSessionLogLine ( nowStr , lat , lon , status = '' ) {
472+ const coords = `${ lat . toFixed ( 5 ) } ${ lon . toFixed ( 5 ) } ` ;
473+ const statusStr = status ? ` ${ status } ` : '' ;
474+ return `${ nowStr } ${ coords } ${ statusStr } ` ;
475+ }
476+
463477// ---- Repeater Tracking ----
464478// Tracks channel echoes (repeater responses) after sending a ping
465479// Debug output is logged to browser console with [Repeater Tracker] prefix
466480// Open DevTools console to see real-time echo detection and diagnose connectivity issues
467481function startRepeaterTracking ( sessionLi ) {
482+ console . log ( `[Debug] startRepeaterTracking called, sessionLi:` , sessionLi ) ;
468483 // Clean up any existing tracking
469484 stopRepeaterTracking ( ) ;
470485
@@ -475,6 +490,8 @@ function startRepeaterTracking(sessionLi) {
475490 } ;
476491
477492 console . log ( `[Repeater Tracker] Started listening for channel echoes (${ REPEATER_LISTEN_MS } ms window)` ) ;
493+ console . log ( `[Debug] Connection object exists:` , ! ! state . connection ) ;
494+ console . log ( `[Debug] LogRxData push code constant:` , Constants . PushCodes . LogRxData ) ;
478495
479496 // Create listener for LogRxData events
480497 state . repeaterLogListener = ( logData ) => {
@@ -546,16 +563,22 @@ function startRepeaterTracking(sessionLi) {
546563
547564 // Start listening for LogRxData events
548565 if ( state . connection ) {
566+ console . log ( `[Debug] Registering LogRxData event listener on connection` ) ;
549567 state . connection . on ( Constants . PushCodes . LogRxData , state . repeaterLogListener ) ;
568+ console . log ( `[Debug] LogRxData event listener registered successfully` ) ;
569+ } else {
570+ console . warn ( `[Debug] Cannot register LogRxData listener: connection is null` ) ;
550571 }
551572
552573 // Schedule stop after REPEATER_LISTEN_MS
553574 state . repeaterListenTimer = setTimeout ( ( ) => {
575+ console . log ( `[Debug] Repeater tracking timeout reached after ${ REPEATER_LISTEN_MS } ms` ) ;
554576 stopRepeaterTracking ( ) ;
555577 } , REPEATER_LISTEN_MS ) ;
556578}
557579
558580function stopRepeaterTracking ( ) {
581+ console . log ( `[Debug] stopRepeaterTracking called` ) ;
559582 // Stop the timer
560583 if ( state . repeaterListenTimer ) {
561584 clearTimeout ( state . repeaterListenTimer ) ;
@@ -564,11 +587,18 @@ function stopRepeaterTracking() {
564587
565588 // Remove the event listener
566589 if ( state . repeaterLogListener && state . connection ) {
590+ console . log ( `[Debug] Removing LogRxData event listener` ) ;
567591 state . connection . off ( Constants . PushCodes . LogRxData , state . repeaterLogListener ) ;
568592 state . repeaterLogListener = null ;
569593 }
570594
571595 // Update the session log entry with repeater data
596+ console . log ( `[Debug] Updating session log with repeater data:` , {
597+ hasRepeaterData : ! ! state . repeaterData ,
598+ hasSessionLi : ! ! state . repeaterData ?. sessionLi ,
599+ repeaterCount : state . repeaterData ?. repeaters ?. size || 0
600+ } ) ;
601+
572602 if ( state . repeaterData && state . repeaterData . sessionLi ) {
573603 const repeaters = state . repeaterData . repeaters ;
574604 if ( repeaters . size > 0 ) {
@@ -581,11 +611,16 @@ function stopRepeaterTracking() {
581611
582612 // Append to the existing text in the session log
583613 const currentText = state . repeaterData . sessionLi . textContent ;
584- state . repeaterData . sessionLi . textContent = `${ currentText } [${ repeaterList } ]` ;
614+ const updatedText = `${ currentText } [${ repeaterList } ]` ;
615+ state . repeaterData . sessionLi . textContent = updatedText ;
585616 console . log ( `[Repeater Tracker] Stopped listening. Total ${ repeaters . size } unique repeater(s) detected: [${ repeaterList } ]` ) ;
617+ console . log ( `[Debug] Session log updated with repeater data:` , updatedText ) ;
586618 } else {
587619 console . log ( `[Repeater Tracker] Stopped listening. No channel echoes detected in ${ REPEATER_LISTEN_MS } ms window` ) ;
620+ console . log ( `[Debug] No repeaters to add to session log` ) ;
588621 }
622+ } else {
623+ console . warn ( `[Debug] Cannot update session log: repeaterData or sessionLi is null` ) ;
589624 }
590625
591626 // Clear repeater data
@@ -638,12 +673,14 @@ async function postToMeshMapperAPI(lat, lon) {
638673
639674// ---- Ping ----
640675async function sendPing ( manual = false ) {
676+ console . log ( `[Debug] sendPing called: manual=${ manual } , timestamp=${ new Date ( ) . toISOString ( ) } ` ) ;
641677 try {
642678 // Check cooldown only for manual pings
643679 if ( manual && isInCooldown ( ) ) {
644680 const remainingMs = state . cooldownEndTime - Date . now ( ) ;
645681 const remainingSec = Math . ceil ( remainingMs / 1000 ) ;
646682 setStatus ( `Please wait ${ remainingSec } s before sending another ping` , "text-amber-300" ) ;
683+ console . log ( `[Debug] Ping blocked by cooldown: ${ remainingSec } s remaining` ) ;
647684 return ;
648685 }
649686
@@ -694,6 +731,7 @@ async function sendPing(manual = false) {
694731 }
695732
696733 const payload = buildPayload ( lat , lon ) ;
734+ console . log ( `[Debug] Payload built: "${ payload } "` ) ;
697735
698736 // Format timestamp as ISO 8601 without milliseconds: YYYY-MM-DDTHH:MM:SSZ
699737 const nowStr = new Date ( ) . toISOString ( ) . split ( '.' ) [ 0 ] + 'Z' ;
@@ -702,7 +740,8 @@ async function sendPing(manual = false) {
702740 // This ensures we capture echoes that arrive immediately after transmission
703741 let sessionLogLi = null ;
704742 if ( sessionPingsEl ) {
705- const line = `${ nowStr } ${ lat . toFixed ( 5 ) } ${ lon . toFixed ( 5 ) } ` ;
743+ const line = formatSessionLogLine ( nowStr , lat , lon , '[sending...]' ) ;
744+ console . log ( `[Debug] Creating session log entry: "${ line } "` ) ;
706745 sessionLogLi = document . createElement ( 'li' ) ;
707746 sessionLogLi . textContent = line ;
708747 sessionPingsEl . appendChild ( sessionLogLi ) ;
@@ -711,11 +750,21 @@ async function sendPing(manual = false) {
711750
712751 // Start tracking repeater echoes BEFORE sending the ping
713752 // This is critical: echoes can arrive within milliseconds of transmission
753+ console . log ( `[Debug] Starting repeater tracking BEFORE sending ping` ) ;
714754 startRepeaterTracking ( sessionLogLi ) ;
715755 }
716756
717757 const ch = await ensureChannel ( ) ;
758+ console . log ( `[Debug] Sending ping to channel ${ ch . channelIdx } : "${ payload } "` ) ;
718759 await state . connection . sendChannelTextMessage ( ch . channelIdx , payload ) ;
760+ console . log ( `[Debug] Ping sent successfully` ) ;
761+
762+ // Update session log to show ping was sent
763+ if ( sessionLogLi ) {
764+ const line = formatSessionLogLine ( nowStr , lat , lon ) ;
765+ sessionLogLi . textContent = line ;
766+ console . log ( `[Debug] Session log updated to show ping sent` ) ;
767+ }
719768
720769 // Start cooldown period after successful ping
721770 startCooldown ( ) ;
@@ -823,8 +872,10 @@ function scheduleNextAutoPing() {
823872}
824873
825874function startAutoPing ( ) {
875+ console . log ( `[Debug] startAutoPing called` ) ;
826876 if ( ! state . connection ) {
827877 alert ( "Connect to a MeshCore device first." ) ;
878+ console . log ( `[Debug] startAutoPing aborted: no connection` ) ;
828879 return ;
829880 }
830881
@@ -833,6 +884,7 @@ function startAutoPing() {
833884 const remainingMs = state . cooldownEndTime - Date . now ( ) ;
834885 const remainingSec = Math . ceil ( remainingMs / 1000 ) ;
835886 setStatus ( `Please wait ${ remainingSec } s before toggling auto mode` , "text-amber-300" ) ;
887+ console . log ( `[Debug] startAutoPing aborted: in cooldown (${ remainingSec } s remaining)` ) ;
836888 return ;
837889 }
838890
@@ -853,6 +905,7 @@ function startAutoPing() {
853905 acquireWakeLock ( ) . catch ( console . error ) ;
854906
855907 // Send first ping immediately
908+ console . log ( `[Debug] startAutoPing: sending first ping immediately` ) ;
856909 sendPing ( false ) . catch ( console . error ) ;
857910}
858911
@@ -870,10 +923,12 @@ async function connect() {
870923 state . connection = conn ;
871924
872925 conn . on ( "connected" , async ( ) => {
926+ console . log ( `[Debug] Connection established successfully` ) ;
873927 setStatus ( "Connected" , "text-emerald-300" ) ;
874928 setConnectButton ( true ) ;
875929 connectBtn . disabled = false ;
876930 const selfInfo = await conn . getSelfInfo ( ) ;
931+ console . log ( `[Debug] Device info retrieved:` , selfInfo ) ;
877932 deviceInfoEl . textContent = selfInfo ?. name || "[No device]" ;
878933 updateAutoButton ( ) ;
879934 try { await conn . syncDeviceTime ?. ( ) ; } catch { /* optional */ }
@@ -965,6 +1020,10 @@ document.addEventListener("visibilitychange", async () => {
9651020
9661021// ---- Bind UI & init ----
9671022export async function onLoad ( ) {
1023+ console . log ( DEBUG_STARTUP_BANNER ) ;
1024+ console . log ( `[Debug] Application loaded at ${ new Date ( ) . toISOString ( ) } ` ) ;
1025+ console . log ( `[Debug] Session pings element:` , sessionPingsEl ) ;
1026+
9681027 setStatus ( "Disconnected" , "text-red-300" ) ;
9691028 enableControls ( false ) ;
9701029 updateAutoButton ( ) ;
@@ -981,8 +1040,12 @@ export async function onLoad() {
9811040 setStatus ( e . message || "Connection error" , "text-red-300" ) ;
9821041 }
9831042 } ) ;
984- sendPingBtn . addEventListener ( "click" , ( ) => sendPing ( true ) . catch ( console . error ) ) ;
1043+ sendPingBtn . addEventListener ( "click" , ( ) => {
1044+ console . log ( `[Debug] Manual ping button clicked at ${ new Date ( ) . toISOString ( ) } ` ) ;
1045+ sendPing ( true ) . catch ( console . error ) ;
1046+ } ) ;
9851047 autoToggleBtn . addEventListener ( "click" , ( ) => {
1048+ console . log ( `[Debug] Auto toggle button clicked, current state.running=${ state . running } ` ) ;
9861049 if ( state . running ) {
9871050 stopAutoPing ( ) ;
9881051 setStatus ( "Auto mode stopped" , "text-slate-300" ) ;
0 commit comments