diff --git a/static/js/modes/bluetooth.js b/static/js/modes/bluetooth.js index 1ad1ce3..41c1090 100644 --- a/static/js/modes/bluetooth.js +++ b/static/js/modes/bluetooth.js @@ -22,6 +22,8 @@ const BluetoothMode = (function() { * Initialize the Bluetooth mode */ function init() { + console.log('[BT] Initializing BluetoothMode'); + // Cache DOM elements startBtn = document.getElementById('startBtBtn'); stopBtn = document.getElementById('stopBtBtn'); @@ -35,6 +37,13 @@ const BluetoothMode = (function() { baselineStatusEl = document.getElementById('btBaselineStatus'); capabilityStatusEl = document.getElementById('btCapabilityStatus'); + console.log('[BT] DOM elements:', { + startBtn: !!startBtn, + stopBtn: !!stopBtn, + deviceContainer: !!deviceContainer, + adapterSelect: !!adapterSelect + }); + // Check capabilities on load checkCapabilities(); @@ -218,8 +227,10 @@ const BluetoothMode = (function() { if (eventSource) eventSource.close(); eventSource = new EventSource('/api/bluetooth/stream'); + console.log('[BT] SSE stream connected'); eventSource.addEventListener('device_update', (e) => { + console.log('[BT] SSE device_update event:', e.data); try { const device = JSON.parse(e.data); handleDeviceUpdate(device); @@ -228,6 +239,11 @@ const BluetoothMode = (function() { } }); + // Also listen for generic messages as fallback + eventSource.onmessage = (e) => { + console.log('[BT] SSE generic message:', e.data); + }; + eventSource.addEventListener('scan_started', (e) => { const data = JSON.parse(e.data); setScanning(true); @@ -269,6 +285,7 @@ const BluetoothMode = (function() { * Handle device update from SSE */ function handleDeviceUpdate(device) { + console.log('[BT] Device update received:', device); devices.set(device.device_id, device); renderDevice(device); } @@ -277,7 +294,16 @@ const BluetoothMode = (function() { * Render a device card */ function renderDevice(device) { - if (!deviceContainer) return; + console.log('[BT] Rendering device:', device.device_id, 'Container:', deviceContainer); + if (!deviceContainer) { + console.warn('[BT] No device container found!'); + // Try to find it again + deviceContainer = document.getElementById('output'); + if (!deviceContainer) { + console.error('[BT] Still no container - cannot render'); + return; + } + } const existingCard = deviceContainer.querySelector(`[data-device-id="${device.device_id}"]`);