Skip to content

Conversation

@tvoirand
Copy link

@tvoirand tvoirand commented Dec 7, 2024

Problem

As of now, detections are posted to BirdWeather by birdnet_analysis.py at the time of detection. If the BirdNET-Pi station is offline during a detection, that detection is not published to BirdWeather, as described in issue #228.

Proposed change

A dedicated service can be added to monitor network connectivity and automatically publish any past detection to BirdWeather when connectivity is restored.

These changes are quite extensive. This PR is intended to present ideas, and further discuss/iterate if there's any interest.

That said, I have tested these updates both on fresh installations and when applied via update_birdnet.sh, and they function as expected.

Detailed description of the changes

  1. Detection class update (helpers.py)

    • Constructor refactor: The Detection constructor no longer depends on the ParseFileName class, enabling handling detections without access to temporary audio files in the StreamData folder. This improves flexibility (and could be implemented independently from this PR).
    • Attributes redefinition: Replace start and stop (delays) with start_datetime and stop_datetime (absolute times). Calculation of detection times are move outside of the constructor.
    • Interactions with the Detection class are updated accordingly in server.py and reporting.py
  2. Centralize logging setup

    • Move the logging setup function from birdnet_analysis.py to helpers.py to allow reuse across multiple scripts
  3. New BirdWeather module (birdweather.py):

    • Add a module to centralize interactions with BirdWeather API, used both by reporting.py and by the new script for processing past detections
  4. New python script for past detections publication (birdweather_past_publication.py):

    • Add a script to process and publish past detections to BirdWeather
    • The script loops through recent detections, publishes those that are missing in BirdWeather, and stores its last run timestamp in a new SQL database table scripts_metadata.
  5. New table in the SQL database:

    • The new scripts_metadata table used by birdweather_past_publication.py is:
      • Added to createdb.sh for fresh installs
      • For updates, created by a new update_db.sh script executed by update_birdnet_snippets.sh to ensure this table is present
  6. New systemd service birdweather_past_publication:

    • A systemd service to execute the new python script
    • The ExecStartPre key ensures the service runs only once BirdWeather is reachable
    • Service installation and update are handled in install_helpers.sh, install_services.sh, and update_birdnet_snippets.sh
  7. Networkd-dispatcher integration:

    • Installed networkd-dispatcher to trigger actions on network status changes.
    • Added a dispatcher script to trigger the birdweather_past_publication service when connectivity is restored.
    • The script includes a placeholder for interfaces names (wlan or ethernet).
    • Installation and update of the script is handled in install_helpers.sh, install_services.sh, and update_birdnet_snippets.sh, including setting root ownership (required for networkd-dispatcher scripts).

@Nachtzuster
Copy link
Owner

Thanks for the PR & writeup.

I probably won't have time to really look at it this week (maybe during the weekend)

This suppresses the output of the curl command, used to check if BirdWeather is accessible, by redirecting it to /dev/null.
Take date *and time* into account (and not just the date) when fetching recent detections from the database.
@tvoirand
Copy link
Author

Hi,

I just wanted to check in on this PR and see whether you think we can move it forward at some point.

I have been watching the repo lately and I can see that it's very active, which is great, though I imagine it must be quite demanding. If this kind of extensive change isn't something you'd like to prioritize or doesn't align with the project's direction, I'd perfectly understand. If that's the case it might make sense to close this PR.

On the other hand, if you're still interested in the proposed feature and would prefer to keep the PR open for a potential review later on, that's fine too.

As a side note, after reviewing the changes, I remembered that some parts could be implemented independently from the full past detections publication service, like the Detection class update and the creation of a dedicated BirdWeather module. A third option could be to close this PR and open another one focused on these less ambitious changes.

Happy to hear your thoughts !

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.

2 participants