diff --git a/.gitignore b/.gitignore index 50425de..2fec127 100644 --- a/.gitignore +++ b/.gitignore @@ -3,9 +3,6 @@ model/BirdNET_Soundscape_Model.pkl .vscode datasets/ -birdnet.conf -miniforge -scripts/install_miniforge.sh IdentifiedSoFar.txt IdentifiedSoFar.txt.bak Birders_Guide_Installer_Configuration.txt diff --git a/birdnet.conf b/birdnet.conf new file mode 100644 index 0000000..1d2afce --- /dev/null +++ b/birdnet.conf @@ -0,0 +1,195 @@ +################################################################################ +# Configuration settings for BirdNET-Pi # +################################################################################ + +############ CHANGE THE LATITUDE AND LONGITUDE TO STATIC VALUES ################ + + +## LATITUDE and LONGITUDE are self-explanatroy. Find them easily at +## maps.google.com. +## Example: these coordinates would indicate the Eiffel Tower in Paris, France. +## LATITUDE=48.858 +## LONGITUDE=2.294 + +## These are input as shell substitutions so that this will work out of the box. +## It guesses your latitude and longitude based off of your network information. +## THESE SHOULD BE CHANGED TO STATIC NUMBERS!!!! +LATITUDE="$(curl -s4 ifconfig.co/json | awk '/lat/ {print $2}' | tr -d ',')" +LONGITUDE="$(curl -s4 ifconfig.co/json | awk '/lon/ {print $2}' | tr -d ',')" + + +## RECS_DIR is the location birdnet_analysis.service will look for the data-set +## it needs to analyze. Be sure this directory is readable and writable for +## the BIRDNET_USER. If you are going to be accessing a remote data-set, you +## still need to set this, as this will be where the remote directory gets +## mounted locally. + +RECS_DIR=/home/pi/BirdSongs + +#----------------------- Web Interface User Password ------------------------# +#____________________The variable below sets the 'birdnet'_____________________# +#___________________user password for the live audio stream,___________________# +#_________________web tools, system info, and processed files__________________# + +## CADDY_PWD is the plaintext password (that will be hashed) and used to access +## certain parts of the web interface + +CADDY_PWD=changeme + +#------------------------- MariaDB User Passwords ---------------------------# +#_____________The variables below set the 'birder' and 'root'__________________# +#_______________________user passwords for the MariaDB_________________________# + +## DB_PWD is for the 'birder' user +DB_PWD=changeme +## DB_ROOT_PWD is for the 'root' user +DB_ROOT_PWD=changeme + +#------------------------- Live Audio Stream --------------------------------# +#_____________The variable below configures/enables the live___________________# +#_____________________________audio stream.____________________________________# + + +## ICE_PWD is the password that icecast2 will use to authenticate ffmpeg as a +## trusted source for the stream. You will never need to enter this manually +## anywhere other than here. + +ICE_PWD=changeme + +#----------------------- Web-hosting/Caddy File-server -----------------------# +#________The four variables below can be set to enable internet access_________# +#____________to your data,(e.g., extractions, raw data, live___________________# +#______________audio stream, BirdNET.selection.txt files)______________________# + + +## BIRDNETPI_URL is the URL where the extractions, data-set, and live-stream +## will be web-hosted. If you do not own a domain, or would just prefer to keep +## the BirdNET-Pi on your local network, keep this EMPTY. + +BIRDNETPI_URL= +EXTRACTIONLOG_URL= +BIRDNETLOG_URL= + + +#------------------- Mobile Notifications via Pushed.co ---------------------# +#____________The two variables below enable mobile notifications_______________# +#_____________See https://pushed.co/quick-start-guide to get___________________# +#_________________________these values for your app.___________________________# + +# Keep these EMPTY if haven't setup a Pushed.co App yet. # + +## Pushed.co App Key and App Secret + +PUSHED_APP_KEY= +PUSHED_APP_SECRET= + +################################################################################ +#-------------------------------- Defaults ----------------------------------# +################################################################################ + +#------------------------------- NoMachine ----------------------------------# +#_____________The variable below can be set include NoMachine__________________# +#_________________remote desktop software to be installed._____________________# + +# Keep this EMPTY if you do not want to install NoMachine. # + +## INSTALL_NOMACHINE is simply a setting that can be enabled to install +## NoMachine alongside the BirdNET-Pi for remote desktop access. This in- +## staller assumes personal use. Please reference the LICENSE file included +## in this repository for more information. +## Set this to Y or y to install NoMachine alongside the BirdNET-Lite + +INSTALL_NOMACHINE=y + +# +#------------------------------ Extraction Service ---------------------------# + +## DO_EXTRACTIONS is simply a setting for enabling the extraction.service. +## Set this to Y or y to enable extractions. + +DO_EXTRACTIONS=y + +#----------------------------- Recording Service ----------------------------# +#____________________The variable below can be set to enable __________________# +#________________________the birdnet_recording.service ________________________# + +## DO_RECORDING is simply a setting for enabling the 24/7 +## birdnet_recording.service. +## Set this to Y or y to enable recording. + +DO_RECORDING=y + +## REC_CARD is the sound card you would want the birdnet_recording.service to +## use. This setting is irrelevant if you are not planning on doing data +## collection via recording on this machine. The command substitution below +## looks for a USB microphone's dsnoop alsa device. The dsnoop device lets +## birdnet_recording.service and livestream.service share the raw audio stream +## from the microphone. If you would like to use a different microphone than +## what this produces, or if your microphone does not support creating a +## dsnoop device, you can set this explicitly from a list of the available +## devices from the output of running 'aplay -L' + +REC_CARD=default + +## PROCESSED is the directory where the formerly 'Analyzed' files are moved +## after extractions have been made from them. This includes both WAVE and +## BirdNET.selection.txt files. + +PROCESSED=${RECS_DIR}/Processed + +## EXTRACTED is the directory where the extracted audio selections are moved. + +EXTRACTED=${RECS_DIR}/Extracted + +## IDFILE is the file that keeps a complete list of every spececies that +## BirdNET has identified from your data-set. It is persistent across +## data-sets, so would need to be whiped clean through deleting or renaming +## it. A backup is automatically made from this variable each time it is +## updated (structure: ${IDFILE}.bak), and would also need to be removed +## or renamed to start a new file between data-sets. Alternately, you can +## change this variable between data-sets to preserve records of disparate +## data-sets according to name. + +IDFILE=${HOME}/BirdNET-Pi/IdentifiedSoFar.txt + +## OVERLAP is the value in seconds which BirdNET should use when analyzing +## the data. The values must be between 0.0-2.9. + +OVERLAP=0.0 + +## CONFIDENCE is the minimum confidence level from 0.0-1.0 BirdNET's analysis +## should reach before creating an entry in the BirdNET.selection.txt file. +## Don't set this to 1.0 or you won't have any results. + +CONFIDENCE=0.7 + +## SENSITIVITY is the detection sensitivity from 0.5-1.5. + +SENSITIVITY=1.25 + +## CHANNELS holds the variabel that corresponds to the number of channels the +## sound card supports. + +CHANNELS=2 + +## VENV is the virtual environment where the the BirdNET python build is found, +## i.e, VENV is the virtual environment miniforge built for BirdNET. + +VENV=/home/pi/BirdNET-Pi/birdnet + +## RECORDING_LENGTH sets the length of the recording that BirdNET-Lite will analyze. +RECORDING_LENGTH= + +## EXTRACTION_LENGTH sets the length of the audio extractions that will be made +## from each BirdNET-Lite detection. +EXTRACTION_LENGTH= + +## BIRDNET_USER should be the non-root user systemd should use to execute each +## service. + +BIRDNET_USER=pi + + +## These are just for debugging +LAST_RUN= +THIS_RUN= diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults index 118e0d4..0ba5c3c 100644 --- a/birdnet.conf-defaults +++ b/birdnet.conf-defaults @@ -1,91 +1,75 @@ ################################################################################ -# Configuration settings for BirdNET as a service # +# Configuration settings for BirdNET-Pi # ################################################################################ -INSTALL_DATE="$(date "+%D")" -#___________The four variables below are the only that are required.___________# -## BIRDNET_USER should be the non-root user systemd should use to execute each -## service. +############ CHANGE THE LATITUDE AND LONGITUDE TO STATIC VALUES ################ -BIRDNET_USER= + +## LATITUDE and LONGITUDE are self-explanatroy. Find them easily at +## maps.google.com. +## Example: these coordinates would indicate the Eiffel Tower in Paris, France. +## LATITUDE=48.858 +## LONGITUDE=2.294 + +## These are input as shell substitutions so that this will work out of the box. +## It guesses your latitude and longitude based off of your network information. +## THESE SHOULD BE CHANGED TO STATIC NUMBERS!!!! +LATITUDE="$(curl -s4 ifconfig.co/json | awk '/lat/ {print $2}' | tr -d ',')" +LONGITUDE="$(curl -s4 ifconfig.co/json | awk '/lon/ {print $2}' | tr -d ',')" ## RECS_DIR is the location birdnet_analysis.service will look for the data-set ## it needs to analyze. Be sure this directory is readable and writable for ## the BIRDNET_USER. If you are going to be accessing a remote data-set, you ## still need to set this, as this will be where the remote directory gets -## mounted locally. +## mounted locally. -RECS_DIR= +RECS_DIR=/home/pi/BirdSongs -## LATITUDE and LONGITUDE are self-explanatroy. Find them easily at -## maps.google.com. Only go to the thousanths place for these variables -## Example: these coordinates would indicate the Eiffel Tower in Paris, France. -## LATITUDE=48.858 -## LONGITUDE=2.294 - -LATITUDE= -LONGITUDE= - -################################################################################ -#------------------------------ Extraction Service ---------------------------# -#__________________The variable below can be set to enable the ________________# -#______________________________ extraction.service ____________________________# - -# Keep this EMPTY if you do not want this device to perform the extractions # - -## DO_EXTRACTIONS is simply a setting for enabling the extraction.service. -## Set this to Y or y to enable extractions. - -DO_EXTRACTIONS= - -################################################################################ -#----------------------------- Recording Service ----------------------------# -#____________________The variable below can be set to enable __________________# -#________________________the birdnet_recording.service ________________________# - -# Keep this EMPTY if you do not want this device to perform the recording. # - -## DO_RECORDING is simply a setting for enabling the 24/7 -## birdnet_recording.service. -## Set this to Y or y to enable recording. - -DO_RECORDING= - -################################################################################ -#----------------------- Web-hosting/Caddy File-server -----------------------# -#_______The two variables below can be set to enable internet access___________# -#____________to your data,(e.g., extractions, raw data, live___________________# -#______________audio stream, BirdNET.selection.txt files)______________________# - -# Leave these EMPTY if you do not want to enable web access # - -## BIRDNETPI_URL is the URL where the extractions, data-set, and live-stream -## will be web-hosted. If you do not own a domain, or would just prefer to keep -## BirdNET-Pi on your local network, keep this empty. - -BIRDNETPI_URL= +#----------------------- Web Interface User Password ------------------------# +#____________________The variable below sets the 'birdnet'_____________________# +#___________________user password for the live audio stream,___________________# +#_________________web tools, system info, and processed files__________________# ## CADDY_PWD is the plaintext password (that will be hashed) and used to access -## the "Processed" directory and live audio stream. This MUST be set if you -## choose to enable this feature. +## certain parts of the web interface -CADDY_PWD= +CADDY_PWD=changeme + +#------------------------- MariaDB User Passwords ---------------------------# +#_____________The variables below set the 'birder' and 'root'__________________# +#_______________________user passwords for the MariaDB_________________________# + +## DB_PWD is for the 'birder' user +DB_PWD=changeme +## DB_ROOT_PWD is for the 'root' user +DB_ROOT_PWD=changeme -################################################################################ #------------------------- Live Audio Stream --------------------------------# #_____________The variable below configures/enables the live___________________# #_____________________________audio stream.____________________________________# -# Keep this EMPTY if you do not wish to enable the live stream # -# or if this device is not doing the recording # ## ICE_PWD is the password that icecast2 will use to authenticate ffmpeg as a ## trusted source for the stream. You will never need to enter this manually ## anywhere other than here. -ICE_PWD= +ICE_PWD=changeme + +#----------------------- Web-hosting/Caddy File-server -----------------------# +#________The four variables below can be set to enable internet access_________# +#____________to your data,(e.g., extractions, raw data, live___________________# +#______________audio stream, BirdNET.selection.txt files)______________________# + + +## BIRDNETPI_URL is the URL where the extractions, data-set, and live-stream +## will be web-hosted. If you do not own a domain, or would just prefer to keep +## the BirdNET-Pi on your local network, keep this EMPTY. + +BIRDNETPI_URL= +EXTRACTIONLOG_URL= +BIRDNETLOG_URL= + -################################################################################ #------------------- Mobile Notifications via Pushed.co ---------------------# #____________The two variables below enable mobile notifications_______________# #_____________See https://pushed.co/quick-start-guide to get___________________# @@ -99,6 +83,9 @@ PUSHED_APP_KEY= PUSHED_APP_SECRET= ################################################################################ +#-------------------------------- Defaults ----------------------------------# +################################################################################ + #------------------------------- NoMachine ----------------------------------# #_____________The variable below can be set include NoMachine__________________# #_________________remote desktop software to be installed._____________________# @@ -109,14 +96,27 @@ PUSHED_APP_SECRET= ## NoMachine alongside the BirdNET-Pi for remote desktop access. This in- ## staller assumes personal use. Please reference the LICENSE file included ## in this repository for more information. -## Set this to Y or y to install NoMachine alongside the BirdNET-Pi +## Set this to Y or y to install NoMachine alongside the BirdNET-Lite -INSTALL_NOMACHINE= +INSTALL_NOMACHINE=y -################################################################################ -#-------------------------------- Defaults ----------------------------------# -#______The seven variables below are default settings that you (probably)______# -#__________________don't need to change at all, but can._______________________# +# +#------------------------------ Extraction Service ---------------------------# + +## DO_EXTRACTIONS is simply a setting for enabling the extraction.service. +## Set this to Y or y to enable extractions. + +DO_EXTRACTIONS=y + +#----------------------------- Recording Service ----------------------------# +#____________________The variable below can be set to enable __________________# +#________________________the birdnet_recording.service ________________________# + +## DO_RECORDING is simply a setting for enabling the 24/7 +## birdnet_recording.service. +## Set this to Y or y to enable recording. + +DO_RECORDING=y ## REC_CARD is the sound card you would want the birdnet_recording.service to ## use. This setting is irrelevant if you are not planning on doing data @@ -129,7 +129,7 @@ INSTALL_NOMACHINE= ## devices from the output of running 'aplay -L' REC_CARD=default - + ## PROCESSED is the directory where the formerly 'Analyzed' files are moved ## after extractions have been made from them. This includes both WAVE and ## BirdNET.selection.txt files. @@ -166,44 +166,29 @@ CONFIDENCE=0.7 SENSITIVITY=1.25 -################################################################################ -#------------------------------ Auto-Generated ------------------------------# -#_____________________The variables below are auto-generated___________________# -#______________________________during installation_____________________________# - ## CHANNELS holds the variabel that corresponds to the number of channels the ## sound card supports. -CHANNELS= - -# Don't touch the variables below - -## SYSTEMD_MOUNT is created from the RECS_DIR variable to comply with systemd -## mount naming requirements. - -SYSTEMD_MOUNT=$(echo ${RECS_DIR#/} | tr / -).mount +CHANNELS=2 ## VENV is the virtual environment where the the BirdNET python build is found, ## i.e, VENV is the virtual environment miniforge built for BirdNET. -VENV=$(dirname ${my_dir})/miniforge/envs/birdnet - -################################################################################ -#---------------------------------- Testing -----------------------------------# -#_____________These variables are for testing. Please don't touch______________# -#_______________them if you are not testing these features.____________________# - -# To test different values for RECORDING_LENGTH, first: -# 1) stop the birdnet_recording.service: -#### run: `sudo systemctl stop birdnet_recording.service` -# 2) remove any remaining audio files in the day's recording directory: -#### Example: to remove recordings for Saturday, October 2nd, 2021, you would -#### run: `rm -rf /home/pi/BirdSongs/October-2021/02-Saturday/*` -# 3) restart the birdnet_recording.service: -#### run: `sudo systemctl restart birdnet_recording.service` +VENV=/home/pi/BirdNET-Pi/birdnet +## RECORDING_LENGTH sets the length of the recording that BirdNET-Lite will analyze. RECORDING_LENGTH= +## EXTRACTION_LENGTH sets the length of the audio extractions that will be made +## from each BirdNET-Lite detection. EXTRACTION_LENGTH= +## BIRDNET_USER should be the non-root user systemd should use to execute each +## service. + +BIRDNET_USER=pi + + +## These are just for debugging LAST_RUN= +THIS_RUN= diff --git a/scripts/clear_all_data.sh b/scripts/clear_all_data.sh index d7b0035..f9ac89c 100755 --- a/scripts/clear_all_data.sh +++ b/scripts/clear_all_data.sh @@ -4,28 +4,59 @@ # you are okay will losing all the data that you've collected and processed # so far. source /etc/birdnet/birdnet.conf +HOME=/home/pi +my_dir=${HOME}/BirdNET-Pi/scripts echo "Stopping services" sudo systemctl stop birdnet_recording.service echo "Removing all data . . . " sudo rm -drf "${RECS_DIR}" sudo rm -f "${IDFILE}" echo "Recreating necessary directories" -[ -d ${RECS_DIR} ] || sudo -u ${BIRDNET_USER} mkdir -p ${RECS_DIR} -[ -d ${EXTRACTED} ] || sudo -u ${BIRDNET_USER} mkdir -p ${EXTRACTED} -[ -d ${EXTRACTED}/By_Date ] || sudo -u ${BIRDNET_USER} mkdir -p ${EXTRACTED}/By_Date -[ -d ${EXTRACTED}/By_Common_Name ] || sudo -u ${BIRDNET_USER} mkdir -p ${EXTRACTED}/By_Common_Name -[ -d ${EXTRACTED}/By_Scientific_Name ] || sudo -u ${BIRDNET_USER} mkdir -p ${EXTRACTED}/By_Scientific_Name -sudo -u ${BIRDNET_USER} ln -s /home/pi/BirdNET-Pi/templates/index.html ${EXTRACTED} -[ -d ${PROCESSED} ] || sudo -u ${BIRDNET_USER} mkdir -p ${PROCESSED} -[ -L ${EXTRACTED}/scripts ] || sudo -u ${BIRDNET_USER} ln -s /home/pi/BirdNET-Pi/scripts ${EXTRACTED}/ -[ -L ${EXTRACTED}/spectrogram.php ] || sudo -u ${BIRDNET_USER} ln -s /home/pi/BirdNET-Pi/scripts/spectrogram.php ${EXTRACTED} -[ -L ${EXTRACTED}/spectrogram.sh ] || sudo -u ${BIRDNET_USER} ln -s /home/pi/BirdNET-Pi/scripts/spectrogram.sh ${EXTRACTED} -[ -L ${EXTRACTED}/viewdb.php ] || sudo -u ${BIRDNET_USER} ln -s /home/pi/BirdNET-Pi/scripts/viewdb.php ${EXTRACTED} +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}/By_Common_Name ] || sudo -u ${USER} mkdir -p ${EXTRACTED}/By_Common_Name +[ -d ${EXTRACTED}/By_Scientific_Name ] || sudo -u ${USER} mkdir -p ${EXTRACTED}/By_Scientific_Name +[ -d ${PROCESSED} ] || sudo -u ${USER} mkdir -p ${PROCESSED} + +sudo -u ${USER} ln -fs $(dirname ${my_dir})/homepage/* ${EXTRACTED} +if [ ! -z ${BIRDNETLOG_URL} ];then + BIRDNETLOG_URL="$(echo ${BIRDNETLOG_URL} | sed 's/\/\//\\\/\\\//g')" + sudo -u${USER} sed -i "s/http:\/\/birdnetpi.local:8080/"${BIRDNETLOG_URL}"/g" $(dirname ${my_dir})/homepage/*.html + phpfiles="$(grep -l "birdnetpi.local:8080" ${my_dir}/*.php)" + for i in "${phpfiles[@]}";do + sudo -u${USER} sed -i "s/http:\/\/birdnetpi.local:8080/"${BIRDNETLOG_URL}"/g" ${i} + done +fi +if [ ! -z ${EXTRACTIONLOG_URL} ];then + EXTRACTIONLOG_URL="$(echo ${EXTRACTIONLOG_URL} | sed 's/\/\//\\\/\\\//g')" + sudo -u${USER} sed -i "s/http:\/\/birdnetpi.local:8888/"${EXTRACTIONLOG_URL}"/g" $(dirname ${my_dir})/homepage/*.html + phpfiles="$(grep -l "birdnetpi.local:8888" ${my_dir}/*.php)" + for i in "${phpfiles[@]}";do + sudo -u${USER} sed -i "s/http:\/\/birdnetpi.local:8888/"${EXTRACTIONLOG_URL}"/g" ${i} + done +fi + +sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts ${EXTRACTED} +if [ ! -z ${BIRDNETPI_URL} ];then + BIRDNETPI_URL="$(echo ${BIRDNETPI_URL} | sed 's/\/\//\\\/\\\//g')" + sudo -u${USER} sed -i "s/http:\/\/birdnetpi.local/"${BIRDNETPI_URL}"/g" $(dirname ${my_dir})/homepage/*.html + phpfiles="$(grep -l birdnetpi.local ${my_dir}/*.php)" + for i in "${phpfiles[@]}";do + sudo -u${USER} sed -i "s/http:\/\/birdnetpi.local/"${BIRDNETPI_URL}"/g" ${i} + done +fi + +sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/spectrogram.php ${EXTRACTED} +sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/viewdb.php ${EXTRACTED} sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED} -[ -L ${EXTRACTED}/phpsysinfo.ini ] || sudo -u ${USER} cp ${HOME}/phpsysinfo/phpsysinfo.ini.new ${HOME}/phpsysinfo/phpsysinfo.ini +sudo -u ${USER} cp -f $(dirname ${my_dir})/templates/phpsysinfo.ini ${HOME}/phpsysinfo/ +sudo -u ${USER} cp -f $(dirname ${my_dir})/templates/green_bootstrap.css ${HOME}/phpsysinfo/templates/ +sudo -u ${USER} cp -f $(dirname ${my_dir})/templates/index_bootstrap.html ${HOME}/phpsysinfo/templates/html -sudo -u ${BIRDNET_USER} cp ~/BirdNET-Pi/templates/index.html ${EXTRACTED}/ + +sudo -u ${BIRDNET_USER} cp ~/BirdNET-Pi/homepage/index.html ${EXTRACTED}/ echo "Dropping and re-creating database" sudo /home/pi/BirdNET-Pi/scripts/createdb.sh echo "Restarting services"