On this page I will summarise the steps needed to setup your Raspberry Pi for video streaming. I’m going to be configuring the system with the Edimax EW-7612UAn V2 wifi stick. This is a 2.4 GHz device and while we eventually want to use the 5 GHz band, for now this device has proven totally reliable on all versions of the Raspberry Pi. I will also cover setting up a Linux PC to receive and display the stream.
To prevent things from getting confusing with lots of options across different platforms, I’m only going to cover the procedure I use. This is based on using a Windows 7 PC for doing most of the installation and configuration.
I’m working on a download and script that will automate many of the following steps. I will keep and update this page to show all the steps for those who want to know what has been done and to aid with debugging if in future a Raspbian update causes an issue. The download and instructions for its use should be published in the next couple of weeks.
Setting Up the Pi
Download the necessary files
- Download and install Win32 Disk Imager on your PC from Sourceforge:
- Download and unzip the latest Raspbian Image from RaspberryPi.org :
- Download and install the putty ssh client:
- Optionally you can download and install WinSCP. It’s useful for transferring files between your PC and Pi.
Copy Raspbian to your SD Card.
- Insert your SD card into your computers card slot or use a USB card reader. Take a note of the drive letter allocated to the card (E.g. E:).
- Launch Win32DiskImager and make sure the selected Device matches the SD card location ( [E:\] ). Having the wrong letter here will corrupt that drive.
- Click the small blue folder icon and select the expanded Raspbian image.
- With everything set click the Write button. You will get a last chance warning about overwriting the drive. Click ‘Yes’ if you are happy to continue.
- Once the image has been written, a small ‘Done’ message box will pop-up. Click the button and then Exit Win32DiskImager.
- Eject/Safely remove the SD card from your computer and insert into your Pi.
Raspbian Configuration and Update.
- Connect the camera to the Pi.
- Connect your Pi to a monitor and keyboard.
- Power it on.
- Once the boot sequence is completed you will be dropped straight into raspi-config.
- Hit ‘Enter’ on “Expand the Filesystem” to fill the SD card and the ‘Enter’ again to clear the “resize on next boot” notice.
- Use the down arrow key to select “Enable Camera” and hit ‘Enter’. On the next screen use the right arrow to select ‘<Enable>’, then hit ‘Enter’ again.
- Enter “Advanced Options” and then “Hostname”. Give your install an identifiable name.
- Ssh should already be enabled, but if you want to check, go back into “Advanced Options”, select “SSH” and then ‘<Enable>’.
- If you haven’t already connect the Pi to your LAN.
- Press the Tab key a couple of times to select ‘<Finish>’ and then press enter to exit raspi-config and reboot the Pi.
- When the boot sequence completes you will see the login prompt and above it the network address. In this case 192.168.1.114
- You can continue the configuration directly on the Pi, but I prefer to switch to ssh so that I can continue working on other stuff, while the Pi chugs away downloading and installing packages. It also makes it easy to copy and paste commands and file contents without using the X desktop.
- Launch putty and enter the IP address. I like to save the address as a session as I go along to save having to type the full IP address every time. When you are ready to proceed, click ‘Open’ to launch a command window.
- At the prompt login as pi
- unless you changed it in raspi-config the password is raspberry
- The first task is to update the base system. The number of packages that need updating will depend on how long it’s been since the base image was released. First we need to update the package catalogue.
sudo apt-get update
- Then we upgrade the currently installed packages.
sudo apt-get upgrade
- Now is a good point to test the camera
- While we are here, we may as well generate an ssh key pair. We probably will never need the keys, but in doing so, we will create the ~/.ssh directory structure that will be needed later on. Just hit enter for all the options offered.
For this example had hoped to use the Tenda W522U 300Mbps Dual Band Wireless N USB Adapter, as its chipset is natively compatible by hostapd. To my knowledge, it is currently the only dual band adapter that works “out of the box” on the Raspberry Pi. The problem is that in 2.4GHz mode it is Slooooooowwwwww and it doesn’t have a high gain antenna, so range will be limited. Having run some comparative tests there is no point in recommending it, even in 5GHz mode.
Because of the problems with the W522U, I’m sticking with the 2.4 GHz band Edimax EW-7612UAn V2 has proven very reliable over the last year.
I default to using vi for editing configuration files. If you prefer a different editor like nano then replace vi with nano in the commands below.
- If it’s not already connected, plug in your USB WiFi adapter and reboot with:
- As a time saver you may want to create some aliases for shutdown and reboot. These are set in the .bash_aliases file.
Paste in the following
#!/bin/bash alias shutdown='sudo shutdown -hHP now' alias reboot='sudo reboot'
From the next time you login you will be able to type ‘reboot’ instead of ‘sudo reboot’ and ‘shutdown’ instead of ‘sudo shutdown -hHP now’
- We are aiming to use this system for FPV where most radio control systems work on the 2.4 GHz band which is also the main band used for WiFi. Ideally, we want to use the 5GHz band, especially now that Raspberry Pi compatible dual band USB Wifi dongles are starting to become available. The problem is that the 5GHz band is more regulated, so we need to install the Central Regulatory Domain Agent (CRDA) package that controls which frequencies and features are available to your country. Hostapd does not work with the world domain (00). You have to be specific. To get the necessary package use:
sudo apt-get install iw crda
- Then to set the CRDA region edit the file /etc/default/crda
sudo vi /etc/default/crda
- Append your domain to the line “REGDOMAIN=”, which in my case is GB
- Next we can set the IP address for the WiFi adapter in the /etc/network/interfaces file
sudo vi /etc/network/interfaces
- Edit the file to look like this:
iface default inet dhcp iface lo inet loopback auto eth0 allow-hotplug eth0 iface eth0 inet dhcp auto wlan0 iface wlan0 inet static address 192.168.42.1 netmask 255.255.255.0
Some people like to include “allow-hotplug wlan0”, however I found in the previous build of Raspbian that this caused some issues with ifplugd dropping the IP address when hostapd started.
- With the file saved, reboot.
- Login again and check that wlan0 has an IP address using:
ip addr list
- The next task is to setup the Pi as a WiFi access point, so we need to install hostpad. As a convenience we will also install dnsmasq to hand out IP addresses to client computers. Once everything is working as expected we give the receiving computer a fixed IP address to reduce the connect and reconnect times. I’ve also added haveged to the install. This helps provide a pool of good entropy to hostapd for WPA encryption. You can manage without it, but may see lots of warnings about /dev/random having insufficient entropy.
sudo apt-get install hostapd dnsmasq haveged
- The Edimax EW-7612UAn V2 wifi stick uses a Realtek chipset which does not provide a standard nl80211 interface so can’t be used with the default hostapd installation. We install it anyway to get all the startup/shutdown scripts. Realtek provide a custom version of hostapd on their website as source code. This has to downloaded, extracted, compiled and installed. The download can be found on the realtek website at http://www.realtek.com/downloads/downloadsView.aspx?Langid=1&PNid=48&PFid=48&Level=5&Conn=4&DownTypeID=3&GetDown=false&Downloads=true#RTL8192CU
Pick the download location to nearest to you and download the file to your PC.
- The download is a zip file with a long name like: 0001-RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911.zip. If the filenames have changed for newer versions then adjust the commands below to suit.
- Open the zip file and work your way through the directory structure until you get into the wpa_supplicant_hostapd directory.
- Extract the wpa_supplicant_hostapd-0.8_rtw_r7475.20130812.tar.gz file to your downloads directory and then use WinSCP to copy it onto the Pi.
- On the Pi extract the contents of the file with the command
tar zxvf wpa_supplicant_hostapd-0.8_rtw_r7475.20130812.tar.gz
- Step down into the new directory and then to the hostapd directory.
- Type make
Then go and make a drink while hostapd is compiled.
- When compilation is finished, we need to replace the default hostapd executables with the Realtek ones.
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd_nl80211 sudo mv /usr/sbin/hostapd_cli /usr/sbin/hostapd_cli_nl80211 sudo cp hostapd /usr/sbin/hostapd sudo cp hostapd_cli /usr/sbin/hostapd_cli
- To configure hostapd we need to create/edit its config file.
sudo vi /etc/hostapd/hostapd.conf
- The configuration below covers a basic 2.4GHz setup using the Edimax EW-7612UAn V2 stick. Make sure there are no spaces on the ends of lines or you will get an error when you try to run hostapd.
interface=wlan0 driver=rtl871xdrv ctrl_interface=/var/run/hostapd ssid=Pi_AP channel=13 beacon_int=100 hw_mode=g ieee80211n=1 wme_enabled=1 wpa=2 wpa_passphrase=Raspberry wpa_key_mgmt=WPA-PSK wpa_pairwise=CCMP max_num_sta=8 wpa_group_rekey=86400
- To have hostapd start at boot we need to edit the file /etc/default/hostapd.
sudo vi /etc/default/hostapd
- Uncomment the DAEMON_CONF line and add the path to the hostapd config file. You can add the debug message option if you want.
- With the previous release of Raspbian, I couldn’t get a reliable WiFi connection from hostapd. After days of searching I found the solution at Sirlagz.net. The ifplugd config file has been changed to make all the network interfaces hot-plugable. This was causing the interface to be dropped when hostapd tried to start. To fix it we need to edit the file /etc/default/ifplugd.
sudo vi /etc/default/ifplugd
- Change the INTERFACES and HOTPLUG_INTERFACES to “eth0”
- Test the access point. This will make the access point visible to your PC (assuming it has WiFi) or you can use an phone app like WiFi analyzer. Use Control-C to exit.
sudo hostapd -d /etc/hostapd/hostapd.conf
- At this point you may wish to reboot again to check hostapd comes up at boot time and that wlan0 is still being given an IP address.
- With hostapd working the final network package to configure is dnsmasq. Create a custom config file:
sudo vi /etc/dnsmasq.d/dnsmasq.custom.conf
- Paste in the following
interface=wlan0 dhcp-range=wlan0,192.168.42.10,192.168.42.50,2h # Gateway dhcp-option=3,192.168.42.1 # DNS dhcp-option=6,192.168.42.1 dhcp-authoritative
- One final reboot to check all is working.
- Now you should be able to connect to the access point from your computer or phone. Windows will show a warning triangle as it cannot connect to the internet through this connection, but putty should be able to connect to 192.168.42.1.
Gstreamer and GPS installation.
- Almost there. We need a lot of packages for gstreamer, but we can get them with a single target.
sudo apt-get install gstreamer1.0
- If you want to log your position using a GPS then install these packages as well.
sudo apt-get install gpsd gpsd-clients
Get the scripts
- You can download a tarball of the scripts from Google Drive. The command below will download and extract the files in one shot.
wget -O - https://goo.gl/As56Za | tar zxvf -
Alternatively you can download the file to your PC, copy it across using WinSCP and then expand it using:
tar zxvf AirSideScripts.tgz
Setting up the Receiving Computer.
For my system I use my Dell XPS 17 laptop, simply because it’s what I’ve got. Although it is Windows 7 based, I have repartitioned the disk so that I could create and dual boot a Lubuntu installation. I choose this as a lighter weight version, which should hopefully allow gstreamer to run faster, although I have no evidence to suggest it does. I’m using version 13 because my WiFi card didn’t work very well in 14. I’m not going to cover installing Lubuntu; there is plenty of information on the Web if you need help.
- The first task is to establish the WiFi connection to the Pi. If you have used my hostapd.conf file then look for an access point Pi_AP and use Raspberry for the WPA key.
- Open a Terminal window.
- We need to create a key pair for ssh so that we don’t need to enter a password every time we connect.
Just hit enter for all the options offered to you. We don’t want a password as this would negate the whole point of creating the keys for this application.
- Next we copy the public key to the Pi. The ~/.ssh directory should already exist from step 29 above.
scp ~/.ssh/id_rsa.pub email@example.com:.ssh/authorized_keys
This should be the last time you will need to enter a password.
- Open a new terminal window and try to connect to the Pi. If the previous step was successful you should be able to connect without entering a password.
- That’s configuration complete
- For details on using the installed scripts have a look at the “Script Usage” Section on the “Current Raspberry Pi Scripts Page”.