Skip to content

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
Nachtzuster:mainfrom
EvaldoOliveira:pr/spectrogram-ajax-csv
Open

EvaldoOliveira wants to merge 1 commit into
Nachtzuster:mainfrom
EvaldoOliveira:pr/spectrogram-ajax-csv

Conversation

@EvaldoOliveira

Copy link
Copy Markdown

Problem

The live species-name overlay on the Spectrogram view never draws anything on non-RTSP (USB/ALSA mic) installations.

The ajax_csv endpoint's non-RTSP branch collects the detection json with glob($look_in_directory . "*.wav.json"), which returns full paths. Later the file is read with:

$contents = file_get_contents($look_in_directory . $newest_file);

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 uses scandir(), 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:

$newest_file = basename(end($files));

(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

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant