Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service to publish past detections to BirdWeather #250

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

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)

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