Chickens are very entertaining pets. Unfortunately, unlike indoor pets like cats and dogs, they live much of their life inside their coop, where I can't easily see them. But now, thanks to the chicken cam, I finally can spy on their hilarious antics!
This tutorial is made for MaaXBoard. It's based on this project by Eben Kouao for Raspberry Pi, so if you'd like a Pi version of this project, check out the tutorial here.
Obviously, this camera can be used for more than just chickens. It's great a pet camera, security camera, or just a camera for remotely watching the grass grow. This tutorial will take you from start to finish in setting up the coop cam.
Go through the headless setup on MaaXBoard. My full tutorial on getting setup headlessly, including expanding the file system, creating a non-root user, and installing remote desktop, is here. Below is a condensed version, since really you only need to be able to connect via SSH.
- Download the Debian image from the "Reference Designs" tab on Element14 and flash it to a 16-64 gig SD card. I use Balena Etcher to flash the board.
- Connect to your MaaXBoard using HDMI and a USB keyboard/mouse or via USB-TTL cable.
- Connect to wifi using the following commands:
nmcli r wifi on
nmcli dev wifi con "YOUR_SSID" password "YOUR_PASSWORD" ifname wlan0
nmcli device con wlan0
- Then save your WiFi credentials by editing wpa_supplicant.conf so the board will connect automatically when rebooted:
nano /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant
GROUP=wheel network={
ssid="YOUR_SSID"
scan_ssid=1
key_mgmt=WPA-PSK
psk="YOUR_PASSWORD"
}
- Reboot your board
When you type "ip a" in the maaxboard terminal, you should now be able to see your board's IP address. Now you can connect to your MaaXBoard from your host computer using SSH:
ssh root@[YOU IP ADDRESS]
HARDWARE SETUPConnect a camera to your MaaXBoardConnect a MaaXBoard camera or a USB webcam to your MaaXBoard. You can use any of the 2 USB ports on MaaXBoard or the 4 USB ports on MaaXBoard Mini to connect your camera. I'm using a Logitech webcam, but pretty much any webcam should work.
SOFTWARE SETUPFix out of date packagesUnfortunately, this still has to be done, even with the latest version of Debian on MaaXBoard. You can find more information on these fixes in my headless setup tutorial and here.
Fix these packages with the following commands:
apt-get update --fix-missing
apt-get install libdevil1c2 -y
apt-get reinstall libqmi-glib5 -y
mv /usr/lib/aarch64-linux-gnu/libOpenVG.so /usr/lib/aarch64-linux-gnu/libOpenVG.so.OLD
Create a virtual environment (optional)Creating a virtual environment is best practice when using python. In this tutorial, I'll be using virtualenv, but other virtual environments like conda or venv work as well.
First install wget, and then use wget to install pip:
apt install wget
wget https://bootstrap.pypa.io/get-pip.py
python3 ./get-pip.py
then install the package itself and remove the leftovers
pip install virtualenv virtualenvwrapper
rm -rf ~/get-pip.py ~/.cache/pip
Now edit our bash shell configuration file ~/.bashrc using nano
nano ~/.bashrc
and at the very bottom of it we add these lines:
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
Exit and save with CTRL+X and make sure you reload your shell config with:
source ~/.bashrc
Now create a virtual environment named cv:
mkvirtualenv cv -p python3
You can enter the “cv” virtual environment by typing:
workon cv
Note that the prompt has now the header “(cv)” in front of it, it means you are “inside” the new env. You can exit from the virtualenv anytime by typing:
deactivate
Install OpenCVOpenCV can be installed simply with the pip command (it will install numpy as well). If you created a virtual environment, make sure you're in your virtual environment before installing:
workon cv
pip install opencv-python
Test it out with the following command:
python -c 'import cv2; print(cv2.__version__)'
Install numpy and imutils as well:
pip install flask
pip install imutils
Download the source codeFinally, install git and clone the repository:
apt install git
git clone https://github.com/zebular13/pi-camera-stream-flask
cd pi-camera-stream-flask
RUN THE APPinside the pi-camera-stream-flask folder, type
python main.py
Note: if you're using the MaaXBoard camera instead of the Raspberry Pi Camera, change src=1 to src=0 on line 12 of camera.py.
In a web browser on your host PC, navigate to the address shown in the output, e.g. http://[MAAXBOARD IP]:5000
(here it's http://192.168.1.46:5000).
You should now be able to watch your chickens in real time!
You can now close your browser tab and open it back up whenever you want to see your chickens! To make sure your app starts if the board reboots, open /etc/profile:
nano /etc/profile
and add this line (include sudo at the beginning if not logged in as root):
workon cv
python pi-camera-stream-flask/main.py
If you plan to use actually this camera in a permanent installation, don't forget to set up a non-root user and password, and give your root user a secure password.
Comments