Wifibroadcast FPV manual setup
The following section assumes the use of Raspberry Pi’s running raspbian on both the tx and rx side with AR9271 wifi dongles (2.4GHz TP-LINK TL-WN722N for example).
As a first step you need to clone the wifibroadcast repository on your tx raspberry pi:
sudo apt-get install mercurial hg clone https://bitbucket.org/befi/wifibroadcast
Next, you need to install a patched firmware for the wifi card that sets the data rate of the injected packets to 26mbit/s:
sudo cp wifibroadcast/patches/AR9271/firmware/htc_9271.fw /lib/firmware
Optinally, you can also patch the kernel driver to set the output power of the card to a fixed level as described here. This helps to increase the maximum range. By default, the kernel patch sets the cards power to 20dBm. But if your country and hardware allows you to use higher power you can adapt the max_power value inside the patch.
Now the wifibroadcast project needs to be compiled:
sudo apt-get install libpcap-dev iw cd wifibroadcast make
To transmit video into the air you need to put the wifi card into monitor mode and start the tx program:
sudo killall ifplugd #stop management of interface sudo ifconfig wlan0 down sudo iw dev wlan0 set monitor otherbss fcsfail sudo ifconfig wlan0 up sudo iwconfig wlan0 channel 13 raspivid -ih -t 0 -w 1280 -h 720 -fps 30 -b 4000000 -n -g 60 -pf high -o – | sudo ./tx -b 8 -r 4 -f 1024 wlan0
The LED of your wifi card should blink indicating that you are transmitting video data of your camera into the air.
On the receiver side you also need wifibroadcast installed:
sudo apt-get install mercurial libpcap-dev iw hg clone https://bitbucket.org/befi/wifibroadcast cd wifibroadcast make
Additionally, you need a program to decode and view the video stream:
cd $HOME hg clone https://bitbucket.org/befi/hello_video cp hello_video/video.c /opt/vc/src/hello_pi/hello_video cd /opt/vc/src/hello_pi/ ./rebuild.sh
Then you can go back to wifibroadcast and start the application:
cd $HOME/wifibroadcast sudo killall ifplugd #stop management of interface sudo ifconfig wlan0 down sudo iw dev wlan0 set monitor otherbss fcsfail sudo ifconfig wlan0 up sudo iwconfig wlan0 channel 13 sudo ./rx -b 8 -r 4 -f 1024 wlan0 | /opt/vc/src/hello_pi/hello_video/hello_video.bin
And voilà, you have finished your wifibroadcast setup 🙂
You can also watch the stream on a normal GNU/Linux PC using gstreamer:
#setup of wifi card is identical to that of the PI (see above) sudo ./rx -b 8 -r 4 -f 1024 wlan0 | gst-launch-1.0 -v fdsrc ! h264parse ! avdec_h264 ! xvimagesink sync=false
Starting things automatically
Since you don’t want to type all these commands each time before you use wifibroadcast, scripts are provided for starting everything automatically.
cd #go into home directory hg clone https://bitbucket.org/befi/wifibroadcast_fpv_scripts cd wifibroadcast_fpv_scripts sudo cp init.d/wbctxd /etc/init.d sudo update-rc.d wbctxd start
After a reboot the video transmission should start automatically. If you want to change the parameters of the transmission just edit the file “wifibroadcast_fpv_scripts/tx.sh”.
The basic setup is analogue to the tx side:
cd #go into home directory hg clone https://bitbucket.org/befi/wifibroadcast_fpv_scripts cd wifibroadcast_fpv_scripts sudo cp init.d/wbcrxd /etc/init.d sudo update-rc.d wbcrxd start
Again, the parameters of wifibroadcast are found in the file “wifibroadcast_fpv_scripts/rx.sh”
The rx.sh script gathers all wifi sticks connected to your Raspberry and uses them for diversity reception (to increase diversity just plug more sticks into the PI). However, there are two things to note: First, the script puts all wifi sticks into monitor mode. So if you use one wifi stick for connection to you wifi network (to get ssh access for example) this script will cut your connection. You can avoid this by listing all wifi devices explicitly in rx.sh NICS variable. The second thing to note is that each wifi sticks adds usb traffic to the PI. You have to test how much traffic it can handle (depends on the video data rate and redundancy settings). Tests have shown that the PI2 can handle much more traffic than its predecessors.
The Rx PI can automatically record video data onto a USB-stick. To enable this feature, you need to install the usbmount tool:
sudo apt-get install usbmount
To get decent write speeds you need to remove the “sync” option in the file “/etc/usbmount/usbmount.conf”.
Now connect the USB-stick and create the required directory:
If you now reboot, the received video will be recorded. Recording is disabled automatically if you boot without USB-stick or with a stick without the “video” directory.
The videos are saved in a raw h264 format. To convert them so that they are compatible with VLC or Youtube, you can use a helper script also provided in the repository. This should be done on your PC instead of the Raspberry.
sudo apt-get install avconv hg clone https://bitbucket.org/befi/wifibroadcast_fpv_scripts cd wifibroadcast_fpv_scripts/utils
To convert the raw video “0.rawvid” int the file “0.avi”:
./h264encaps 48 /tmp/0.rawvid /tmp/0.avi
Especially if you are recording video you want to have a clean shutdown where all the data gets written properly to your disks.
A simple way to do so is to connect a pushbutton with one leg to the raspberry GPIO pin header #22 (which is gpio no. 25) and the other leg to 3.3V and also a resistor > 1k between the GPIO and GND. Then you can install the following scripts from the repository:
cd #go into home directory cd wifibroadcast_fpv_scripts sudo cp init.d/shutdown /etc/init.d sudo update-rc.d shutdown start
Now a button press for at least a second should bring the system to halt and you can safely remove the power.