Camera Manager for SIYI A8 mini for RPi based on MAVSDK.
This tutorial is using a Raspberry Pi 4 (or 5) with Raspberry Pi OS 64 bits (based on Debian Bullseye or Bookworm) accessible over WiFi using ssh.
If you haven't already, I suggest flashing the RPi's SD card using the RPi imager. It allows you to set up login passwords, WiFi passwords and ssh support right there before flashing. Connect it to your WiFi, find the IP using your router's web UI, or look for open ssh ports to find the IP. If you have a hard time finding it, consider doing an nmap call before connecting it, and after and then diffing the output.
Note
If the automatic WiFi connection doesn't work, try the latest version of rpi-imager from the release page instead of the system installed one.
Connect the SIYI camera using the Ethernet adapter cable and an Ethernet cable into the RPi.
We need to set up a static IP for Ethernet in order to talk to SIYI:
Edit the file /etc/dhcpcd.conf
:
interface eth0
static ip_address=192.168.144.20/24
static routers=192.168.144.20
static domain_name_servers=8.8.8.8
nogateway
To enable it, just unplug Ethernet and plug it back in.
To set the ethernet connection to static, use nmcli
.
First, find the name:
sudo nmcli connection show
NAME UUID TYPE DEVICE
preconfigured XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX wifi wlan0
lo XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX loopback lo
Wired connection 1 XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX ethernet --
Now, set the IP for this Wired connection 1
:
sudo nmcli connection modify 'Wired connection 1' connection.autoconnect yes ipv4.method manual ipv4.address 192.168.144.20/24
The settings are saved to /etc/NetworkManager/system-connections/Wired connection 1.nmconnection
and persist reboots.
You can check the IP used:
ip addr
...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet 192.168.144.20/24 brd 192.168.144.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::2c28:c725:4499:e123/64 scope link
valid_lft forever preferred_lft forever
...
And you should be able to ping the camera:
ping 192.168.144.25
And see something like
PING 192.168.144.25 (192.168.144.25) 56(84) bytes of data.
64 bytes from 192.168.144.25: icmp_seq=1 ttl=64 time=0.368 ms
64 bytes from 192.168.144.25: icmp_seq=2 ttl=64 time=0.710 ms
64 bytes from 192.168.144.25: icmp_seq=3 ttl=64 time=0.175 ms
If you cannot ping 192.168.144.25
, first verify that the static IP address has been assigned by pinging the assigned IP.
ping 192.168.144.20
If this fails, make sure that you are using the correct Debian package to configure the static IP address.
If you can ping 192.168.144.20
but not the camera at 192.168.144.25
, this is most likely a netmask issue. However you interact with the network settings, make sure that the eth0
netmask is 255.255.255.0
and that no gateway is set.
In order to access the video stream from WiFi, we need to subscribe to the camera's RTSP server and open another RTSP server on the RPi.
This can be done using the rtsp-rebroadcast application which is using gstreamer.
In order to run the program, you can build it on device for prototyping (or use cross-compilation, or whatever deployment tool you use).
Install the gstreamer dependencies:
sudo apt install libgstreamer1.0-dev libgstrtspserver-1.0-dev build-essential cmake git
Get the source code, which is part of this repository, either using scp
, or via a git clone
.
git clone https://github.com/julianoes/siyi-a8-mini-camera-manager.git
Then build it on the RPi:
cd rtsp-rebroadcast
cmake -Bbuild -S.
cmake --build build
Then run it:
build/rtsp_rebroadcast
(by default there is no output)
To test the RTSP server, try to connect to it from another computer connected to the same network. Replace 192.168.x.y
with the IP of your RPI device.
Either using gstreamer:
sudo apt install gstreamer1.0-plugins-base-apps
gst-play-1.0 rtsp://192.168.x.y:8554/live
Or ffmpeg:
sudo apt install ffmpeg
ffplay rtsp://192.168.x.y:8554/live
Or open the URL in VLC.
Note that all these tools add quite a bit of buffering by default, so a delay of 1-3 seconds is quite normal.
In order to have QGroundControl auto-connect to the video feed and show camera settings, we can use a MAVLink camera server.
The camera manager is implemented using A small application on top of MAVSDK the RTSP URL, as well as camera settings.
Download the latest MAVSDK release as a .deb. For Raspberry Pi 4 running a 64bit image, this is using the package for the arm64
architecture:
wget https://github.com/mavlink/MAVSDK/releases/download/v2.12.12/libmavsdk-dev_2.12.12_debian12_arm64.deb
sudo dpkg -i libmavsdk-dev_2.12.12_debian12_arm64.deb
Clone or copy this repo on to the the RPi:
Then build:
cd camera-manager
cmake -Bbuild -S.
cmake --build build -j4
And run it, passing as positional arguments:
--connection
- How MAVSDK should connect to the Pixhawk, for serial:serial:///dev/serial/to/pixhawk:baudrate
--forwarding
- Whether to enable/disable forwarding (default: off)--stream-url
- Our IP (where RTSP video is available):rtsp://192.168.x.y:8554/live
E.g.
build/camera_manager --connection serial:///dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A907CB4L-if00-port0:3000000 --forwarding 'on' --stream-url rtsp://192.168.1.29:8554/live
or:
build/camera_manager --connection serial:///dev/serial0:3000000 --forwarding 'on' --stream-url rtsp://192.168.1.29:8554/live
There are at least three ways to connect a Pixhawk to the RPi 4:
Connect Telem 2 to the RPi's pin header pin 8 (GPIO14, UART Tx) and pin 10 (GPIO15, UART Rx), and GND.
Note that this requires bluetooth to be disabled.
In order for the serial connection to work, a couple of settings are required:
/boot/config.txt
: Add (or uncomment)enable_uart=1
and add (or uncomment)dtoverlay=disable-bt
./boot/cmdline.txt
: Removeconsole=serial0,115200
sudo systemctl disable hciuart
sudo reboot
There should now be a a serial device on /dev/serial0
respectively /dev/ttyAMA0
.
ls -l /dev | grep serial
lrwxrwxrwx 1 root root 7 Nov 2 18:35 serial0 -> ttyAMA0
lrwxrwxrwx 1 root root 5 Nov 2 18:35 serial1 -> ttyS0
Note that a user must be in the group dialout
to have access.
Connect Telem 2 to an FTDI cable plugged into the RPi. The serial device should be on /dev/ttyUSB0
as well as /dev/serial/by-id/usb-FTDI_...
, e.g.:
ls -l /dev/serial/by-id/ grep FTDI
lrwxrwxrwx 1 root root 13 Oct 31 21:55 usb-FTDI_FT232R_USB_UART_A907CB4L-if00-port0 -> ../../ttyUSB0
Note that a user must be in the group dialout
to have access.
Alternatively, just connect the Pixhawk's USB cable to the RPi. However, this is generally not recommended, as the NuttX USB port is not tested in-flight. Also, it blocks the port for a firmware update via USB.
In that case the serial device should show up as /dev/ttACM0
.
This currently only properly works with PX4 built from source from the main
branch and the latest release v1.14.3. The reason is that forwarding is broken with v1.14.2 and earlier.
For case 1 and 2, we need to configure PX4 to send out MAVLink on Telem 2.
To do so, set these params:
- MAV_1_CONFIG to Telem 2 (102). Then restart the Pixhawk!
- MAV_1_FLOW_CTRL to On or Off depending on whether you have RTS and CTS connected.
- SER_TEL2_BAUD to 3000000.
You can now try to connect using QGroundControl. Make sure to use the latest release. I've tested it using 4.4.1.
If everything works you should:
- See it connect to the Pixhawk.
- Display the video stream.
- Allow to take pictures, and record video (they should appear on the SD card).
- Show the camera interace and settings. The only settings available for now are the streaming resolution.
This could have a couple of reasons:
- Are both processes running, the rtsp-rebroadcast as well as the camera-manager?
- Are all arguments to camera-manager correct?