Fix live species labeling on the spectrogram for non-RTSP setups (ajax_csv doubled the directory in the path) - #650
Open
EvaldoOliveira wants to merge 1 commit into
Conversation
…b() returns full paths, so the directory got prepended twice when reading the newest .wav.json and ajax_csv always answered empty - no label was ever drawn; take the newest match and reduce it to a basename like the RTSP/scandir branch does
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The live species-name overlay on the Spectrogram view never draws anything on non-RTSP (USB/ALSA mic) installations.
The
ajax_csvendpoint's non-RTSP branch collects the detection json withglob($look_in_directory . "*.wav.json"), which returns full paths. Later the file is read with:so the directory is prepended a second time (
/home/pi/BirdSongs/StreamData//home/pi/BirdSongs/StreamData/....wav.json),file_get_contents()fails, and the endpoint always answers an empty 200 — the browser JS (loadDetectionIfNewExists) then never draws a label. The RTSP branch is unaffected because it usesscandir(), which returns basenames.A second small issue in the same lines:
$files[0]picks the alphabetically first match rather than the newest (relevant when more than one json exists, e.g. multiple streams' leftovers).Fix
Reduce the newest glob match to a basename, mirroring what the RTSP branch produces:
(
glob()sorts alphabetically by default, which is chronological for these date-prefixed file names.)Testing
On a Pi 4 station (USB mic, no RTSP), before:
curl 'http://localhost/spectrogram.php?ajax_csv=true'→ HTTP 200, empty body. After: the newest detection json is returned (file_name,timestamp,delay,detections[]), the repeat-poll dedup (newest_file=parameter) answers empty as expected, and detected species names are drawn on the live spectrogram again.🤖 Generated with Claude Code
https://claude.ai/code/session_01VZUYHB2yN6XCPYyUWf7mzG