When it comes to monitoring and surveillance, a wide variety of systems with different levels of features and sophistication are available commercially as products or services.
In such a wide market, one might find himself needing a monitoring solution integrated in his own custom product. Also, it may be just funny to build your own surveillance system, improving it over time.
GoalsThe proposal here is to build a surveillance system that has the following features:
- Industrial-grade core: the choice of the Toradex Iris Carrier Board + Colibri i.MX6DL computer on module ensures an all-environment hardware. This means less work and headache if you plan on turning this solution into a product in the near future.
- Motion detection: it uses the HC-SR04 ultrassonic distance sensor to detect something or someone. You could have it in your 5-year-old bedroom door, for instance.
- Communication: by using a VOIP SIP user-agent and a speaker system, you are allowed to communicate to the possible perpetrator, scaring him to death or just cursing as they steal some roses from your preciously cultivated garden.
- IP-Cam snapshot: takes a snapshot from one or multiple IP-Cameras. Never thought you would use that old smartphone anymore, did you? Now you can use it as a low-cost IP-Camera and, in the process, help saving the world by reducing electronic waste.
- Telegram bot interaction: all of the trigger detection and snapshots are sent to your smartphone, without the need to code an app specifically for this purpose. Also, the possibilities of functionality expansion are endless.
Attach the Colibri i.MX6 computer on module to the Iris Carrier Board:
You can notice in the picture above that there is an USB dongle plugged-in. This is an optional WiFi-USB dongle, if you don't want your system connected to an Ethernet wired connection. To the left of the USB port, there is the audio output, where any speakers may be connected.
The HC-SR04 is connected directly to the X16 connector (pin header) of the Iris Carrier Board: VCC - pin 12; GND - pin 36; echo - pin 16; trigger - pin 17. The pictures below illustrate the connection:
This section will describe how to implement the project.
Embedded system setup
As a first step, you must flash the latest pre-build Linux image provided by Toradex for the Colibri i.MX6 modules.
Then, it is needed to compile and deploy a kernel module for the ultrasonic sensor HC-SR04. The instructions on how to fetch the source-code and compile the kernel and its modules for the i.MX6 are provided here. Then you can find the driver for the HC-SR04 in this GitHub repository. You may change the HCSR04_ECHO value to 166, in the hcsr04.c, line 21, before compiling the module.
The PJSUA2 implementation of a VOIP SIP user-agent will be used later in this project - it will be provided ready to install. If you want to know how it was built, the steps are described in this CNX-embedded article.
Telegram Bot
You must also create a Telegram Bot, following instructions from here. Please take note of the token generated during the process.
Application deployment and setup
The application source-code can be found in the following Bitbucket repository. In the repository is also present the PJSUA2 implementation installer, in a compressed file named pjsip-pjsua-install.tar.bz2 - just extract it in the embedded system and run the install script.
Regarding the application, you must first install Node.js according to the instructions provided here. Please install the 6.x.x version - in order to do so, do not use the opkg
approach described in the article, instead fetch Node from its release repository.
Then install the following modules:
npm install debug request node-telegram-bot-api
npm install -g forever
You also need to edit the Node.js application, main_app.js
, so it fits your environment. First of all, edit the var token
to hold the token generated when you creted your Telegram Bot. Then, edit the var filename_web
inside the take_snapshot
function with the photo URL of your IP-camera.
In order to start the application, an init script example is provided:
#!/bin/sh
sleep 2
insmod /home/root/hcsr04.ko # ultrassonic module
echo "Don't forget to configure the internet settings, such as nameserver and wifi connection!"
sleep 1
echo "Starting monitoring application in 3..."
sleep 1
echo "2..."
sleep 1
echo "1..."
sleep 1
echo "Start!"
forever start main_app.js -l /home/root/demoVoipMonitoring/forever.log -o /home/root/demoVoipMonitoring/nodelog.log -e /home/root/demoVoipMonitoring/nodeerr.log
pjsua-cmdline-ref --config-file=/home/root/demoVoipMonitoring/.pjsua-conf
- Load the ultrasonic sensor module: change the path to the location of the .ko binary.
- Change the path of the Forever log files if you want.
- Edit the
pjsua
configuration file: it is initially configured to answer automatically to incoming calls and hang-up after 60 seconds, if the call is still active.
To start the application:
./init.sh
Below you can see a video presenting the working system. Hope this was helpful and I am looking forward to see you next project!
Comments
Please log in or sign up to comment.