AvianVisitors hardening pass — install via fork's newinstaller
Restructures the install so users run ONE command. The fork's newinstaller.sh clones this repo (instead of upstream Nachtzuster) and runs BirdNET-Pi's installer. install_services.sh symlinks the avian/ overlay into the Caddy site root, so http://birdnet.local/avian/ comes up after reboot with no Caddy config needed. Reviewer-flagged fixes: Frontend (avian/frontend/apt.js) - Switch all API paths from /api/*.json (which didn't route) to relative action-based URLs (./api/birdnet-api.php?action=recent etc.). - Fetch ./masks.json + ./dims.json relatively (were /avian/*.json). - Replace every innerHTML user-content sink with createElement + textContent + setAttribute — species labels are user-editable in BirdNET-Pi, so untrusted. - Add esc() helper for the few remaining innerHTML attribute contexts. - fetchJson throws on non-200 (was silently parsing 404 HTML as JSON). - Defensive null-check in loadMask if MASKS hasn't loaded. Backend (avian/api/*.php) - birdnet-api.php now derives DB_PATH from dirname(__DIR__, 3) so any BirdNET-Pi install user works (no hardcoded /home/birdnet). - recording/spectrogram/cutout use getenv('HOME') for the same reason. - cutout.php reworked as the canonical image resolver: bundled illustration → bundled cutout → cached rembg → fresh Wikipedia+rembg, with the binomial regex guard and atomic rename on cache write. Wikipedia URL host pinned to wikimedia.org / wikipedia.org to block SSRF. - Stale 'X-BirdNET-Proxy-Token' auth claims removed everywhere. Pregen (avian/scripts/pregen.py) - Gemini key moved from URL query to x-goog-api-key header. - Model bumped to gemini-2.5-flash-image-preview. - Bounded retry on 429 + 5xx with Retry-After honoured. - Default --sleep raised from 1s to 4s (under free-tier RPM). - Unified parser handles |/_/comma in all three input modes. - responseModalities now [TEXT, IMAGE] (was IMAGE-only). - --poses validated against POSES keys. - ASCII [ok]/[fail] markers (was ✓/✗ — Windows console crash). - Surfaces finishReason + blockReason on safety blocks. Prompt template - 'Two placeholders' typo → three. - 'warm paper' / 'transparent background' contradiction resolved. Forwarding - mqtt-bridge.py: paho-mqtt 2.x CallbackAPIVersion compat shim. - avian-mqtt.service: dropped broken %i, set User=birdnet + %h path. - forwarding/README.md uses the actual action-based URLs. README - One-line install via curl … newinstaller.sh. - No more 'install BirdNET-Pi separately' step (our fork does it). - License section uses absolute github.com links. - bird.onethreenine.net replaces the not-yet-existent project writeup. - docs/thumb.png replaced with the 24-bird Twitter capture. Removed - avian/caddy/ and avian/scripts/install.sh — no longer needed; the overlay symlink in install_services.sh handles everything.
This commit is contained in:
+25
-35
@@ -1,6 +1,6 @@
|
||||
# Optional: forwarding the collage off your local network
|
||||
|
||||
Default install hosts the collage at `http://birdnet.local/collage/` on
|
||||
Default install hosts the collage at `http://birdnet.local/avian/` on
|
||||
your LAN with no auth. If you want it accessible from anywhere — or
|
||||
piped into Home Assistant / MQTT — pick one of the recipes below.
|
||||
|
||||
@@ -8,18 +8,17 @@ Each recipe is independent. Skip what you don't need.
|
||||
|
||||
---
|
||||
|
||||
## 1. Cloudflare Tunnel (recommended for public access)
|
||||
## 1. Cloudflare Tunnel — public HTTPS, no port forwarding
|
||||
|
||||
Gives you a public HTTPS URL with no port forwarding and no exposed
|
||||
home IP. Free Cloudflare account required.
|
||||
Free Cloudflare account required.
|
||||
|
||||
Install `cloudflared` on the Pi:
|
||||
Install `cloudflared`:
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /usr/share/keyrings
|
||||
sudo apt install -y lsb-release
|
||||
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg \
|
||||
| sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
|
||||
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main' \
|
||||
echo "deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared $(lsb_release -cs) main" \
|
||||
| sudo tee /etc/apt/sources.list.d/cloudflared.list
|
||||
sudo apt update && sudo apt install -y cloudflared
|
||||
```
|
||||
@@ -29,28 +28,21 @@ Authenticate + create the tunnel:
|
||||
```bash
|
||||
cloudflared tunnel login
|
||||
cloudflared tunnel create birds
|
||||
```
|
||||
|
||||
Add a public route — pick a hostname on a zone you own:
|
||||
|
||||
```bash
|
||||
cloudflared tunnel route dns birds birds.your-domain.com
|
||||
```
|
||||
|
||||
Configure the tunnel to point at the local Caddy:
|
||||
Configure + start the tunnel:
|
||||
|
||||
```bash
|
||||
sudo cp avian/forwarding/cloudflared.yml /etc/cloudflared/config.yml
|
||||
# edit /etc/cloudflared/config.yml — set `tunnel:` to your tunnel UUID
|
||||
sudo cp ~/BirdNET-Pi/avian/forwarding/cloudflared.yml /etc/cloudflared/config.yml
|
||||
# Edit /etc/cloudflared/config.yml — set `tunnel:` to your tunnel UUID
|
||||
sudo cloudflared service install
|
||||
sudo systemctl restart cloudflared
|
||||
```
|
||||
|
||||
**Adding password protection on the public URL.** With Cloudflare in
|
||||
front, gate the public endpoint via Cloudflare Access (zero-trust
|
||||
free tier supports up to 50 users) — see Cloudflare docs. The local
|
||||
LAN URL remains unprotected. If you'd rather use HTTP Basic auth on
|
||||
Caddy itself, see [forwarding/caddy-auth.caddy](caddy-auth.caddy).
|
||||
To password-protect the public URL, set up Cloudflare Access (free
|
||||
tier: up to 50 users). The LAN URL stays open. If you'd rather use HTTP
|
||||
Basic auth, see [`caddy-auth.caddy`](caddy-auth.caddy).
|
||||
|
||||
---
|
||||
|
||||
@@ -60,13 +52,11 @@ Add to `configuration.yaml`:
|
||||
|
||||
```yaml
|
||||
rest:
|
||||
- resource: http://birdnet.local/api/recent.json?hours=1
|
||||
- resource: http://birdnet.local/avian/api/birdnet-api.php?action=recent&hours=1
|
||||
scan_interval: 60
|
||||
sensor:
|
||||
- name: "Latest Bird"
|
||||
value_template: >
|
||||
{% set top = value_json.species | sort(attribute='last_seen', reverse=true) | first %}
|
||||
{{ top.com if top else 'none' }}
|
||||
value_template: "{{ value_json.species[0].com if value_json.species else 'none' }}"
|
||||
json_attributes_path: "$.species[0]"
|
||||
json_attributes:
|
||||
- sci
|
||||
@@ -75,25 +65,25 @@ rest:
|
||||
- best_conf
|
||||
```
|
||||
|
||||
Use the sensor in automations — flash a light when a new species is
|
||||
heard, etc.
|
||||
`birdnet-api.php?action=recent` already returns `species` ordered by
|
||||
count desc; if you want most-recent first, replace the value_template
|
||||
with a sort filter.
|
||||
|
||||
---
|
||||
|
||||
## 3. MQTT — fan out detections to other services
|
||||
|
||||
If you already run an MQTT broker, publish every new detection.
|
||||
Install `paho-mqtt` and run the bridge:
|
||||
|
||||
```bash
|
||||
sudo pip3 install paho-mqtt --break-system-packages
|
||||
cp avian/forwarding/mqtt-bridge.py ~/avian-mqtt.py
|
||||
# edit ~/avian-mqtt.py — broker host, topic prefix
|
||||
sudo cp avian/forwarding/avian-mqtt.service /etc/systemd/system/
|
||||
cp ~/BirdNET-Pi/avian/forwarding/mqtt-bridge.py ~/avian-mqtt.py
|
||||
# Edit ~/avian-mqtt.py — broker host, topic prefix, credentials
|
||||
sudo cp ~/BirdNET-Pi/avian/forwarding/avian-mqtt.service /etc/systemd/system/
|
||||
# Edit /etc/systemd/system/avian-mqtt.service — set User= to your username
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now avian-mqtt
|
||||
```
|
||||
|
||||
The bridge polls `/api/recent.json?hours=1` once a minute and
|
||||
publishes new species under `birdnet/<slug>` with the full record as
|
||||
JSON payload.
|
||||
The bridge polls `/avian/api/birdnet-api.php?action=recent&hours=1`
|
||||
once a minute and publishes new species under `birdnet/<slug>` with the
|
||||
full record as a JSON payload. Dedup is in-memory only — downstream
|
||||
consumers should be idempotent.
|
||||
|
||||
@@ -4,7 +4,10 @@ After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/python3 /home/%i/avian-mqtt.py
|
||||
# Edit User= and the ExecStart path to match your Pi's username if
|
||||
# you didn't install BirdNET-Pi as the `birdnet` user.
|
||||
User=birdnet
|
||||
ExecStart=/usr/bin/python3 %h/avian-mqtt.py
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Poll /api/recent.json on the Pi once a minute and publish each new
|
||||
detection to MQTT. Edit BROKER, TOPIC_PREFIX, and PI_URL below."""
|
||||
"""Poll AvianVisitors' recent-detections endpoint once a minute and publish
|
||||
each new species to MQTT. Edit BROKER, TOPIC_PREFIX, and PI_URL below."""
|
||||
import json
|
||||
import time
|
||||
import urllib.request
|
||||
@@ -11,7 +11,7 @@ PORT = 1883
|
||||
USER = ""
|
||||
PASSWORD = ""
|
||||
TOPIC_PREFIX = "birdnet"
|
||||
PI_URL = "http://birdnet.local/api/recent.json?hours=1"
|
||||
PI_URL = "http://birdnet.local/avian/api/birdnet-api.php?action=recent&hours=1"
|
||||
|
||||
seen_keys: set[str] = set()
|
||||
|
||||
@@ -36,7 +36,13 @@ def loop(client: mqtt.Client) -> None:
|
||||
time.sleep(60)
|
||||
|
||||
def main() -> None:
|
||||
client = mqtt.Client()
|
||||
# paho-mqtt 2.x requires CallbackAPIVersion; the constructor below
|
||||
# also works on 1.x (the kwarg is just ignored). Pin to VERSION2 so
|
||||
# we get the modern callback signatures going forward.
|
||||
try:
|
||||
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
|
||||
except AttributeError: # paho-mqtt 1.x
|
||||
client = mqtt.Client()
|
||||
if USER:
|
||||
client.username_pw_set(USER, PASSWORD)
|
||||
client.connect(BROKER, PORT, keepalive=60)
|
||||
|
||||
Reference in New Issue
Block a user