Raspberry Pi Zero 2 W Webcam

Raspberry Pi Zero 2 W with Raspberry Pi HQ Camera

I bought a Raspberry Pi model B revision 2.0 nine years ago and I’ve been using it with various cameras as a webcam server pointed out my window in places that I’ve lived.

A couple of weeks ago, I found a Raspberry Pi Zero W 2 in stock at Chicago Electronic Distributors, so I decided to switch my webcam from the Pi Model B to a Pi Zero 2 W. In the last iteration of my webcam, I was using Motion with the Raspberry Pi HQ Camera and the 6mm wide angle lens. With the Pi Zero, you also need the Pi Zero Camera Cable because of the smaller the CSI-2 camera connector.

On my Pi Model B, Motion had been crashing frequently with the errors, “unexpected camera control callback event, 0x4f525245” and “motion_watchdog: Thread 1 – Watchdog timeout Trying to do a graceful restart.” I was never able to sort out the problem after spending more time on it (here and here) than I wanted.

With the new Raspberry Pi Zero W 2, I had initially tried installing the just released Raspberry Pi OS, Bullseye, but I saw that other people were having some problems with Motion and Bullseye, so I installed Buster 10.11 instead.

I used the Raspberry Pi Imager app to setup the micro SD card. One thing that I had forgotten with the imager app was that using Ctrl-Shift-x will bring up an Advanced options dialog box where you can set the hostname, enable SSH, configure WiFi and locale settings. This makes it easier to do a headless setup. After I found the Pi Zero’s IP address on my network (by looking at the client list on my Asus router) I gave it a static IP address then used these great Circuit Basics instructions to setup Motion.

I also installed Apache Web server using the command:

sudo apt install apache2 -y

With the Pi Model B, I had the webcam’s address on a subdomain of my site. I used Dynamic DNS (on Google Domains, my registrar) to redirect to the IP address that my Pi was running on. Because I wanted to enable HTTPS on the camera URL, I got a certificate from Let’s Encrypt, so the URL, pizero.lesliewong.us:8081, was able to use the HTTPS protocol. IIRC, on the Model B, I was able to edit /etc/motion/motion.conf and add the lines:

stream_tls on
webcontrol_tls on
webcontrol_key /path to…/privekey.pem
webcontrol_cert /path to…/fullchain.pem

to enable HTTPS streaming. When I did that on my new setup, it didn’t work because the version of Motion that I installed wasn’t compiled with SSL/TLS support, which I found when I ran the command:

sudo systemctl status motion

After spending a lot of time trying to get that to work and failing using stream_tls, I found a way using the Apache Module mod_proxy:

sudo a2enmod proxy
sudo a2enmod proxy_http

I also added two lines to the file /etc/apache2/sites-enabled/000-default-le-ssl.conf (where /webcam is the URL on the domain, e.g., domain.com/webcam):

ProxyPass /webcam http://xxx.xxx.xxx.xxx:8081/
ProxyPassReverse /webcam http:// xxx.xxx.xxx.xxx:8081/

I was sort of surprised when it worked.

Riding a Bike on the Golden Gate Bridge

In this video, I’m riding my bike south towards San Francisco around the north tower of the Golden Gate Bridge. I used a GoPro HERO3+: Silver Edition to capture the video. The occasional clicking sound is the downshifting of my Campagnolo Chorus Ergopower controls.

In the video poster frame, you can see the water just outside San Francisco Bay in the gap between the orange barriers. That doesn’t help my acrophobia, especially knowing that there is a 227 foot drop to the water. And it’s only blocked by a temporary Cyclone fence.

There’s almost always a constant wind off the Pacific Ocean, blowing across the bridge to the east . This year, the bridge authority retrofitted the railings to withstand 100 mph gusts. Now, when the wind is >25 mph, the new sidewalk railings emit a deafening hum that can be heard miles away. Add the sound of cars and trucks three feet away going south at 50 mph, it’s not a wonderful experience.

I just try not to look to the right.

Updating the Raspberry Pi Webcam

Update (January 25, 2021) My Raspberry Pi powered webcam is now showing the Jordan Park Neighborhood in San Francisco, California. The Raspberry Pi Model B, Rev 2 is using the Raspberry Pi High Quality Camera (with the Raspberry Pi HQ Camera Lens – 6mm Wide Angle) and is running Motion (pi_buster_motion_4.3.2-1_armhf). Details to follow.

(Original post) I built a streaming webcam showing the view from my downtown Oakland apartment in November 2012. I used a Raspberry Pi (Model B Revision 1.0) and the Raspian Wheezy (2012-10-28) image. For the webcam/web server software, I used MJPG-streamer. The problem with MJPG-streamer is that if the images/stream is available on the internet, then anyone can access the software.

Recently my Raspberry Pi began to lose the WiFi connection. In researching various solutions, I disabled WiFi power management on the Edimax EW-7811Un nano-size USB WiFi adapter. That didn’t solve the problem. I switched to Ethernet but the connection still dropped.

I found a nice script for “Rebooting the Raspberry Pi when it loses wireless connection“. It’s a script that runs in crontab and checks for a network connection by pinging a local address. If the ping fails, it restarts wlan0.

The checkwifi.sh script worked great, but then I had an issue with the video stream image oscillating. The image would continually go between light and dark and the only way to stop it was to restart MJPG-streamer.

I decided to update to the current Raspbian Jessie with Pixel and some other webcam software. The Motion-Project seemed not to difficult – I could use it as a streaming webcam. I decided to use Motion 4.0 and Kenneth Lavrsen’s Motion 4.0 Guide to help set it up. I don’t know if the image oscillation is an issue caused by using the Creative Live! Cam Chat HD (auto exposure?) but this current setup seems to have resolved the issue.