Monitoring with motion

tabofa
4 min readMar 4, 2021

I recently downloaded an app that would allow me to create a video feed using a mobile phone and then connect to it and see the feed. This worked decently. I could get the image rolling on the screen. It’s nice since the setup was minimal and the walkthru in the app was decent in explaining what was expected of me to get it to work.

Well up an running I started noticing connectivity issues, sometimes the feed would freeze. The app would still be happy, and display it as running. This wasn’t optimal. The phone I was using to record with, apparently, had terrible night vision properties. If there was a low-lit room, like the room I wanted it to record from, the screen was completely black.

To make matters worse; this feed could be accessed from anywhere. Meaning that the app sent the video feed out on the net. Encrypted or not, I didn’t feel comfortable with that.

The conclusion: This wasn’t going to fly.

So what could I do to resolve this issue? Well, I could buy the real deal, a quick google told me that it was going to be expensive. To add to the sour taste in my mouth the sites that offered these solutions didn’t have any information about whether or not this was contained to the local network or if the devices needed internet access. Call me crazy, but I don’t like not knowing and I don’t trust IoT that much.

I remembered I had a couple of RaspberryPi’s laying around, as well as a CameraModule that I hadn’t used in years. So I started digging in my drawers to see if I could find all the things I needed. Said and done! I had a Pi, a case, AC-adapter, and a camera.

What now?

I started by creating a fresh install of Rasbian, or RaspberryOs as it’s called now. You can also install it using the command-line

sudo apt install rpi-imager

While installing RaspberryOs I connected the camera module. When done I started booting up the Pi. Some standard config such as WiFi, key-board layout, local and SSH.

Time to test it out!

ssh pi@pihost
cd Desktop
raspstill -0 first.jpg

A jpg file was created. Since I’m in a shell it’s hard to view the file. But with some magic, I moved it to the desktop of my daily driver.

scp pi@pihost:~/Desktop/first.jpg ~/Desktop/first.jpg

Marvellous! The image was decent, nothing fancy, just a picture of some stray cables that happened to be in front of the camera. But the image was clear.

Now I needed something that could take the images and make them accessible from another computer on the network.

Some googling around gave me several answers, I ended up with Motion. SSH into the

sudo apt install motion

Some tinkering later I had updated the config in /etc/motion/motion.conf to my desires

stream_localhost off   # accessible from other sorces than localhost
stream_port 8000 # port to access the feed
daemon on # run as daemon

Open the browser and navigate to http://pihost:8000 and voila! A stream! Very crude, but still a stream.

I updated the config with the following

framerate 10        # max number of frames captured / sec
stream_maxrate 10 # max framerate for stream
width 640 # number of pixels in width
height 480 # number of pixels in height

Nice, now its actually decent! You could play around with these settings to make them fit your needs. For me, this was good enough, for now.

Next, we want the Pi to start motion automatically and start recording and sending the feed once it’s booted up. Makes things easier on our part. Just move it to wherever you want it, plug it in and aim the camera. wait a little bit and you can see the stream.

sudo nano /etc/motion/motion

Simply change start_motion_daemon=no to yes, write(save) the changes with control + o and exit with control + w.

Now let’s enable the service

sudo systemctl enable motion

And reboot the Pi

reboot -h now   # will rebote the system without delay

Spam refresh in the browser. Got an image? Nice!

I ran into trouble with privileges, I wasn’t allowed to write to the default log file. So you can either change those, change the ownership of the directory or just remove logging altogether. I opted for the latter.

; logfile /var/log/motion/motion.log # add ; to ignore the setting

Next on the list for me is to swap the camera module for noIR camera module. This module doesn’t have an IR filter, so the images will look terrible. However, they will hopefully be able to display a visible image, and in the worst-case scenario, I’ll have to invest in some IR LEDs.

--

--