A Raspberry Pi (RPI) is a cheap, flexible and power-efficient platform that can easily be used as a wireless remote camera for Dragonfly. It can easily stream a video over Ethernet, WiFi or LTE with the proper equipment.
1 – RPI Hardware
The required hardware to create a Raspberry Pi streaming kit is the following one:
- Raspberry Pi motherboard: two different options are available:
- Raspberry Pi 3 B+: this is the most recent and powerful version of the RPI. For streaming, its main advantage is to have an integrated 5 GHz WiFi controller, which provides a much better connection than the older 2.4 GHz WiFi controller of the other boards.
- Raspberry Pi Zero W: this is the most compact and power efficient version of the RPI. It is also cheaper than the Raspberry Pi 3 B+, but it only comes with a weak 2.4 GHz WiFi controller.
- Micro SD card: 16 GB are sufficient to run the OS smoothly. We recommend to purchase a class 10 card to make sure the RPI will not be too slow.
- Fish eye CSI camera: any wide angle CSI camera with a frame-rate above 30 fps @ 640 x 480 can be used. Our recommendation is this SainSmart Wide Angle Fish-Eye Camera.
- (OPTIONAL) the following equipment can be useful in some cases:
- USB power bank: the power consumption of a RPI is very low and can run hours on small power banks. The power bank MUST provide an output of at least 2 Ampere.
- Case for the RPI: there are a bunch of cases for the different RPI models. They are often already provided with ready-to-go kits.
- Case/enclosure for the RPI camera.
- HDMI cable, USB keyboard and USB mouse: useful if you want to use the user interface to configure the RPI the first time. It is also possible to configure the RPI in headless mode though, as explained below.
Can I use the USB stereoscopic camera from ASTAR?
No, it can’t be used with Raspberry Pi up to 3B+ because the USB 2.0 ports do not deliver enough power. It might work on a Raspberry Pi 4 (it needs to be tested).
2 – RPI setup
2.1 – Camera physical connection
Those marked in BLUE are the slots to be used to connect the SainSmart Wide Angle Fish-Eye Camera to the RPI.
2.2 – Setup Raspbian Buster
OPTION 1 – Using the RPI graphic interface
Install the operating system
- Download to your computer the latest version of Raspbian Buster with desktop from here. We can only guarantee correct operation on Stretch and Buster.
- Download to your computer Etcher from here.
- Insert your micro SD card in your computer, and use Etcher to flash it with the downloaded image of Raspbian Buster with desktop.
- Insert the micro SD card in the Raspberry Pi.
- Plug your RPI to a monitor, plug a USB keyboard and mouse, and power the RPI.
- Follow the configuration wizard and connect your RPI to a Wi-Fi network.
Enable the SSH server and the Camera interface
You need to plug the camera to your RPI before following the instructions below.
- Open the LX Terminal on your RPI.
- Run the command:
sudo raspi-config
- Select Interfacing Options > SSH and enable the SSH server.
- Select Interfacing Options > Camera and enable the Camera interface.
- Select Advanced Options > Expand filesystem.
- Go back to the main screen click on Finish and confirm the reboot.
OPTION 2 – Without the RPI graphic interface (headless mode)
Install the operating system
- Download to your computer the latest version of Raspbian Buster Lite from here. We can only guarantee correct operation on Stretch and Buster.
- Download to your computer Etcher from here.
- Insert your micro SD card in your computer, and use Etcher to flash it with the downloaded image of Raspbian Buster Lite.
- Open a terminal window and
to the micro SD card using the following command:cd
cd /Volumes/boot
- In the
boot
drive, create a file calledssh
. Just an empty file with exactly that name.
touch ssh
- In the
boot
drive, create a file calledwpa_supplicant.conf
.
touch wpa_supplicant.conf
- Take an editor of your choice and add this to
wpa_supplicant.conf
and changeYOUR_SSID
andYOUR_PSK
parts according to your environment:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=<your_ISO-3166-1_two_letters_country_code>network={
ssid="<YORU_SSID>"
psk="<YOUR_PSK>"
key_mgmt=WPA-PSK
} - Insert the micro SD card in RPI and power it ON.
If you have problems connecting your RPi to the WiFi network please look at this thread.
Enable the Camera interface
You need to plug the camera to your RPI before following the instructions below.
- Open the terminal on your machine (Linux or macOS).
- Find the local IP assigned to your RPI (from now on
ip_of_the_pi
) using one of the methods of this guide OR launching this command (after having installed nmap):
#Replace 192.168.0.1 with the base address of your class C network.
sudo nmap -sP 192.168.0.1/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
- Run the following command and put
raspberry
as a password when requested:
ssh pi@<ip_of_the_pi>
- Run the command:
sudo raspi-config
- Select Interfacing Options > Camera and enable the Camera interface.
- Select Advanced Options > Expand filesystem.
- Go back to the main screen click on Finish and confirm the reboot.
2.3 – Setup Gstreamer
We use Gstreamer to stream the video. To install it enter the following commands on your RPI:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get -y install libgstreamer1.0-dev
sudo apt-get -y install libgstreamer-plugins-base1.0-dev
sudo apt-get -y install libglib2.0-dev
sudo apt-get -y install gstreamer1.0-libav
sudo apt-get -y install gstreamer1.0-tools
sudo apt-get -y install gstreamer1.0-plugins-good
sudo apt-get -y install gstreamer1.0-plugins-bad
sudo apt-get -y install gstreamer1.0-plugins-ugly
2.4 – Make your RPI a RTSP server
To make the RPI video stream a RTSP stream accessible you have to enter the following commands on your RPI:
- Check which Gstreamer version has been installed at point 2.3 using this command:
dpkg -l | grep gstreamer
- On this site look for the URL of the Gstreamer RTSP server compatible with the Gstreamer version installed at point 2.3
- Install the Gstreamer RTSP server using the following commands but please remember to edit the commands with the version of the Gstreamer RTSP server found in the site linked above:
wget https://gstreamer.freedesktop.org/src/gst-rtsp-server/gst-rtsp-server-1.14.4.tar.xz
tar -xf gst-rtsp-server-1.14.4.tar.xz
cd gst-rtsp-server-1.14.4
./configure
make
sudo make install - Install the raspivid wrapper gst-rpicamsrc using these commands:
cd ~
sudo apt-get install git
git clone https://github.com/thaytan/gst-rpicamsrc.git
cd gst-rpicamsrc/
./autogen.sh
make
sudo make install - Check, if gst-rpicamsrc is installed launching this command:
gst-inspect-1.0 | grep rpicamsrc
3 – Activate the RTSP streaming
- On the RPI launch this command (edit the command with the version of the Gstreamer RTSP server installed):
cd..
cd gst-rtsp-server-1.14.4/examples
./test-launch "( rpicamsrc bitrate=8000000 awb-mode=tungsten preview=false ! video/x-h264, width=640, height=480, framerate=30/1 ! h264parse ! rtph264pay name=pay0 pt=96 )" - The command above should return this:
stream ready at rtsp://127.0.0.1:8554/test
- Leave this terminal open and DON’T STOP THIS COMMAND.
4 – Make the video stream available to Dragonfly
- Launch Dragonfly.
- Click on the Configuration tab:
- Set the Camera source parameter to the following string (where ip_of_the_pi is the local IP address assigned to the RPI):
gstreamer:rtspsrc location=rtsp://ip_of_the_pi:8554/test latency=0 buffer-mode=auto ! rtph264depay ! avdec_h264 ! videoconvert ! appsink sync=false
- Set the Camera source parameter to the following string (where ip_of_the_pi is the local IP address assigned to the RPI):
- Click on Save and Restart.