Nonprofessional video surveillance of the apartment is entertaining and inexpensive.

From the moment I got a GSM alarm system in my apartment on guard, I thought that it would be nice to have an “eye” in my absence in the apartment if the alarm sensors were triggered (could it be a false alarm?). As I am an engineer in the field of information technology, I didn’t speak about any professional decision in the form of a registrar and a heap of cameras - only myself, with my own hands. It was also decided to immediately limit the budget to zero , and if the project is successful, we should think about its further improvement and modernization.


First of all we select iron. "Eyes" means the camera, here you can not go anywhere. Then the question arises of what to do with the resulting image - to store it, transfer it somewhere, etc. So I thought about a router connected via UPS with a 4G modem for a stable channel with the Internet which is hard to “put on” to a potential robber.

At work, we have been using ZyXel Keenetic USB routers for several years now (specifically my already outdated Giga2 model). After the developers of the firmware "screwed" such a thing as OPKG (package manager) - it became possible to turn your router into a personal computer with linux with the most extensive possibilities, which I decided to use for my purpose. So, having a computer router at home with a 4G modem connected, I lacked only an “eye” - a USB camera. He remembered that three or four years ago he bought a logitech C270 web camera for parents to communicate with relatives via skype on a computer and what they now communicate through a tablet — they requisitioned the camera. By the way, the camera on the front panel has a LED,

Pairing and adjusting the iron

So, there is iron. And that can not but rejoice - while we are within the budget.
There are two USB ports on my router, one of which was already occupied by a 4G USB modem. We will use the second one by inserting the logitech C270 camera there. In order for the router to work with the camera, you must first install the OPKG component on the router (in this component, we tick all the checkboxes except “Kernel modules for USB support for DVB tuners”). But there is a catch - OPKG in the router needs disk space (enough gigabytes for the eyes), but where can I get it, because both USB ports on the router are already taken? There were two possible solutions - either a USB hub with a USB flash drive (the first thing that immediately comes to mind), or the fact that you can put a microSD card into my 4G USB modem. And the old slow 8GB microSD card found at home went straight to the modem. File system left on an NTFS card (although EXT2 or EXT3 is strongly recommended).

Then we go to the admin panel of the router, the OPKG tab, select our memory card, in the line “initrc script” we write


and click Apply .
After installing OPKG, the SSH client (I use the Putty program on my laptop with windows), we cling to the router and execute the following commands to update the OPKG:

opkg update
opkg upgrade

By default, the root password is keenetic (or zyxel depending on the firmware version) on SSH . Password is strongly recommended to change the command passwd .


Next, install the program motion.

opkg install motion

It will work with our camera, analyze the change of the picture and instruct the router where to send the resulting image. The file of the motion program settings is \ etc \ motion \ motion.conf, editing it and changing the settings we need. First of all, I set the maximum resolution supported by the camera to 1280x720, turned the image 180 degrees (it was more convenient for me to set the camera upside down), recording 2 frames per second.

width 1280
height 720
framerate 2

I didn’t see the need to record the entire video stream and broadcast it to the Internet, so I set up motion to record the video and transmit it only if the image was changed. In the process of setting up the motion, it became clear that it does not support the MJPEG mode with my camera, but only supports the YUYV mode - as a result, the result of the motion will not be a video series, but a sequence of JPEG photos.


I also set up motion so that a copy of the photos is copied to an external FTP server.

on_picture_save wput ftp://login:pass@XX.29.136.XX %f

In the event that a router with a memory card is taken out of the apartment, it will still be possible to see exactly how it happened.

It is strongly recommended to change the login password to connect to your camera.

stream_authentication login:pass

After all the settings, we look at the result in the browser at:


Attention! If you have not seen any image in the browser, you should pay attention to your version of the Keenetic firmware. Presumably, starting with firmware version 2.11.A.4.0-1, video modules are not loaded by default, so you need to load them into SSH by handles or add them to the launch script:

/opt/sbin/insmod /lib/modules/3.4.113/i2c-core.ko
/opt/sbin/insmod /lib/modules/3.4.113/i2c-dev.ko
/opt/sbin/insmod /lib/modules/3.4.113/videodev.ko
/opt/sbin/insmod /lib/modules/3.4.113/videobuf2-core.ko
/opt/sbin/insmod /lib/modules/3.4.113/videobuf2-memops.ko
/opt/sbin/insmod /lib/modules/3.4.113/videobuf2-vmalloc.ko
/opt/sbin/insmod /lib/modules/3.4.113/v4l2-common.ko
/opt/sbin/insmod /lib/modules/3.4.113/uvcvideo.ko 

If the image did not appear after that, first look at the Keenetic logs, what happens when the camera is connected. Is the camera defined as a video device, etc.?


Having done all this work, the thought came that it was necessary to somehow manage it, i.e. turn on and off at the right time (and mostly remotely). I decided to install the SSH client on my android smartphone. After choosing SSH clients I stopped at ScriptKitty. By pressing two or three keys on the smartphone, you can quickly enable or disable motion.

Running motion via ssh:

/opt/etc/init.d/K99motion restart

Finishing motion via SSH:

/opt/etc/init.d/K99motion stop

But there was another trick waiting for me - a “gray” ip address on my 4G modem. Connecting to the router via Wi-fi without any problems you can turn off or turn on motion. But what to do if you are outside the Wi-fi of your router, and your router has a gray ip? I found salvation in the form of a VPN. The scheme is as follows - with my home router I cling to a router at work with a static IP through a PPTP client (at work a PPTP server is installed on the router). Now, having made an SSH port forwarding from a working router to a home one, I can finally control my camera by remotely accessing my smartphone at the static address of the router at work.

I also tried to automate management using the Tasker automator (it has its own separate SSH client) - monitor the smartphone’s connection to the Wi-Fi router and, depending on this, turn on or off the motion. The logic here is this: the smartphone is connected to the Wi-Fi router - that means I am at home - turn off the camera. The smartphone is not connected to the Wi-Fi router - it means I am not at home - turn on the camera. But after experimenting, I refused this option - too many false positives. For example, I'm at home, the smartphone fell asleep, the router lost the smartphone, the camera turned on - well, etc. Currently I use only manual method.


In principle, what I wanted from the project, I got it. I can “see” the apartment when I want, and in the event of some GSM alarm triggering, I have already decided what to do next. In the process of implementation, I solved a lot of problems, but their solution caused a certain buzz from the acquired knowledge and implementation of the plan.

Also popular now: