BirdNET-Pi October 2023 Installation for Remote System
Bullseye vs Debian version: 12 (Bookworm)
- Current issue with Bookworm release of Raspberry Pi OS
- The installation exited unsuccessfully - tflite_runtime-2.6.0-cp39-none-linux_aarch64.whl is not a supported
- Solution is to install Pi OS (Legacy, 64-bit) Lite version of the Bullseye port
Enable SSH
sudo raspi-config
Interface Options
Select SSH
Select Yes
Server is enabled
Finish
BirdNET-Pi Updates
sudo apt update
sudo apt upgrade
SSD Configuration
lsusb -t
sudo fstrim -v /
lsblk -D
sudo su
- Exit root
exit
Install BirdNET-Pi Software
curl
Installing Packages
Installation installed successfully
Configuration of BirdNET-Pi using Web Portal
Tools Login
Tools Settings
Select a Model Update location - to 4 decimal places
Change default admin password New username is birdnet
Find your location
Update Settings - button
Success - Advanced settings
Advanced settings menu
Update default Admin password settings. Note - username changes from admin to birdnet
Instruction to Access BirdNET-Pi web portal
Update settings
External Booster WiFi Antenna
ifconfig
ssh birdnetpiremote@192.168.1.155
Home Router configuration for Static IP Address
Advanced > Network > LAN Settings
Address Reservation > Add
IP and MAC Address
Add IP and MAC address to list
Static IP address included in list
TeamViewer - Connect to Remote Raspberry Pi computer that has no GUI Interface
To install TeamViewer on a Raspberry Pi without a GUI interface (headless installation), you can use the TeamViewer Host version. Here are the steps to install TeamViewer on a headless Raspberry Pi:
- Access Your Raspberry Pi: You'll need to have SSH access to your Raspberry Pi. Connect to it using SSH from another computer. Alternatively, you can also configure the Raspberry Pi directly (prior to deployment into the field. This is easier and more secure because you don't need to enable SSH.
- Download TeamViewer Host:
- Visit the TeamViewer download page for Raspberry Pi using a web browser: TeamViewer Raspberry Pi Download.
- Look for the TeamViewer Host for Raspberry Pi section.
- Right-click on the appropriate download link (choose 64-bit version for BirdNET-Pi) based on your Raspberry Pi model (e.g., Raspberry Pi 3 or Raspberry Pi 4) and choose "Copy link address" from the context menu.
https://download.teamviewer.com/download/linux/teamviewer_arm64.deb
- Download TeamViewer: - On your Raspberry Pi, use wget to download TeamViewer.
wget https://download.teamviewer.com/download/linux/teamviewer_arm64.deb
- Install TeamViewer:- Install TeamViewer using dpkg. Replace <downloaded-package.deb> with the actual filename you downloaded. This will install TeamViewer without any GUI components.
sudo dpkg -i teamviewer_arm64.deb
sudo apt-get install -f
- Set Up TeamViewer: Now, you can set up TeamViewer to work with your TeamViewer account by running the following command:
sudo teamviewer setup
Follow the on-screen instructions to set up TeamViewer, including signing in with your TeamViewer account or creating one if you don't have an account yet. You will be asked to sign in to your TeamViewer account. Once signed in, an email will be sent to your email address asking for the addition of the remote computer to be verified.
- Click Add to Trusted Devices
- Start TeamViewer: After setting up TeamViewer, you can start it by running:
sudo teamviewer daemon start
- Access the Raspberry Pi: You can now access and control your headless Raspberry Pi using TeamViewer from another computer.
Remember that you will need to have an active internet connection on both your Raspberry Pi and the computer you use to access it via TeamViewer.
Testing MPPT Data upload
- Connect VE.Dect cable to USB Port on Raspberry Pi computer.
- During initial trials using WiFi 3 USB ports were already occupied (Wifi External, SSD external drive, USB microphone) - so the Smart Shunt was not connected.
- To list all USB devices enter the command:
lsusb
- To list specific USB connected devices enter the following command.
- The VE.Direct cable is connected to /dev/ttyUSB0
ls /dev/*USB*
Create MPPT.py file
- Create a new empty file using the following command.
- Create this file in the user directory /home/birdnetpiremote/MPPT.py
- Alternatively, if the python code is available, use nano and create and populate the file in the one step.
touch MPPT.py
- Enter the following python code to read data from the Victron MPPT Solar Charge Controller.
- The following key changes were made:
- Installation of VE.Direct required.
- File write path adjusted. Also set to 'w' so that file is written over each time with new data.
#!venv/bin/python
#import serial
import datetime
from vedirect import VEDirect
port_0 = '/dev/ttyUSB0'
ve_0 = VEDirect(port_0,60,'')
data_0 = ve_0.read_data_single()
datasave_0=""
mppt_dict={}
ls_0=['V','VPV','PPV','IL','LOAD','H19','H20','H21','H22','H23','ERR','CS','FW','PID','SER#','HSDS','MPPT']
for i in range(len(ls_0)):
mppt_dict.update({ls_0[i]:data_0[ls_0[i]]})
print(mppt_dict)
now = datetime.datetime.now()
date_stamp = now.strftime("%Y-%m-%d %H:%M:%S")
data_save_0=date_stamp+'\n'
data_save_1=data_save_0
print(f'The current time is {date_stamp}')
#date = str(line) + "," + date_stamp + "\n"
#print(f'The data is= {data}')
for i in range(len(ls_0)):
length=len(ls_0[i])+len(str(data_0[ls_0[i]]))
data_save_0=data_save_0+ls_0[i]+ " : " + str(data_0[ls_0[i]]) + " "*(20-length)
if (i+1)%5==0:
data_save_0=data_save_0+"\n"
else:
data_save_0=data_save_0+"| "
f=open('/home/birdnetpiremote/MPPT/mppt_data_new.txt','w')
f.write(data_save_0)
f.close
Change File Permissions
- The MPPT.py cannot be executed in the current form and needs to be made executable
- To change file permissions enter the following commands.
sudo chmod +x MPPT.py
Verify that the permissions have been changed with the command
ls -l
Installing vedirect python module
- Tying to run the MPPT.py file will result in a error because the vedirect python module has not been installed.
sudo apt install git
python3 -m pip install "git+https://github.com/jmfife/vedirect"
The command python3 -m pip install "git+https://github.com/jmfife/vedirect" is used to install a Python package directly from a Git repository. Here's what each part of the command does:
- python3: This invokes the Python 3 interpreter.
- -m pip: This uses Python's package manager, pip, to manage package installations.
- install: This is the pip command to install Python packages.
- "git+https://github.com/jmfife/vedirect": This is the argument to the install command and specifies the package to install. In this case, it's a Git repository URL. pip will clone the repository from GitHub and install the package.
So, running this command will install the Python package available in the specified Git repository into your Python environment.
Creating MPPT directory to save MPPT data
- Create a new directory named MPPT
- Within the MPPT directory create a new file named mppt_data_new.txt
Testing MPPT.py
- The MPPT.py python file can now be tested.
- Enter the following command to test the code.
python3 MPPT.py
To visualise the saved data enter the following command.
cat mppt_data_new.txt
Testing Uploading of Data to Dropbox
Create DropboxUpload.py python code
- Create a new file named DropboxUpload.py with the touch command.
touch DropboxUpload.py
- Use nano to upload the following code.
- Full code reproduced here.
import datetime
import dropbox
current_datetime = datetime.datetime.now()
ACCESS_TOKEN = ',\<Enter-Access-Token-Here'
formatted_datetime = current_datetime.strftime("%Y-%m-%d_%H-%M-%S")
dbx =dropbox.Dropbox(ACCESS_TOKEN)
local_file_path = '/home/birdnetpiremote/MPPT/mppt_data_new.txt'
dropbox_path='/MPPT/'+formatted_datetime+'mppt.txt'
with open(local_file_path, 'rb') as f:
dbx.files_upload(f.read(),dropbox_path)
#local_file_path = '/home/pi/MPPT/shunt_data_new.txt'
#dropbox_path='/Smart Shunt/'+formatted_datetime+'shunt.txt'
#with open(local_file_path, 'rb') as f:
# dbx.files_upload(f.read(),dropbox_path)
print("File Uploaded!")
Install Dropbox python library
- Enter the following command so that data files can be directly uploaded to a Dropbox account.
pip install dropbox
Making DropboxUpload.py file executable
sudo chmod +x DropboxUpload.py
Execute DropboxUpload.py file
Run the DropboxUpload.py file with the following command.
python3 DropboxUpload.py
- An upload error may be encountered if the Access Token has expired.
- If this occurs then renew the Access Token.
- Run the python file to verify that it works.
python3 DropboxUpload.py
All Files Running on RemoteBirdNET-Pi 25 Oct 2023
MPPT.py
#!venv/bin/python
import datetime
from vedirect import VEDirect
port_0 = '/dev/ttyUSB0'
ve_0 = VEDirect(port_0,60,'')
data_0 = ve_0.read_data_single()
datasave_0=""
mppt_dict={}
ls_0=['V','VPV','PPV','IL','LOAD','H19','H20','H21','H22','H23','ERR','CS','FW','PID','SER#','HSDS','MPPT']
for i in range(len(ls_0)):
mppt_dict.update({ls_0[i]:data_0[ls_0[i]]})
print(mppt_dict)
now = datetime.datetime.now()
date_stamp = now.strftime("%Y-%m-%d %H:%M:%S")
data_save_0=date_stamp+'\n'
data_save_1=data_save_0
print(f'The current time is {date_stamp}')
for i in range(len(ls_0)):
length=len(ls_0[i])+len(str(data_0[ls_0[i]]))
data_save_0=data_save_0+ls_0[i]+ " : " + str(data_0[ls_0[i]]) + " "*(20-length)
if (i+1)%5==0:
data_save_0=data_save_0+"\n"
else:
data_save_0=data_save_0+"| "
f=open('/home/birdnetpiremote/MPPT/mppt_data_new.txt','w')
f.write(data_save_0)
f.close
DropboxUpload.py
import datetime
import dropbox
current_datetime = datetime.datetime.now()
ACCESS_TOKEN = '<<INSERT HERE>>'
formatted_datetime = current_datetime.strftime("%Y-%m-%d_%H-%M-%S")
dbx =dropbox.Dropbox(ACCESS_TOKEN)
local_file_path = '/home/birdnetpiremote/MPPT/mppt_data_new.txt'
dropbox_path='/MPPT/'+formatted_datetime+'mppt.txt'
with open(local_file_path, 'rb') as f:
dbx.files_upload(f.read(),dropbox_path)
#local_file_path = '/home/pi/MPPT/shunt_data_new.txt'
#dropbox_path='/Smart Shunt/'+formatted_datetime+'shunt.txt'
#with open(local_file_path, 'rb') as f:
# dbx.files_upload(f.read(),dropbox_path)
print("File Uploaded!")
BirdDat.py
#!venv/bin/python
import datetime
import sqlite3
import datetime
def isleap(Y): # This functions decides whether Y is a leap year.
if(Y%4!=0):
return False
elif(Y%100!=0):
return True
elif(Y%400!=0):
return False
else:
return True
def date_minus(former):
year=1000*(ord(former[0])-ord('0'))+100*(ord(former[1])-ord('0'))+10*(ord(former[2])-ord('0'))+(ord(former[3])-ord('0'))
month=10*(ord(former[5])-ord('0'))+(ord(former[6])-ord('0'))
day=10*(ord(former[8])-ord('0'))+(ord(former[9])-ord('0'))
M=[31,28,31,30,31,30,31,31,30,31,30,31] # M stores how many days are there in each month.
if(isleap(year)):
M[1]+=1 # If this is a leap year, then February has 29 days.
if(day>1): # Usual date. Example: 2022-08-19->2022-08-18
day-=1
elif(day==1 and month==1): # First day of the year. Example: 2014-01-01 -> 2013-12-31
year-=1
month,day=12,31
elif(day==1 and month!=1): # First day of the month excluding January. Example: 2012-03-01-> 2012-02-29
month-=1
day=M[month-1]
new_date=str(year)+'-'+str(month).zfill(2)+'-'+str(day).zfill(2) # Formatting the new date.
return new_date
now = datetime.datetime.now()
current_date = now.strftime("%Y-%m-%d")
target_date=date_minus(current_date)
conn = sqlite3.connect('/home/birdnetpiremote/BirdNET-Pi/scripts/birds.db')
cursor = conn.cursor()
select_query = 'SELECT * FROM detections WHERE date = ?'
cursor.execute(select_query,(target_date,))
rows = cursor.fetchall()
# Close the connection to database
conn.close()
# Save birdNET detection data to local file named birdDB_listing.txt
data = ''
open('/home/birdnetpiremote/BirdData/B.txt','w').close()
f = open('/home/birdnetpiremote/BirdData/B.txt','a')
for row in rows:
# Convert all items to strings using "list comprehension"
stringified_items = [str(item) for item in row]
# Join the stringified items with commas
data = ', '.join(stringified_items)
f.write(data + '\n')
f.close()
DropboxUploadBirdData.py
import datetime
import dropbox
current_datetime = datetime.datetime.now()
ACCESS_TOKEN = '<<ACCESS TOKEN HERE>>'
formatted_datetime = current_datetime.strftime("%Y-%m-%d_%H-%M-%S")
dbx =dropbox.Dropbox(ACCESS_TOKEN)
local_file_path = '/home/birdnetpiremote/BirdData/B.txt'
dropbox_path='/MPPT/'+formatted_datetime+'BirdData.txt'
with open(local_file_path, 'rb') as f:
dbx.files_upload(f.read(),dropbox_path)
print("File Uploaded!")
Scheduling File Executing using Cron
Starting Cron for the first time
crontab -e
- Choose nano as the default editor for nano.
Adding files to Cron
- Add the following files to the cron file.
5 * * * * python3 /home/birdnetpiremote/MPPT.py
6 * * * * python3 /home/birdnetpiremote/DropboxUpload.py
Uploaded file in Dropbox
All Cron Files
Extracting Bird Data from birds.db Sqlite3 Database
- When the remote BirdNET-Pi is fully deployed data will only be extracted once per day.
- However in these initial trials using WiFi data may be extracted hourly to test the system.
Installing TeamViewer
- Before installing TeamViewer - stop all BirdNET-Pi processing by naviagating to the /home/birdnetpiremote/BirdNET-Pi/scripts directory and entering the command
./stop_core_services.sh
- This command will reduce processing overloads on the Raspberry Pi and allow TeamViewer to be installed.
- Check that the process is less busy with the command htop
- To exist htop enter Fn+10
- Don't forget to restart services with the command.
restart_services.sh
- Create new directory named Downloads in the home directory /home/birdnetpiremote/Downloads
- Navigate into the Downloads directory with cd Downloads
- Install TeamViewer with command
wget https://download.teamviewer.com/download/linux/teamviewer-arm64.deb
- Install the application with the command.
- The sudo apt-get install -f command in Linux is used to fix and resolve package dependencies.
sudo apt-get install -f
- Set up Teamviewer with the command
sudo teamviewer setup
- Accept licence agreement.
- Enter the username and password for your existing TeamViewer account.
- Confirmation will then be sent to your email address.
- Reply to email from TeamViewer to verify remote computer.
- Click on Add Trusted Device
- Click on Trust Device
- Device added successfully.
- Sign in again on the remote computer.
- This will also initiate the final setup.
- Notification that remote device Successfully added to Contacts in TeamViewer
- Restart TeamViewer daemon on the remote computer.
sudo teamviewer daemon start
Port Forwarding Configuration on the Home Router for SSH remote access
Adding a 4G WiFi Router and Configuring WiFi using the Terminal
Configuring WiFi on a Raspberry Pi using the Terminal involves editing the network configuration file. Here are the steps to configure WiFi on a Raspberry Pi using the Terminal:
- Open the Terminal: You can access the Terminal from the desktop or use an SSH connection.
- Edit the wpa_supplicant.conf file:
- This file contains the WiFi configuration settings.
- Use a text editor like nano to edit it. Type the following command:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
- Add WiFi Configuration: Add the following lines to the end of the file, replacing your_ssid and your_password with your WiFi network name and password:
network={
ssid="your_ssid"
psk="your_password"
}
- If your WiFi network doesn't use a password (which is not recommended for security reasons), you can omit the psk line.
- Save and Exit: - Save your changes in nano by pressing Ctrl + X, then press Y to confirm saving, and press Enter to exit.
- Restart the Networking Service: - Restart the networking service to apply the changes:
sudo systemctl restart networking
- Check Connection: You can check if your Raspberry Pi is connected to WiFi using the following command:
ifconfig
- Look for the wlan0 section, and you should see an IP address assigned to it.
- That's it! Your Raspberry Pi should now be connected to the WiFi network you specified.
- Keep in mind that these instructions assume you are using the default Raspbian/Raspberry Pi OS configuration.
- If you are using a different operating system or configuration, the steps might vary.