Skip to content

A live bird collage card for your Home Assistant dashboard.

single URL installation -- 1 custom URL

mcguirepr893f5c667fa159
diff --git a/homepage/index.php b/homepage/index.php
index 0aed13a4..0fe3688e 100644
--- a/homepage/index.php
+++ b/homepage/index.php
@@ -9,6 +9,7 @@ echo "<a href=\"https://github.com/mcguirepr89/BirdNET-Pi.git\" target=\"_blank\
echo "<a href=\"https://github.com/mcguirepr89/BirdNET-Pi.git\" target=\"_blank\"><img src=\"images/bird.png\"></a>";
}?>
</div>
+ <div class="stream">
<?php
if(isset($_GET['stream'])){
if (file_exists('/home/pi/BirdNET-Pi/thisrun.txt')) {
@@ -28,6 +29,7 @@ if(isset($_GET['stream'])){
if($submittedpwd == $caddypwd && $submitteduser == 'birdnet'){
echo "
<audio controls autoplay><source src=\"/stream\"></audio>
+ </div>
<h1><a href=\"\">BirdNET-Pi</a><img src=\"images/version.svg\"></h1>
</div>";
} else {
@@ -42,34 +44,17 @@ if(isset($_GET['stream'])){
<form action=\"\" method=\"GET\">
<button type=\"submit\" name=\"stream\" value=\"play\">Live Audio</button>
</form>
+ </div>
<h1><a href=\"\">BirdNET-Pi</a><img src=\"images/version.svg\"></h1>
</div>";
}
if(isset($_GET['log'])) {
if (file_exists('/home/pi/BirdNET-Pi/thisrun.txt')) {
- $config = parse_ini_file('/home/pi/BirdNET-Pi/thisrun.txt');
- if(empty($config['BIRDNETLOG_URL']) !== true) {
- $logs = $config['BIRDNETLOG_URL'];
- } elseif(empty($config['BIRDNETPI_URL'] !== true)) {
- $logs = $config['BIRDNETPI_URL'].":8080";
- } else {
- $logs = "http://birdnetpi.local:8080";
- }
- } elseif (file_exists('/home/pi/BirdNET-Pi/firstrun.ini')) {
- $config = parse_ini_file('/home/pi/BirdNET-Pi/firstrun.ini');
- if(empty($config['BIRDNETLOG_URL']) !== true){
- $logs = $config['BIRDNETLOG_URL'];
- } elseif(empty($config['BIRDNETPI_URL'] !== true)) {
- $logs = $config['BIRDNETPI_URL'].":8080";
- } else {
- $logs = "http://birdnetpi.local:8080";
- }
- }
- header("Location: $logs?logo=smaller");
+ header("Location: /log");}
} elseif(isset($_GET['spectrogram'])){
- header("Location: /spectrogram.php?logo=smaller");
+ header("Location: /spectrogram.php");
} else {
- echo "
+ echo "
<iframe src=\"/views.php\">
</div>";
}
diff --git a/homepage/views.php b/homepage/views.php
index bbff3247..3159f2c1 100644
--- a/homepage/views.php
+++ b/homepage/views.php
@@ -153,14 +153,7 @@ if(isset($_POST['view'])){
$submitteduser = $_SERVER['PHP_AUTH_USER'];
if($submittedpwd == $caddypwd && $submitteduser == 'birdnet'){
#ACCESS THE WEB TERMINAL
- if(empty($config['BIRDNETLOG_URL']) == false) {
- $webterm = $config['WEBTERMINAL_URL'];
- } elseif(empty($config['BIRDNETPI_URL'] == false)) {
- $webterm = $config['BIRDNETPI_URL'].":8888";
- } else {
- $webterm = "http://birdnetpi.local:8888";
- }
- header("Location: $webterm");
+ header("Location: /terminal");
} else {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
diff --git a/scripts/advanced.php b/scripts/advanced.php
index d58ed09c..d6c0b3ca 100644
--- a/scripts/advanced.php
+++ b/scripts/advanced.php
@@ -50,30 +50,6 @@ if(isset($_POST['submit'])) {
}
}
- if(isset($_POST["webterminal_url"])) {
- $webterminal_url = $_POST["webterminal_url"];
- if(strcmp($webterminal_url,$config['WEBTERMINAL_URL']) !== 0) {
- $contents = preg_replace("/WEBTERMINAL_URL=.*/", "WEBTERMINAL_URL=$webterminal_url", $contents);
- $contents2 = preg_replace("/WEBTERMINAL_URL=.*/", "WEBTERMINAL_URL=$webterminal_url", $contents2);
- $fh = fopen("/home/pi/BirdNET-Pi/birdnet.conf", "w");
- $fh2 = fopen("/home/pi/BirdNET-Pi/thisrun.txt", "w");
- fwrite($fh, $contents);
- fwrite($fh2, $contents2);
- }
- }
-
- if(isset($_POST["birdnetlog_url"])) {
- $birdnetlog_url = $_POST["birdnetlog_url"];
- if(strcmp($birdnetlog_url,$config['BIRDNETLOG_URL']) !== 0) {
- $contents = preg_replace("/BIRDNETLOG_URL=.*/", "BIRDNETLOG_URL=$birdnetlog_url", $contents);
- $contents2 = preg_replace("/BIRDNETLOG_URL=.*/", "BIRDNETLOG_URL=$birdnetlog_url", $contents2);
- $fh = fopen("/home/pi/BirdNET-Pi/birdnet.conf", "w");
- $fh2 = fopen("/home/pi/BirdNET-Pi/thisrun.txt", "w");
- fwrite($fh, $contents);
- fwrite($fh2, $contents2);
- }
- }
-
if(isset($_POST["birdnetpi_url"])) {
$birdnetpi_url = $_POST["birdnetpi_url"];
if(strcmp($birdnetpi_url,$config['BIRDNETPI_URL']) !== 0) {
@@ -219,17 +195,11 @@ foreach($formats as $format){
<h3>BirdNET-Pi Password</h3>
<label for="caddy_pwd">Webpage: </label>
<input name="caddy_pwd" type="text" value="<?php print($newconfig['CADDY_PWD']);?>" /><br>
- <h3>Custom URLs</h3>
- <p>When you update any of the URL settings below, the web server will reload, so be sure to wait at least 30 seconds and then reload the page.</p>
+ <h3>Custom URL</h3>
+ <p>When you update the URL below, the web server will reload, so be sure to wait at least 30 seconds and then go to your new URL.</p>
<label for="birdnetpi_url">BirdNET-Pi URL: </label>
<input name="birdnetpi_url" type="url" value="<?php print($newconfig['BIRDNETPI_URL']);?>" /><br>
<p>This URL is how the main page will be reached. If you want your installation to respond to an IP address, place that here, but be sure to indicate `http://`.<br>Example for IP:http://192.168.0.109<br>Example if you own your own domain:https://birdnetpi.pmcgui.xyz</p>
- <label for="birdnetlog_url">BirdNET-Lite Log URL: </label>
- <input name="birdnetlog_url" type="url" value="<?php print($newconfig['BIRDNETLOG_URL']);?>" /><br>
- <p>This URL is how the log will be reached. Only use this variable for Fully Qualified Domain Names.</p>
- <label for="webterminal_url">Web Terminal URL: </label>
- <input name="webterminal_url" type="url" value="<?php print($newconfig['WEBTERMINAL_URL']);?>" /><br>
- <p>This URL is how the Web browser terminal will be reached. Only use this variable for Fully Qualified Domain Names.</p>
<h3>BirdNET-Lite Settings</h3>
<label for="overlap">Overlap: </label>
<input name="overlap" type="number" min="0.0" max="2.9" step="0.1" value="<?php print($newconfig['OVERLAP']);?>" required/><br>
diff --git a/scripts/clear_all_data.sh b/scripts/clear_all_data.sh
index 910857d9..cab0dac4 100755
--- a/scripts/clear_all_data.sh
+++ b/scripts/clear_all_data.sh
@@ -17,29 +17,34 @@ sudo rm -f "${IDFILE}"
sudo rm -f $(dirname ${my_dir})/BirdDB.txt
echo "Creating necessary directories"
-[ -d ${EXTRACTED} ] || sudo -u ${USER} mkdir -p ${EXTRACTED}
-[ -d ${EXTRACTED}/By_Date ] || sudo -u ${USER} mkdir -p ${EXTRACTED}/By_Date
-[ -d ${EXTRACTED}/Charts ] || sudo -u ${USER} mkdir -p ${EXTRACTED}/Charts
-[ -d ${PROCESSED} ] || sudo -u ${USER} mkdir -p ${PROCESSED}
+[ -d ${EXTRACTED} ] || mkdir -p ${EXTRACTED}
+[ -d ${EXTRACTED}/By_Date ] || mkdir -p ${EXTRACTED}/By_Date
+[ -d ${EXTRACTED}/Charts ] || mkdir -p ${EXTRACTED}/Charts
+[ -d ${PROCESSED} ] || mkdir -p ${PROCESSED}
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/homepage/* ${EXTRACTED}
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/model/labels.txt ${my_dir}/
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts ${EXTRACTED}
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/play.php ${EXTRACTED}
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/spectrogram.php ${EXTRACTED}
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/overview.php ${EXTRACTED}
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/stats.php ${EXTRACTED}
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/viewdb.php ${EXTRACTED}
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/history.php ${EXTRACTED}
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/homepage/images/favicon.ico ${EXTRACTED}
-sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED}
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/templates/phpsysinfo.ini ${HOME}/phpsysinfo/
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/templates/green_bootstrap.css ${HOME}/phpsysinfo/templates/
-sudo -u ${USER} ln -fs $(dirname ${my_dir})/templates/index_bootstrap.html ${HOME}/phpsysinfo/templates/html
+ln -fs $(dirname ${my_dir})/homepage/* ${EXTRACTED}
+ln -fs $(dirname ${my_dir})/model/labels.txt ${my_dir}/
+ln -fs $(dirname ${my_dir})/scripts ${EXTRACTED}
+ln -fs $(dirname ${my_dir})/scripts/play.php ${EXTRACTED}
+ln -fs $(dirname ${my_dir})/scripts/spectrogram.php ${EXTRACTED}
+ln -fs $(dirname ${my_dir})/scripts/overview.php ${EXTRACTED}
+ln -fs $(dirname ${my_dir})/scripts/stats.php ${EXTRACTED}
+ln -fs $(dirname ${my_dir})/scripts/viewdb.php ${EXTRACTED}
+ln -fs $(dirname ${my_dir})/scripts/history.php ${EXTRACTED}
+ln -fs $(dirname ${my_dir})/homepage/images/favicon.ico ${EXTRACTED}
+ln -fs ${HOME}/phpsysinfo ${EXTRACTED}
+ln -fs $(dirname ${my_dir})/templates/phpsysinfo.ini ${HOME}/phpsysinfo/
+ln -fs $(dirname ${my_dir})/templates/green_bootstrap.css ${HOME}/phpsysinfo/templates/
+ln -fs $(dirname ${my_dir})/templates/index_bootstrap.html ${HOME}/phpsysinfo/templates/html
sudo chmod -R g+rw $(dirname ${my_dir})
sudo chmod -R g+rw ${EXTRACTED}
echo "Dropping and re-creating database"
createdb.sh
+echo "Generating BirdDB.txt"
+touch $(dirname ${my_dir})/BirdDB.txt
+echo "Date;Time;Sci_Name;Com_Name;Confidence;Lat;Lon;Cutoff;Week;Sens;Overlap" > $(dirname ${my_dir})/BirdDB.txt
+ln -sf $(dirname ${my_dir})/BirdDB.txt ${my_dir}/BirdDB.txt
+chown pi:pi ${my_dir}/BirdDB.txt && chmod g+rw ${my_dir}/BirdDB.txt
echo "Restarting services"
restart_services.sh
diff --git a/scripts/install_services.sh b/scripts/install_services.sh
index dacd7530..ba93ed72 100755
--- a/scripts/install_services.sh
+++ b/scripts/install_services.sh
@@ -7,7 +7,6 @@ USER=pi
HOME=/home/pi
my_dir=${HOME}/BirdNET-Pi/scripts
tmpfile=$(mktemp)
-gotty_url="https://github.com/yudai/gotty/releases/download/v1.0.1/gotty_linux_arm.tar.gz"
config_file="$(dirname ${my_dir})/birdnet.conf"
install_depends() {
@@ -20,7 +19,6 @@ install_depends() {
pulseaudio avahi-utils sox libsox-fmt-mp3 php php-fpm php-curl php-xml \
php-zip icecast2 swig ffmpeg wget unzip curl cmake make bc libjpeg-dev \
zlib1g-dev python3-dev python3-pip python3-venv
- wget -c ${gotty_url} -O - | tar -xz -C /usr/local/bin/
}
@@ -206,8 +204,14 @@ http://localhost http://$(hostname).local ${BIRDNETPI_URL} {
basicauth /phpsysinfo* {
birdnet ${HASHWORD}
}
+ basicauth /terminal* {
+ birdnet ${HASHWORD}
+ }
reverse_proxy /stream localhost:8000
php_fastcgi unix//run/php/php7.4-fpm.sock
+ reverse_proxy /log* localhost:8080
+ reverse_proxy /stats* localhost:8501
+ reverse_proxy /terminal* localhost:8888
}
EOF
else
@@ -223,34 +227,13 @@ http://localhost http://$(hostname).local ${BIRDNETPI_URL} {
}
reverse_proxy /stream localhost:8000
php_fastcgi unix//run/php/php7.4-fpm.sock
+ reverse_proxy /log* localhost:8080
+ reverse_proxy /stats* localhost:8501
+ reverse_proxy /terminal* localhost:8888
}
EOF
fi
- if [ ! -z ${WEBTERMINAL_URL} ] && [ ! -z ${HASHWORD} ];then
- cat << EOF >> /etc/caddy/Caddyfile
-${WEBTERMINAL_URL} {
- basicauth {
- birdnet ${HASHWORD}
- }
- reverse_proxy localhost:8888
-}
-EOF
- elif [ ! -z ${WEBTERMINAL_URL} ] && [ -z ${HASHWORD} ];then
- cat << EOF >> /etc/caddy/Caddyfile
-${WEBTERMINAL_URL} {
- reverse_proxy localhost:8888
-}
-EOF
- fi
-
- if [ ! -z ${BIRDNETLOG_URL} ];then
- cat << EOF >> /etc/caddy/Caddyfile
-${BIRDNETLOG_URL} {
- reverse_proxy localhost:8080
-}
-EOF
- fi
systemctl enable caddy
usermod -aG pi caddy
}
@@ -322,7 +305,7 @@ RestartSec=3
Type=simple
User=${USER}
Environment=TERM=xterm-256color
-ExecStart=/usr/local/bin/gotty -p 8080 --title-format "BirdNET-Pi Log" birdnet_log.sh
+ExecStart=/usr/local/bin/gotty --address localhost -p 8080 -P log --title-format "BirdNET-Pi Log" birdnet_log.sh
[Install]
WantedBy=multi-user.target
EOF
@@ -337,7 +320,7 @@ RestartSec=3
Type=simple
User=${USER}
Environment=TERM=xterm-256color
-ExecStart=/usr/local/bin/gotty -w -p 8888 --title-format "BirdNET-Pi Terminal" bash
+ExecStart=/usr/local/bin/gotty --address localhost -w -p 8888 -P terminal --title-format "BirdNET-Pi Terminal" bash
[Install]
WantedBy=multi-user.target
EOF
diff --git a/scripts/plotly_streamlit.py b/scripts/plotly_streamlit.py
new file mode 100755
index 00000000..c1abe215
--- /dev/null
+++ b/scripts/plotly_streamlit.py
@@ -0,0 +1,121 @@
+#!/home/pi/BirdNET-Pi/birdnet/bin/python3
+import streamlit as st
+import pandas as pd
+import plotly.express as px
+import numpy as np
+import plotly.graph_objects as go
+from plotly.subplots import make_subplots
+from datetime import timedelta, datetime
+
+def load_data():
+ df1 = pd.read_csv('/home/pi/BirdNET-Pi/BirdDB.txt', sep=';')
+ return df1
+
+
+# Read in the cereal data
+df = load_data()
+df2=df.copy()
+df2['DateTime']=pd.to_datetime(df2['Date'] + " " + df2['Time'])
+df2=df2.set_index('DateTime')
+
+# Filter on date range
+# Date as calendars
+#Start_Date1 = pd.to_datetime(st.sidebar.date_input('Which date do you want to start?', value = df2.index.min()))
+#End_Date1 = pd.to_datetime(st.sidebar.date_input('Which date do you want to end?', value = df2.index.max()))
+# Date as slider
+Start_Date = pd.to_datetime(df2.index.min())
+End_Date = pd.to_datetime(df2.index.max())
+Date_Slider = st.sidebar.slider('Date Range',
+ value=(Start_Date.to_pydatetime(),
+ End_Date.to_pydatetime())
+ )
+filt = (df2.index >= Date_Slider[0]) & (df2.index <= Date_Slider[1]+timedelta(days=1))
+df2 = df2[filt]
+
+#Create species count for selected date range
+
+Specie_Count=df2['Com_Name'].value_counts()
+
+#Create species treemap
+
+# Create Hourly Crosstab
+hourly=pd.crosstab(df2['Com_Name'],df2.index.hour)
+
+# Filter on species
+species = list(hourly.index)
+
+top_N = st.sidebar.select_slider(
+ 'Select Number of Birds to Show',
+ list(range(1,len(Specie_Count))),
+ value=(10))
+
+top_N_species = (df2['Com_Name'].value_counts()[:top_N])
+
+
+specie = st.sidebar.selectbox('Which bird would you like to explore?', species, index=species.index(list(top_N_species.index)[0]))
+
+
+font_size=15
+
+
+#specie filter
+filt=df2['Com_Name']==specie
+
+df_counts=df2[filt].resample('D').count()
+
+fig = make_subplots(
+ rows=2, cols =2,
+ specs= [[{"type":"xy","rowspan":2}, {"type":"polar"}], [None, {"type":"xy"}]],
+ subplot_titles=('<b>Species in Date Range</b>',
+ '<b>'+specie+'</b>'
+ '<br>Total Detections:'+str('{:,}'.format(sum(df_counts.Time)))+
+ '<br>''Max Confidence:'+str('{:.2f}%'.format(max(df2[df2['Com_Name']==specie]['Confidence'])*100))+
+ '<br>''Median Confidence:'+str('{:.2f}%'.format(np.median(df2[df2['Com_Name']==specie]['Confidence'])*100))
+
+ )
+ )
+# fig.layout.height=900
+# fig.layout.width=1500
+
+#Plot seen species for selected date range and number of species
+fig.add_trace(go.Bar(y=top_N_species.index, x=top_N_species, orientation='h'), row=1,col=1)
+
+fig.update_layout(
+ margin=dict(l=0, r=0, t=50, b=0),
+ yaxis={'categoryorder':'total ascending'})
+# Set 360 degrees, 24 hours for polar plot
+theta = np.linspace(0.0, 360, 24, endpoint=False)
+
+fig.add_trace(go.Barpolar(r = hourly.loc[specie], theta=theta), row=1, col=2)
+
+fig.update_layout(
+ autosize=True,
+ width = 1000,
+ height = 750,
+ showlegend=False,
+ polar = dict(
+ radialaxis = dict(
+ tickfont_size = font_size,
+ showticklabels = False),
+ angularaxis = dict(
+ tickfont_size= font_size,
+ rotation = -90,
+ direction = 'clockwise',
+ tickmode='array',
+ tickvals=[0,45,90,135,180,225,270,315],
+ ticktext=['12am','3am', '6am','9am','12pm','3pm', '6pm','9pm'],
+ hoverformat = ""#"%{theta}: <br>Popularity: %{percent} </br> %{r}"
+ ),
+ ),
+ )
+
+fig.layout.annotations[1].update(x=0.8,y=0.4, font_size=25)
+
+x=df_counts.index
+y=df_counts['Com_Name']
+
+fig.add_trace(go.Bar(x=df_counts.index,y=df_counts['Time']), row=2, col=2)
+
+container=st.container()
+container.plotly_chart(fig, use_container_width=True)
diff --git a/scripts/update_caddyfile.sh b/scripts/update_caddyfile.sh
index 17091353..c0f0e3e7 100755
--- a/scripts/update_caddyfile.sh
+++ b/scripts/update_caddyfile.sh
@@ -32,8 +32,14 @@ http://localhost http://$(hostname).local ${BIRDNETPI_URL} {
basicauth /phpsysinfo* {
birdnet ${HASHWORD}
}
+ basicauth /terminal* {
+ birdnet ${HASHWORD}
+ }
reverse_proxy /stream localhost:8000
php_fastcgi unix//run/php/php7.4-fpm.sock
+ reverse_proxy /log* localhost:8080
+ reverse_proxy /stats* localhost:8501
+ reverse_proxy /terminal* localhost:8888
}
EOF
else
@@ -49,32 +55,9 @@ http://localhost http://$(hostname).local ${BIRDNETPI_URL} {
}
reverse_proxy /stream localhost:8000
php_fastcgi unix//run/php/php7.4-fpm.sock
-}
-EOF
-fi
-
-if [ ! -z ${WEBTERMINAL_URL} ] && [ ! -z ${HASHWORD} ];then
- cat << EOF >> /etc/caddy/Caddyfile
-${WEBTERMINAL_URL} {
- basicauth {
- birdnet ${HASHWORD}
- }
- reverse_proxy localhost:8888
-}
-EOF
-elif [ ! -z ${WEBTERMINAL_URL} ] && [ -z ${HASHWORD} ];then
- cat << EOF >> /etc/caddy/Caddyfile
-${WEBTERMINAL_URL} {
- reverse_proxy localhost:8888
-}
-EOF
-fi
-
-if [ ! -z ${BIRDNETLOG_URL} ];then
- cat << EOF >> /etc/caddy/Caddyfile
-
-${BIRDNETLOG_URL} {
- reverse_proxy localhost:8080
+ reverse_proxy /log* localhost:8080
+ reverse_proxy /stats* localhost:8501
+ reverse_proxy /terminal* localhost:8888
}
EOF
fi