From 2fefea5618cff97d141ab675bc64697efd17f116 Mon Sep 17 00:00:00 2001 From: Smittix Date: Wed, 4 Feb 2026 10:03:47 +0000 Subject: [PATCH] Add listening audio debug endpoint --- routes/audio_websocket.py | 10 ++++++--- routes/listening_post.py | 43 +++++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/routes/audio_websocket.py b/routes/audio_websocket.py index 1971d88..17abaa2 100644 --- a/routes/audio_websocket.py +++ b/routes/audio_websocket.py @@ -228,9 +228,13 @@ def init_audio_websocket(app: Flask): except TimeoutError: pass - except Exception as e: - if "timed out" not in str(e).lower(): - logger.error(f"WebSocket receive error: {e}") + except Exception as e: + msg = str(e).lower() + if "connection closed" in msg: + logger.info("WebSocket closed by client") + break + if "timed out" not in msg: + logger.error(f"WebSocket receive error: {e}") # Stream audio data if active if streaming and proc and proc.poll() is None: diff --git a/routes/listening_post.py b/routes/listening_post.py index 2e9cd83..4b59d5a 100644 --- a/routes/listening_post.py +++ b/routes/listening_post.py @@ -860,14 +860,41 @@ def stop_audio() -> Response: return jsonify({'status': 'stopped'}) -@listening_post_bp.route('/audio/status') -def audio_status() -> Response: - """Get audio status.""" - return jsonify({ - 'running': audio_running, - 'frequency': audio_frequency, - 'modulation': audio_modulation - }) +@listening_post_bp.route('/audio/status') +def audio_status() -> Response: + """Get audio status.""" + return jsonify({ + 'running': audio_running, + 'frequency': audio_frequency, + 'modulation': audio_modulation + }) + + +@listening_post_bp.route('/audio/debug') +def audio_debug() -> Response: + """Get audio debug status and recent stderr logs.""" + rtl_log_path = '/tmp/rtl_fm_stderr.log' + ffmpeg_log_path = '/tmp/ffmpeg_stderr.log' + + def _read_log(path: str) -> str: + try: + with open(path, 'r') as handle: + return handle.read().strip() + except Exception: + return '' + + return jsonify({ + 'running': audio_running, + 'frequency': audio_frequency, + 'modulation': audio_modulation, + 'sdr_type': scanner_config.get('sdr_type', 'rtlsdr'), + 'device': scanner_config.get('device', 0), + 'gain': scanner_config.get('gain', 0), + 'squelch': scanner_config.get('squelch', 0), + 'audio_process_alive': bool(audio_process and audio_process.poll() is None), + 'rtl_fm_stderr': _read_log(rtl_log_path), + 'ffmpeg_stderr': _read_log(ffmpeg_log_path), + }) @listening_post_bp.route('/audio/stream')