Raspberry Pi Zero W - Streaming Webcam

I've been swamped by travel and things to occupy my time. But the $10 dollar Raspberry Pi Zero W has been on my list of things to do. I wanted to reuse a Logitech Webcam and use the Pi Zero W as an on demand streaming server.

The Pi Zero W is basically the circuit board with the empty row of header pins in the black plastic box with a clear top and sliding door to expose the header pins, if installed. It has one microUSB power port, one microUSB OTG power and communications port. And a microHDMI port to the right and a microSD card port on the right end. On the left end is a Pi Camera port.. which I didn't use.

I used a microUSB OTG to Type A USB 2.0 adapter, which immediately made a Left turn and blocked the lesser used (power only) microUSB port. The adapter has a pass thru microUSB port which is used to power the Pi Zero W.

The MACBOOK multi-function Lan Adapter is hanging off the USB 2.0 port and provides an Ethernet port, two Type A USB 2.0 ports, a full size SD card slot and microSD slot.. as well as having its own external power port.. should other devices need more power than the Pi can share over USB.

Both the multi-function adapter and the webcam get their power from the Pi over USB.

I have tested this with POE to microUSB and it works fine.. so CAT5 cabling to remote locations is possible.. even where WiFi is not available.. and there is no high voltage mains available.

The Noob or Raspbian Debian distro based on Jessie is the default start up Operating System and provides an LXDE desktop and a lot of apps in a meager 8 GB. I use a 32 GB microSD card and win32imager to write the raw disk image to the microSD card. The reason for over provisioning is write level wearing means the card lasts longer the more extra unused space is available.

Networking is configured to start up via DHCPv5 but has a flaw.. if the DHCP server isn't available a hard coded -1 option in the daemon startup defaults means it quits and doesn't continue to try to grab a dhcp address.. so very often in edge conditions.. the Pi will fail to obtain an IP address... and never try again.

The solution to that is hard code an IP address in the /etc/dhcpcd.conf file at the bottom of the file as specified in the dhcpcd.conf man pages. Doing the same for wlan0 might also be advised, as a backup measure.. but be careful of routing loops or duplicate default routes.

The Ethernet  setup involves

1. editing the /etc/dhcpcd.conf

pi$sudo vi /etc/dhcpcd.conf

.. and placing something like the following at the bottom

interface wlan0

static ip_address=

interface eth0

static ip_address=
static routers=
static domain_name_servers=

The WPA2/PSK setup involves

1. scanning the WiFi air space for SSIDs

pi$ sudo iwlist wlan0 scan | grep ESSID

2. using the wpa_passphrase command to generate a configuration stanza

pi$ sudo wpa_passphrase "testing"

.. which will prompt for the WPA2 pre-shared key (the WiFi password)

3. copying the output lines from the wpa_passphrase and putting them in

pi$ sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

.. after all of the lines already in that file

4. then performing a reboot or manually command ifup wlan0

pi$ sudo ifdown wlan0
pi$ sudo ifup wlan0

Setting up the Pi should always begin by running the command

pi$ sudo raspi-config

Its a whiptail (menu of menus) traversed with the keyboard and no mouse.

A gui version exists, but is incomplete.

Raspberry amd RealVNC have a shared history and Pi with Jessie now comes with a free Home use Cloud edition of RealVNC which can make the Pi desktop a "server" accessible from anywhere in the world.. similar to the Teamviewer style shared desktop programs over the Internet. One simply downloads the RealVNC "viewer" and it starts a cloud "address book" of all the RealVNC servers you have configured to attach to your cloud addressbook when they come online. From this addressbook a live connection can be established in spite of firewalls or nat routing challenges.

Every menu option should be looked at, the Pi is by default tailored for Great Britain and that locale, keyboard and timezones.. and many other options are not what you want to be using anywhere else in the world.. even the WiFi radio bands are configured here.

If you decide to disable the X-Windows server and run the Pi by command line only, the option is in the menu. If you want to start the SSH server, the option is in the menu.. all the basics you'll want to change are in these menus.. explore and be aware.. its cleaner than hacking at the infrastructure based on experience with other distros. (BTW) sshd is disabled by default, and permitrootlogin is set to prevent it.. to change either you'll need to visit the /etc/ssh/sshd_config file.

All of this to say you'll probably need a microHDMI and  and usb mouse and keyboard. I got along using a logitech RF mouse and USB nubbin to connect that to the Pi, then a Bluetooth keyboard using the Bluetooth systray icon to pair the keyboard with the Pi Zero W.

There are "unsafe" ways of post-writing the Jessie Pixel image to the sdcard (to) mount the filesystem and configure a few things.. but the hazards are real and time consuming.. go the monitor and mouse, keyboard route and it will go much faster and safer. Use the raspi-config command !

After all that you might want to apt-get update, and possible apt-get upgrade your version of the operating system; and use apt-cache search to find useful packages.

Not all useful packages are in the Debian Jessie repository however, some may need to be added to get packages of a more unique nature.

And some code drifts in and out of development favor and is only available by subversion or git repositories and must be compiled.

apt-get install vlc

is a nice one to have

mjg-streamer is also very nice to setup a streaming webcam, without fswebcam, ffmpeg or vlc but parts may support it.

This Raspberry Pi Forum article details how I got it working, following their directions and finally fixing the startup script main command line to avoid a typo and add the path to the webserver content.

mjpg-streamer: Blank Image and No Video

The result was a working streaming on demand server with "near" realtime framerate (24 fps), that starts automatically each time the Pi Zero W reboots.

The pages also demo the different client types, static snapshots, browser streaming, java applet streaming. javascript streaming, VideoLAN client streaming and finally a demo control panel for changing the camera UVC controls on the fly while streaming.