Some of this content is Depreciated!
Read Sinamics for updated configuration.
New complete RPI software script package (UAVcast) ready for implementation. Read here for further information.
Added UQMI instructions for cellular 4G LTE
This guide will explain the installation of RPI with video stream using USB Webcam and live telemetry from your aircraft.
If you succeed you should be able to fly your aircraft by cellular network and simultaneous have live video feed and telemetry.
Imagine flying your drone by USB gamepad and as loong as the battery holds, and guess what, its possible!
First we need to get some tools (programs) which allows us to communicate with the Rpi and so on.
there are many diffrent way to interact with rpi, and google will help you on the way. Anyway, here is the basic programs im using.
- SSH client Bitvise tunnelier
- FTP client Total Commander
Install RPI image Whezzy First get hold of Debian Wheezy Image and install that image to the SD card.
(Instruction can be found at Rpi site) Connect your RPI to your local network with ethernet cable.
Before you move on, you need to know the IP adress to your RPI. This you will find in your router or you can download Netscan software form internet which will search all ip adresses on your local network. Im using this one
Start Bitvise tunnelier on you laptop, enter the ip adress to the RPI and type in Username & password
default (pi, raspberry )
Hopefully you should be able to connect with RPI and have a command window like this:
Start the RPI config panel with this syntax.
Set your lanuage and desired settings.
Im also expands-filesystem. Gives you more free space to work with,
Save and reboot.
Install FTP server
This will allow us to connect RPI with total commander or any other ftp client.
It could be more convenience to use than vi editor. You will also find it handy to use when moveing files from your computer to rpi.
sudo apt-get install proftpd
Setting up DynDns
Next we will install DynDns software which allows us to use a dynamic name to connect our laptop to RPI when using cellular network.
This is not required if your cell operator gives you static ip adress, but normally they dont. So instead of finding your cell IP adress every time, we use Dynamic andress of your choice.
There are many DynDns vendors, pick one. Im using www.no-ip.com
Create a account and a Host name.
Lets say for this tutorial your host (dns) are myairplane.no-ip.info
Install Inadyn software into RPI which will sync your IP against your dns.
Type this syntax
sudo apt-get install inadyn
Then we need to change the config to match our account at No-Ip
sudo vi /etc/inadyn.conf
If the file above do not exists, it will create one.
paste in the bellow lines and change your username and password to your needs. (same credentials to log on No-Ip site)
Type your DynDns adress as alias. ( for this tutorial we use myairplane.no-ip.info.
If you are using dndns.org dont change the dyndns_system.
If you e.g using no-ip.info, change the dyndns_system to firstname.lastname@example.org
Then we need to add this to startup script, so we dont need to start inadyn manually.
Type this syntax, just before the exit 0.
add this line
Great, Now rpi should sync myairplane.no-ip.info to rpi IP adress on bootup.
If you are connected to your local network, this adress will point to your external ip adress, (your broadband). To verify correct behavior of inadyn, type this syntax
more /var/log/messages |grep INADYN
If eveything whent successfully, you should see something like this
Im also using one dynamic adress for my laptop ( Ground Control Station ) so i always know the adress without having to find the IP adress on every startup.
My aircraft (rpi) has one Dynamic adress: e.g myairplane.no-ip.info
My laptop has one Dynamics adress: e.g mygcs.no-ip.info
Then i always know the adresses to connect my aircraft or laptop independent of the acutal IP adress. It will be more convenience to work with.
Next we will install gStreamer which allows us to grab the video stream from your web cam.
We need to download some more programs.
Run these lines.
sudo apt-get install gstreamer1.0
now, if everything went successfully, you should have installed gstreamer.
You can verify by typeing this line
It should print out a bunch of lines without errors.
Next, connect your usb webcam to usb port. And then type this command
You should see your webcam in that list.
Also verify that you have /dev/video0 availible.
sudo ls /dev/video0
Then we need to get the correct syntax for gstreamer to start streaming our picture to a desired adress and port. See attached gstreamer.sh file.
v4l2-ctl --set-fmt-video=width=360,height=288,pixelformat=1 v4l2-ctl -i 1
gst-launch-1.0 -v \
rtpbin name=rtpbin v4l2src device=/dev/video0 \
! video/x-raw,width=352,height=288,framerate=15/1 \
! queue \
! omxh264enc target-bitrate=500000 control-rate=1 \
! "video/x-h264,profile=high" \
! h264parse \
! queue max-size-bytes=10000000 \
! rtph264pay pt=96 config-interval=1 \
! rtpbin.send_rtp_sink_0 rtpbin.send_rtp_src_0 \
! udpsink port=5000 host=$ip ts-offset=0 name=vrtpsink rtpbin.send_rtcp_src_0 \
! udpsink port=5001 host=$ip sync=false async=false name=vrtcpsink udpsrc port=5000 name=vrtpsrc \
This file should be enough to start gstreamer porperly.
change the ip adress to where you want to receive your stream. You may want to create another Dynamic adress for your laptop or wherever you want to retrive this pipeline.
To test this on your local network, type in your laptop ip adress.
To find your IP -> On windows Win + R type cmd
In the command prompt type ipconfig
For this tutorial we use 10.0.0.225 ( My local laptop IP adress )
copy file to RPI. e.g /home/pi
You can use Bitevise or FTP program to copy your file. Then we need to set some permission to this file with the this syntax
chmod 755 /home/pi/gstreamer.sh
Try to start gstreamer with this command
sudo sh /home/pi/gstreamer.sh
if everything went well, you should see something like this.
A bounch of unreadable data..
Great. gStreamer should now stream to your desired IP adress. Add gStreamer to startup script We need to copy the gstreamer.sh script to /etc/init.d/ folder.
Type this syntax. We also removes the wolfram-engine, as we dont need it, at it will save you 460MB.
sudo cp /home/pi/gstreamer.sh /etc/init.d/
sudo apt-get remove wolfram-engine
sudo update-rc.d gstreamer.sh defaults
Dont mind if you get LSB tag errors.
Reboot your RPI and then type
sudp ps ax
you should now see that gst-launch1.0 are added to your process list .
We are now ready to retrive the video on our laptop. I will explain using both gstreamer & vlc.
gStreamer for Windows.
Get the gstreamer installation package for windoes here
Install the package and then navigate to the installation bin directory. e.g gstreamer\1.0\x86\bin
Then open windows command prompt in that directory. left shift + right click. "Open command line here".
Then type this syntax to start gstreamer to listen for any video stream at port 5000.
If your RPI are streaming, you should get a picture right away.
gst-launch-1.0 -v udpsrc port="5000" caps="application/x-rtp,media=(string)video,
(uint)1584170994,seqnum-base=(uint)42626" ! rtph264depay ! decodebin! autovideosink -v
If you don't have the VLC installed, you can get it here
Save the attached vlc.sdp and run it.
You are now a proud person and cant wait to test this in air.
Next i will explain the telemetry configuration and methods which can be used.
I guess you all have heard about UDP & TCP , and there are many dicussions about which is best and so on. I will not explain the diffrent between those two, there is a lot of documentation out there.
Google is our friend.
I allways prefer UDP for this kind of use, as we dont need the extra features / safety TCP provides.
Anyway, lets start of and explain the data flow and how all works out.
Lets say we have a APM or Pixhawk (or whatever flight controller availlible) and we want that telemetry stream flow trough internet and to our computer.How is that possible? releax, its not that hard.
The basics, Our flight contoller sends out telemetry in serial data packages, and all we need to do is routing those packages to where we want, and normally our GCS. I will recommend to use TTL to Ethernet converter which alows us to convert serial data from flight controller to Ethernet RJ45 at UDP.
Then just connect that ethernet to RPI RJ45 port.
Fligth Controller tx/rx -> TTL to Ethernet -> RPI udp_redirect -> GCS e.g mission planner
This is from one of my lates projects, and you can see how the TTL to Ethernet are wired up to RPI.
TTL adapter needs to be configured as UDP sever before use.
Then we need to tell RPI that all those packages should be routed to adress we desire. For that we need to install a script called UDP_REDIRECT . Download the udp_redirect file and copy to your rpi /home/pi and compile it with the following code:
gcc -o udp_redirect udp_redirect.c
./udp_redirect our-ip our-port send-to-ip send-to-port
./udp_redirect our-ip our-port (echo mode) Example:
./udp_redirect 0.0.0.0 53 192.168.0.1 53 ./udp_redirect 0.0.0.0 7
You could also make a script such as bellow and run it in boot up sequence. Create a new file
sudo vi /home/pi/udp-send.sh
Copy and paste the bellow code, change the DNS to match yours.
ip=`dig +short YOUR_GCS_DYNDNS`
echo $ip /root/udp_redirect 0.0.0.0 14550 $ip 14550 &
Then we add this file to our startup script.
sudo cp /home/pi/udp-send.sh /etc/init.d/
sudo update-rc.d udp-send.sh defaults
For testing, you could start the script manually by typing
sudo sh /home/pi/udp-send.sh
If you have connected the tx/rx from flight controller to TTL adapter correct ( tx -> rx & rx -> tx) , it should start streaming to your adress right away, But hey, our RPI are not connected to internet..
We fix. USB cellular adapter. Using Sakis3g(3G) or UQMI(4G LTE) You need to choose either sakis or uqmi. I will recommend to use sakis3g for linux beginners, as UQMI can be tricky to configure properly.
Sakis3g This is probably the most easy part, as sakis3g has a nice user interface to work with.
Connect your usb adapter to rpi, im using ZTE MF821D which works out of the box. No issues.
When connected type the following
you should see the adpater in that list. And write down the ID, we need that later on,.
Now we need to install the sakis3g.
sudo mkdir /usr/bin/modem3g
sudo chmod 777 /usr/bin/modem3g
sudo cp sakis3g.tar.gz /usr/bin/modem3g cd /usr/bin/modem3g
sudo tar -zxvf sakis3g.tar.gz sudo chmod +x sakis3g
Now you should be able to start sakis with the following command.
sudo ./sakis3g --interactive
This will open a user interface, and just follow the instruction.. Then we could add this to the startup script as well.
sudo vi /etc/rc.local
add these lines. Note! You need to change the ID & APN & USBinterface to mach yours.
./sakis3g "--sudo" OTHER="USBMODEM" USBMODEM="19d2:0167" "FORCE_APN=internet.public" USBINTERFACE="3" APN_USER="user" APN_PASS="user" "connect" "info"
If everything are correct, it should connect on reboot. Now, all you need to configure is the mission planner and the Game pad.
UQMI (Suppors 4G LTE)
Thanks to Antiec for this great instructions.
Read discussion thread HERE
Tested and works on RPI 2.
sudo apt-get update
apt-get install usb-modeswitch
apt-get install cmake
sudo apt-get install dh-autoreconf
sudo apt-get upgrade
sudo apt-get install dnsutils
tar -xvf json-c-0.12.tar.gz
sed -i s/-Werror// Makefile.in && ./configure --prefix=/usr --disable-static && make -j1
git clone https://github.com/UAVmatrix/libubox.git libubox
cmake CMakeLists.txt -DBUILD_LUA=OFF
sudo make install
mkdir -p /usr/include/libubox
cp *.h /usr/include/libubox
cp libubox.so /usr/lib
cp libblobmsg_json.so /usr/lib
Then git, compile and install uqmi
sudo git clone git://nbd.name/uqmi.git
sudo cmake CMakeLists.txt
sudo make install
uqmi -d /dev/cdc-wdm0 --network-register
uqmi -d /dev/cdc-wdm0 --start-network --auth-type both --username user --password user
--keep-client-id wds --autoconnect
Release new ip
dhclient -v wwan0
Stop network syntax (Reset)
uqmi -d /dev/cdc-wdm0 --stop-network 4294967295 --autoconnect
Game Pad & Mission Planner
Thx to @chuckster1 who provided this link.
Read that link and you should now how to set up the game pad.
All failsafe function will remain as before.
Read this article http://plane.ardupilot.com/wiki/arduplane-setup/apms-failsafe-function/