They turned to me for help. The task was: to connect and configure a video surveillance kit in the country. Experience in this area was minimal, I dabbled at home with USB cameras. And at work there was already a configured system with a separate server. The presentation was how video surveillance is arranged, since there is experience in the IT field.
For the article, I tried to find the original photo devices. Some are of poor quality. The rest will be taken from the Internet.
Installation of video surveillance began in 2019. Changes were made until the end of 2021. The interesting thing started when the customer wanted to check the cameras from home.
Part 1 – installation, connection, configuration
Let’s start by introducing the “culprit” of a little adventure.
The set is similar. The kit includes:
HDD DVR with built-in POE
4 outdoor IP cameras with IR illumination
4 wires of 10m (perhaps the customer purchased separately)
There were no restrictions on installation time. It was desirable to be in time before the repair work inside the house began at the dacha. We completed this task in a couple of days.
We chose the optimal points for the cameras and began to attach them to the cladding of the house. The outer part of the house was made of tiles (To be honest, I don’t understand building materials). They drilled it carefully, otherwise there was only one piece of such a coating in stock. The base of the house was made of wood. Through it and the insulation it was easy to make holes and get inside.
After installation of each camera, it was checked for operability. So that you can re-crimp the wire before the completion of the installation work. As a result, everything was connected to the DVR without problems. It remains only to configure it.
The translation of the firmware from the DVR was in clumsy Russian. Sometimes the meaning of a paragraph did not coincide with its title. On YouTube, we found settings with similar firmware, in some cases we were guided by the icons in the menu. Well, nobody canceled dancing with a tambourine.
The tuning was to optimize the use of hard disk space. So that there is no extra video, and important points are not erased. The DVR supports motion detection. It is configured by selecting squares on the video, by which it determines the changes in the picture. The only negative is that there is no video pre-buffering. After detection starts recording with a delay.
In general, it turned out great. Everything works as it should. No harm done. I gained experience in installing video surveillance, and the customer spying on his summer cottage. They noted the matter and dispersed.
Part 2 – everything is fine, but I want better
Well, who doesn’t want better. Once again they turn to me. Everything works great, but I want to be at home in the city, lying on the couch to watch what’s going on in the country.
Poraskidav thoughts, once again studying the DVR. It has an Ethernet connection. So let’s connect to the internet. The next question is how to watch cameras remotely via the web interface? Internet connection can be configured only through a router with 3G/4G modem support. But behind a gray IP address you will not get to the DVR. Found two ways.
Method 1. I had a Raspberry Pi 2 without need. You can install it and set up a connection via Hamachi.
Method 2. The one we used. It turned out that the DVR has its own cloud storage on xmeye. There is also an app for android.
Without thinking for a long time, we began to search for a router and a USB modem. We chose a router, I don’t remember what brand, but it doesn’t matter, we handed it back to the store. And the USB modem was chosen easier, by cellular communication it catches better in the country. It turned out to be a megaphone.
We started to connect the whole thing in a bundle: a video recorder – a router – a USB modem. The saddest thing began, no matter how I tried to set up a connection on the router, it did not connect to the Internet.
I thought that I would have to abandon this idea with the Internet. Or maybe it’s in the firmware? It remains to take a chance and look for the latest firmware on the router. And indeed found. But even after the update, the Internet did not want to work.
The USB modem was indeed one of the latest models. And most likely they have not yet managed to release the firmware with support for the new device. Sadly, I decided not to give up and offered to try another router, although it was not smart.
We handed over that router and I picked up another one. Which you see below.
Once again, it was not possible to connect out of the box. We are looking for firmware. We are sewing. And finally we manage to reach the goal! A stone fell from my soul. It works!
Connected to the Internet. A user account has been added to the DVR. It’s time to set up the app on android XMEye
Connecting was easy. In the DVR where information about the system, there are two QR codes. One with a serial number, the other for installing the application. After adding the device to the application by serial number, it requested a login / password. After logging in under the user account, we saw the cameras.
The application is easy to use. There is a view of the cameras online. You can watch old posts. You can download the recording to your phone or take a picture. As well as some DVR settings that are available from the admin account. But they were not interesting, because. everything was already set up as it should.
Well, as without cons. The tariff that I arranged was with limited internet. It happened that someone used traffic via Wi-Fi and the cameras were not available until the end of the month.
Here the meeting is over. Everyone is happy. I realized that I need to carefully select a router or USB modem for compatibility. In extreme cases, you can always return the product. The customer is satisfied. They noted the matter and dispersed.
Part 3 – time later
It won’t be a big intermediate part. Problems with video surveillance are not over. The router hung from time to time and only reboot saved. But the customer does not always go to the dacha to reboot the router.
They changed the operator from a megaphone to mts. There is unlimited Internet, it turned out to catch too well. There was one caveat, the Internet was not immediately connected. As it turned out, the USB modem had its own local IP address, which conflicted with the router. I had to change the subnet on the router, and with it, reconfigure the DVR.
After resetting the network settings of the cameras, all motion detection settings remained. And that was the most important thing. Less time spent on setup. Although all the settings were taken on the phone in advance. We looked in the menu for how to reconfigure the camera connection. It’s been a year since at least everything was forgotten. It turned out that there is no separate item in the menu, the setting is only through the installation wizard.
It remains to deal with the freezing of the router. After fixing this problem, I experienced euphoria. Feels like an abandoned quest went. And more on that in the next part.
Part 4 – raspberry
I was attacked by constant complaints of freezing. And can something be done about it. It mainly happened in winter and the customer thought maybe he needed another router, which has a larger operating temperature range. To be honest, I did not find one, or badly looked for it. And in general I thought that the matter was in the router itself. Periodically, you need to reboot it, especially if it works with a USB modem.
The idea was this. Install my Raspberry Pi 2 in the country, which until now was unnecessarily (played enough). And configure it to reboot the router via telnet. At the same time, you can connect to my home server via VPN. The idea is great. Both liked it. Only from all that was proposed, I did not know how to set up a reboot of the router.
Thanks to google I found the solution. Expect. For me it was a revelation.
Expect supports a regular expression engine and basic programming features that allow simple scripts to efficiently manage programs such as telnet, ftp, and ssh that do not have a built-in scripting language, macros, or other programming mechanisms.
Arranged a meeting to go to install and configure. It was the beginning of December, it was cold. It was necessary to do some of the settings at home. Nobody heated the dacha, so it will be cold to set up.
By this time, the old building had collapsed. And I made an improvised one from a non-working switch. This Frankenstein looks like this now
I chose Raspbian Stretch as the OS. I downloaded it from the archive.
I set up the system via SSH, because at hand there was nothing with an HDMI input. To enable SSH on Raspberry, you need to create an empty file in the root of the flash drive with the name “ssh”. After the first setup, it remains to stuff with scripts. I’ll retreat right away, it was not possible to connect to the home server via PPTP, most likely this protocol is not friendly with gray IP addresses. So we set up Hamachi.
The first “ping.sh” script contained an internet connection check and then a VPN connection check. It looks like this:
#!/bin/bash # Есть интернет? if ! /bin/ping -c 1 220.127.116.11 then # Нету. Перезагружаем роутер /home/pi/router.sh fi # Есть интернет? if /bin/ping -c 1 18.104.22.168 then # Есть. А есть VPN подключение? (IP моего сервера в хамачи изменен) if ! /bin/ping -c 1 22.214.171.124 then # Нету. Перезапускаем хамачи /etc/init.d/logmein-hamachi restart fi fi
I copied the download script from the wiki to set it up in place.
We arrived at the cottage. Added raspberries. Connected laptop. Enable telnet in router settings. Let’s try to connect. And voila, there is a login prompt.
There is a contact. Next, I set up the script’s reactions to regular expressions. By imagining how the script will interact with the router. And on the example of how I connect manually, I set it up. I’m launching. Doesn’t connect and throws an error. There was no need to go far. As it turned out, the installed telnet client on the raspberry was missing.
I install the client. I’m running the script. Silence, the script exits without error. We are waiting for the router to reboot. Hooray! Working!
The router reboot script “router.sh” turned out like this for D-Link DIR-620S:
#!/usr/bin/expect -f # Открываем telnet сессию на удалённом сервере, и ждем запроса имени пользователя. spawn telnet 192.168.2.1 expect "dlinkrouter login:" # Посылаем имя пользователя и ждем запроса пароля. send "adminr" expect "Password:" # Посылаем пароль и ждем приглашения ввода командного интерпретатора. send "passwordr" expect "$" # Посылаем команду, и ждем следующего приглашения ввода командного интерпретатора. send "rebootr" expect eof
Sending an exit command is not necessary, because on reboot, the connection is dropped. And finally, setting up the cron:
SHELL=/bin/bash #Перезагрузка каждый день в 6 утра 0 6 * * * /sbin/reboot #Проверка интернета при старте системы @reboot /home/pi/ping.sh #Проверка интернета каждый час 0 * * * * /home/pi/ping.sh
Having tested the scripts a few more times, we were convinced that the solution to the problem worked. And you think that’s all? For now, yes. Until now, access to the cameras has never been lost.
Hamachi is pretty easy to set up via dpkg. The batch file can be downloaded here: https://www.vpn.net/linux called logmein-hamachi_*.*.*.***-*_armhf.deb
Connecting to Hamachi servers:
sudo hamachi login
Adding to a group (previously configured in your account):
sudo hamachi do-join ***-***-***
Add to autoload:
sudo update-rc.d logmein-hamachi defaults
The client was my friend. After we set up the system for the first time, I did not expect that we would touch it more than once. Two years have passed, but it feels like yesterday. He has an idea to increase the number of cameras to cover a larger area. As a request for help arrives, I will continue this story (not within the framework of the article).
The main thing is not to forget to relax in the country. Thank you for your attention.
UPD: Fight against low temperature.
The router and raspberry were placed in a box. With the expectation that the heat generated by the devices will be enough in a confined space. And just in case, they put a couple of bags with moisture-absorbing balls, took them from work from the box of a new printer.
You can check the temperature of the raspberry processor with the command:
The temperature of the processor in the cold reached 17 ‘C
Now let’s say it’s -6 ‘C outside, and the temperature of the raspberries is 25’C
All this taking into account that the raspberry works without load.