📜 ⬆️ ⬇️

Video surveillance of a remote object on Debian + AVReg + gsm

Maybe someone will use my solution for offline monitoring of the object.

I got a plot of land for building a house and had the idea to organize remote monitoring of it to identify outsiders (or who rummaged without me). With the observation itself and the recording of problems, there was no problem, the problem was how to transfer the data home without having a dedicated channel (and indeed no channel at all).

Task:
1. To fix the movement in the frame and record;
2. Expand into folders;
3. Transfer home for viewing.

There were a couple of cameras with video output, an old computer, a video capture card, a gsm-modem 1550 usb, a wish.
')
With the software was determined quickly enough. This is a Debian and AVReg system for fixing. Why such a bunch? It's simple, Windows is not suitable for budget video surveillance, not even in terms of tuning, but in terms of the hardware requirements, it requires an order of magnitude higher power. I liked Debian with brevity, the ability to install a system without a desktop out of the box, besides Debian, I think, is more server-based after freebsd. I chose AVReg because its installation and setup is normally described, and there are 4 free licenses (just for the garden), I would have to deal with others specifically, and I'm not such a linux specialist.

A little about setting up AVReg. By default, it is configured to create photos. Motion detector forced to take a photo every 30 minutes, because sometimes the movement may not be half a day.

Dealt with a software, almost.

Iron is: Celeron 2.26GHz with a motherboard, 1Gb of RAM, 40Gb hard drive, video capture card on a Bt878 chip:

image

Huawei E1550 USB Modem:



Cameras are so unpretentious.



As you can see, on Windows with such a configuration no decent video surveillance will fly.

There were no problems with the installation of Debian and AVReg, all the description is on the Internet on home sites.

Now there was a task to transfer the accumulated information to home. Online channel 24x7 via GSM is unreal (not in our city), it turns out that the server itself should call and merge the data. From here poured such a script, it is registered in / etc / crontab for execution every hour.
script

#! / bin / sh
echo = on
PATH = / bin: / usr / bin: / sbin: / usr / sbin

sudo /etc/init.d/wvdial start
sleep 15s

kat = `date '+% m.% d.% y.% H.% M'`
cd / home
mkdir $ kat

cd / var / spool / avreg /
cp --parents $ (find -name * .jpg -mtime -1) / home / $ kat /

cd / home / $ kat /
sensors> sensors.txt
smartctl --all / dev / sda> smart.txt
apcaccess status> ups.txt

cd / home /
tar -cvzf $ kat.tar.gz / home / $ kat
rm -R / home / $ kat

ls -l / home

ftp -n -d "server address" << INPUT_END
quote USER "username"
quote PASS "password"
passive
cd pub
prompt
binary
mput * .tar.gz
INPUT_END
echo "*** PROGRAM COMPLETED"

rm -f /home/*.tar.gz
sleep 5s

/etc/init.d/wvdial stop


Wvdial setup

The problem of usb gprs modems on linux, zte mf-180 and Huawei 1550.
The problem is in linux, switching to modem mode does not work correctly, or rather, by default it does not work at all.
Solution: in any windows we plug the modem into the port, copy the software somewhere, install the software, then the modem will switch from card reader mode to modem mode.
Open the hyperterminal and select the COM port that the modem has visited.
Give commands
AT + ZCDRUN = Ern
Or
AT + ZCDRUN = 8
In response, he writes ... ... ... result (0: fail 1: success): 1 ie we have 1 team accepted
I gave both commands (just in case) the modem stopped being detected as a card reader when turned on and became immediately identified as a modem on COM ports.

Copy wvdial.conf to / etc / and wvdial to /etc/init.d/
start /etc/init.d/wvdial start
uncomment the noauth parameter in the ppp / etc / ppp / options settings

wvdial.conf settings for megaphone
[Dialer Defaults]
Init1 = ATZ
Stupid Mode = on
Init3 = AT + CGDCONT = 1, "IP", "internet"
Password = gdata

Phone = * 99 *** 1 #

New PPPD = yes
Abort on Busy = off
Modem Type = Analog Modem
Baud = 115200

Modem = / dev / ttyUSB0
ISDN = 0
Username = gdata
Init2 = ATQ0 V1 E1 S0 = 0 & C1 & D2 + FCLASS = 0
Auto Reconnect = on


Settings wvdial were taken on the Internet (such as used for satellite Internet).

wvdial settings
#! / bin / bash
echo = on
case "$ 1" in
start)
killall wvdial
killall pppd

/ usr / bin / wvdial

;;
stop)

killall wvdial # Not the best solution, there is where to think out
killall pppd
;;
esac

exit 0




What the main script does:
- starts wvdial waits 15 seconds. For normal communication;
- forms a date-time variable and creates a directory with their name in / home;
- copies with selection by mask * .jpg;
- sensors are also created-copied from the motherboard, smart disk and UPS status;
- all this mess is packed in the archive and deleted the directory;
- then the archive is transferred via FTP to a remote resource;
- the archive is deleted and the communication session is closed.

Why I did just that. At the very beginning, I realized that for me there is no analogue to FTP, but I need to transfer a bunch of files. I tried curlftpfs (this library connects the FTP resource as a directory in the system), but a big problem came out, a couple of files were copied and all that stuff hung. After dancing, I decided to pack it in the archive and transfer it, I first transmitted it every 5 hours, but when 3 cameras were added, the archive size exceeded the session limit, ftp had to be transmitted more often.

With FTP, too, there was a problem, I couldn’t find a free FTP server with a raid (I liked http://net2ftp.ru/, but it didn’t work for me with it), I had to raise my FTP server at home.

On the home server, a bunch of small archives immediately formed, which should have been parsed, wrote a script, which neatly unpacks everything into the same directory.

unpacking script
#! / bin / sh
echo = on
PATH = / bin: / usr / bin: / sbin: / usr / sbin

ls * .tar.gz | while read i; do tar xzvf $ i home / $ {i %%. tar.gz} /smart.txt home / $ {i %%. tar.gz} /sensors.txt home / $ {i %%. tar.gz} / up $
#ls * .tar.gz | while read i; do tar xzvf $ i home / $ {i %%. tar.gz} /sensors.txt; done
#ls * .tar.gz | while read i; do tar xzvf $ i home / $ {i %%. tar.gz} /ups.txt; done
#ls * .tar.gz | while read i; do tar xzvf $ i home / $ {i %%. tar.gz} / syslog; done

#ls * .tar.gz | while read i; do tar xzvf $ i --strip-components = 2 home / $ {i %%. tar.gz} / 2014-04; done
#ls * .tar.gz | while read i; do tar xzvf $ i --strip-components = 2 home / $ {i %%. tar.gz} / 2014-05; done
#ls * .tar.gz | while read i; do tar xzvf $ i --strip-components = 2 home / $ {i %%. tar.gz} / 2014-06; done
#ls * .tar.gz | while read i; do tar xzvf $ i --strip-components = 2 home / $ {i %%. tar.gz} / 2014-07; done
#ls * .tar.gz | while read i; do tar xzvf $ i --strip-components = 2 home / $ {i %%. tar.gz} / 2014-08; done
#ls * .tar.gz | while read i; do tar xzvf $ i --strip-components = 2 home / $ {i %%. tar.gz} / 2014-09; done
ls * .tar.gz | while read i; do tar xzvf $ i --strip-components = 2 home / $ {i %%. tar.gz} / 2014-10; done


Results: the scheme has been operating for 2 years, there are no fundamental failures (except for problems with iron, energy). I am satisfied and I get these shots.

There are plans to add Arduino as a meteorological station and, of course, build a smart home (with sensors, automatic, autonomous, for the soul and a comfortable life).



Source: https://habr.com/ru/post/362621/


All Articles