Installing CAM-AI server on a Raspberry Pi

This is an installation tutorial for the CAM-AI Server on a Raspberry Pi 4 (Minimum 4 GB of internal RAM) with Raspberry Pi OS 12 (bookworm) 64bit. For Raspi we recommend installing CAM-AI on a freshly installed Raspi-OS. You can prepare your Raspi (OS installation etc.) following the instructions in this separate tutorial.

Prepare Debian (for non-Raspi Users)

First, create the user “cam_ai” with sudo priveledges and login to this new user:

sudo adduser cam_ai
sudo usermod -aG sudo cam_ai
su cam_ai

Next, install Django:

pip3 install Django

Finally, you need to install Miniconda and initialize the shells:

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh


~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh

You will need to shut down and reopen your current shell to proceed with creating your new environment:

conda create --name tf python=3.10

Now, you’re ready to proceed with this manual.

When the OS is ready, you log into your new CAM-AI server via SSH with root privileges (on Raspi: user cam_ai):

ssh cam_ai@cam-ai-raspi

If your CAM-AI servers name is not cam-ai-raspi, please replace cam-ai-raspi with the name you have got and replace it everywhere in this tutorial. Some routers do not use the system name (here: cam-ai-raspi). In these cases, you have to use the IP address of your Raspi (192.168.0.42 e. g.) to replace the term cam-ai-raspi throughout this tutorial.

If you get this warning table, this is probably because you have done other tasks with the same Raspi in the past. Fix it with entering:

ssh-keygen -R "cam-ai-raspi"

…and then try again. If this does not work, try to replace “cam-ai-raspi” with “[YOUR-IP]” using your Raspi’s IP address.

If you are using an Apple computer (MacBook etc.) as a Terminal to do this, this might not work. In this case, go to your home directory, change to subdirectory /.ssh (after making hidden directories visible), and edit the file “known host”. Delete all lines related to your raspi.

If you are asked about the authenticity of your fingerprint (see example below), answer with yes.

Now you give the cam_ai user the privilege to launch server shutdown and reboot without a password. This is needed to end or update the program from the web interface:

sudo visudo -f /etc/sudoers.d/shutdown_privilege

You add the following context to the empty file. When done, save and leave:

cam_ai ALL=(root) NOPASSWD: /sbin/shutdown

Next is getting the CAM-AI installer program and launching it:

wget https://raw.githubusercontent.com/ludgerh/cam-ai/main/cam-ai-setup.py

python cam-ai-setup.py

This installation program will ask you a couple of questions first:

Here are the answers:

  • Localhost: Hit “Enter” for no if you do not plan to access your server from a browser on the same machine.
  • Internal IP: Enter “cam-ai-raspi”, if this is your server’s name. If not, enter the right server name or the server’s IP address.
  • External domain: Hit “Enter” for none.
  • Root password: This is the password for the root access to the database. Select one and write it down, in case you need it later.
  • CAM-AI password: This is the password for the user’s access to the database. Select one and write it down, in case you need it later.

After a couple of minutes of activity on your monitor you should be able to start the server:

./runserver.sh

Log in

From another PC in the same network, you can now log in by giving your browser:

http://cam-ai-raspi:8000/

Again, if your server has a network name different from “cam-ai-raspi”, use that or the IP address. The initial login information is user=admin password=cam-ai-123. (Not your registered CAM-AI user. You will need that one later.)

Done.

What’s next?

  • A CAM-AI server installed on a slow machine (Raspberry Pi for example) needs a connection to another server that is capable of doing the AI work. Get an account from our fast server in the cloud. Here is how. Write down your new username and password. You will need it later.
  • To connect your camera to your server and your Server to the AI server, you need to do a basic server setup.
  • Optional: If you want to use this server for daily use, it makes sense to add the autostart feature and make it autonomous from your PC’s terminal. Here is how.
  • Optional: If you want to access your server from outside your local area network, you need to configure HTTPS. Here is how.

Discuss this topic in our Forum

2 thoughts on “Installing CAM-AI server on a Raspberry Pi”

  1. Pingback: Making a Raspi server autostart - CAM-AI: Articial intelligence for cameras

  2. Pingback: Enabling HTTPS on your Raspi server - CAM-AI: Articial intelligence for cameras

Comments are closed.

Scroll to Top