OpenWRT + Motion + Mjpg_streamer = Sistem CCTV Sederhana


IMG_20130131_101902 - Copy

so, bagi anda yang mengikuti blog ini mungkin sudah tahu klo akhir2 ini saya sering post tentang tugas akhir saya #ceileh. Dan Alhamd, Sekarang sudah selesai hehe

Dan melanjutkan postingan-postingan blog kemarin, untuk postingan ini akan saya coba jelaskan untuk tutorialnya secara lengkap. Kalau dilihat dari gambar diatas, yap ada beberapa hardware tambahan pada sistem cctv ini. Antara lain USB Modem, USB Flashdrive, USB Soundcard, Webcam dan Speaker.

Konfigurasi Awal
1. Install OpenWRT pada TPlink MR-3420 -> tutorial banyak, contohnya disini
2. Exroot – Digunakan untuk menambah space memory pada router -> Tutorial
3. USB Soundcard – Digunakan untuk sumber keluaran bunyi alarm -> Tutorial
4. Instalasi webcam dan motion ->Tutorial . Untuk instalasi mjpg_streamer googling sendiri yak hehe
5. Instalasi PHP -> Tutorial
6. Instalasi MySQL – Sebisa mungkin password menggunakan kata ‘dewi’ agar tidak perlu setting lebih lanjut hehe -> Tutorial
7. Instalasi Samba Server -> Tutorial
8. Instalasi Lighttpd (Optional) -> Tutorial
9. Instalasi mail Server -> Tutorial

Konfigurasi Lanjut
1. Konfigurasi Database Mysql
– Masuk ke mysql admin

     mysql -u root -p
     

– buat database baru dengan nama injen

     create database injen;
     use injen;
     

– buat tabel user, level dan log


 CREATE TABLE IF NOT EXISTS `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(10) NOT NULL,
  `passwd` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data untuk tabel `user`
--

INSERT INTO `user` (`id`, `username`, `passwd`) VALUES
(1, 'admin', '21232f297a57a5a743894a0e4a801fc3');

CREATE TABLE IF NOT EXISTS `level` (
  `id` int(1) NOT NULL,
  `level` int(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `level`
--

INSERT INTO `level` (`id`, `level`) VALUES
(1, 0);

CREATE TABLE IF NOT EXISTS `log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` datetime NOT NULL,
  `rincian` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

     

2. Download file source code i-njen cctv disini, kemudian extract ke folder /www/ . Setelah itu coba akses via browser pada link http://ip-router/injen . Kalau muncul tampilan atur tanggal berarti sudah lancar

atur tanggal

atur tanggal

3. Untuk login ke system, menggunakan username dan password = admin | admin. Pengaturan password dapat dirubah melalui menu setting pada system. Halaman home berisi status perangkat router dan status perangkat yang terhubung ke router.

status perangkat

status perangkat

untuk pengaturan perangkat terhubung, edit file cekstatus.sh yang terletak di /www/injen/script/ .

cek status

cek status

Sesuaikan id tersebut dengan id perangkat anda. Untuk mengetahui id perangkat dengan mengetikkan lsusb pada terminal/putty

cek id

cek id

4. Setting port modem untuk pengiriman SMS. Edit file trigger3.sh yang terletak di /www/injen/script. Sesuaikan port modem tersebut

sms

sms

5. Atur konfigurasi samba server, edit file smb.conf yang terletak di /etc/samba/

config samba
	option 'name'			'OpenWrt'
	option 'workgroup'		'WORKGROUP'
	option 'description'		'OpenWrt'
	option 'homes'			'1'

config sambashare
	option 'read_only'	'no'
	option 'create_mask' 	'0700'
	option 'dir_mask'	'0700'
	option 'name'		'samba'
	option 'path' '/www/injen/logcam'
	option 'guest_ok' 'yes'

6. Mengaktifkan fitur log email harian menggunakan cronjob
matikan dulu cronjobnya

    /etc/init.d/cron stop
    crontab -e
    

isi dengan
01 00 * * * /www/injen/script/kirimemail.sh
syntax diatas akan melakukan pengiriman setiap pukul 00.01 setiap harinya
jalankan lagi cronnya

   /etc/init.d/cron start
   

NAH!! i-njen CCTV sudah bisa diicip2 hehe
untuk dokumentasi lengkapnya bisa mengunduh skripsi saya disini

thanks to : agustian romi ariansyah, cindy wijaya, tisaros kaskus, xopal unil, forum id-openwrt, group openwrt facebook

fungsi PHP Mail di openwrt


#opkg install msmtp

edit file /etc/msmtprc

//contoh pengaturan untuk akun gmail

account default

host smtp.gmail.com
port 587
auth on
user username@gmail.com
password password_email

auto_from off
from usernamae@gmail.com

tls on
tls_starttls on
tls_certcheck off

logfile
syslog LOG_MAIL

edit file /etc/php.ini

tambahkan baris berikut pada akhir text

sendmail_path = /usr/sbin/sendmail -t

restart webserver
uhttpd
/etc/init.d/uhttpd restart

lighttpd
/etc/init.d/httpd restart

tes dengan membuat file

Agar bisa menjalankan file php di cli maka perlu install php-cli
# opkg install php-cli

cara menjalankan
# php-cli mail.php

FFMPEG Cheatsheet


This will create a video slideshow (using video codec libx264) from series of png images, named named img001.png, img002.png, img003.png, …

(each image will have a duration of 5 seconds)

ffmpeg -f image2 -r 1/5 -i img%03d.png -vcodec libx264 out.mp4

This will create a slideshow in which each image has a duration of 15 seconds:

ffmpeg -f image2 -r 1/15 -i img%03d.png -vcodec libx264 out.mp4

If you want to create a video out of just one image, this will do (output video duration is set to 30 seconds):

ffmpeg -loop 1 -f image2 -i img.png -vcodec libx264 -t 30 out.mp4

If you don’t have images numbered and ordered in series (img001.jpg, img002.jpg, img003.jpg) but rather random bunch of images, you might try this:

cat *.jpg | ffmpeg -f image2pipe -r 1 -vcodec mjpeg -i – -vcodec libx264 out.mp4

or for png images:

cat *.png | ffmpeg -f image2pipe -r 1 -vcodec png -i – -vcodec libx264 out.mp4

That will read all the jpg/png images in the current directory and write them, one by one, using the pipe, to the ffmpeg’s input, which will produce the video out of it.

Important: All images in a series need to be of the same size and format.

Explanation: By telling FFmpeg to set the input file’s FPS option (frames per second) to some very low value, we made FFmpeg duplicate frames at the output and thus we achieved to display each image for some time on screen 🙂

Install Lighttpd di OpenWRT


lanjuuutttt..

opkg install lighttpd
opkg install lighttpd-mod-cgi
opkg install lighttpd-mod-fastcgi
opkg install lighttpd-mod-simple-vhost

kemudian hilangkan tanda # pada
server.modules = (
# "mod_rewrite",
# "mod_redirect",
# "mod_alias",
# "mod_auth",
# "mod_status",
# "mod_setenv",
"mod_fastcgi",
# "mod_proxy",
"mod_simple_vhost",
"mod_cgi",
# "mod_ssi",
# "mod_usertrack",
# "mod_expire",
# "mod_webdav"
)

tambahkan index.php pada index-file.names
index-file.names = ( "index.php", "index.html", "default.html", "index.htm", "default.htm" )

rubah port default lighttpd
## bind to port (default: 80)
server.port = 80

rubah baris pada fastcgi
#### fastcgi module
## read fastcgi.txt for more info
fastcgi.server = (
".php" => (
"localhost" => (
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/bin/php-fcgi"
)
)
)

Agar tidak bentrok dengan uhttpd. Maka tambahkan baris berikut agar luci bisa jalan pada lighttpd
cgi.assign = ( "luci" => "/usr/bin/lua" )

jalankan lighttpd 😀
# /etc/init.d/uhttpd stop
# /etc/init.d/uhttpd disable
# /etc/init.d/lighttpd start
# /etc/init.d/lighttpd enable

Install Samba Server di Openwrt


paket yang dibutuhkan
– luci-app-samba
– samba36-server
– ntfs-3g

1. pertama edit “/etc/config/firewall”
# vi /etc/config/firewall

————————————————-
config rule
option src lan
option proto udp
option dest_port 137-138
option target ACCEPT
config rule
option src lan
option proto tcp
option dest_port 139
option target ACCEPT
config rule
option src lan
option proto tcp
option dest_port 445
option target ACCEPT
————————————————–

2. rubah file “smb.conf.template” di folder “/etc/config/samba” menjadi “smb.conf” kemudian isi
[global]
netbios name = |NAME|
workgroup = |WORKGROUP|
server string = |DESCRIPTION|
syslog = 10
encrypt passwords = true
passdb backend = smbpasswd
obey pam restrictions = yes
socket options = TCP_NODELAY
unix charset = ISO-8859-1
local master = yes
preferred master = yes
os level = 20
security = share
guest account = nobody
invalid users = root
smb passwd file = /etc/samba/smbpasswd

3. tambahkan kode dibawah di /etc/config/samba
config ‘samba’
option ‘name’ ‘openwrt’
option ‘description’ ‘openwrt’
option ‘workgroup’ ‘WORKGROUP’

config ‘sambashare’
option ‘read_only’ ‘no’
option ‘create_mask’ ‘0700’
option ‘dir_mask’ ‘0700’
option ‘name’ ‘samba’
option ‘path’ ‘/mnt/sdb2’ <==== sesuaikan dengan drive yg mau diakses
option 'guest_ok' 'yes

4. tambahkan baris berikut, ke "/etc/rc.local" :

—————————————————

smbd -D
nmbd -D

exit 0

—————————————————

5. ketik perintah berikut pada "putty" :
/etc/init.d/samba enable
/etc/init.d/samba start

6. Akses dengan ketik ip router pada alamat windows explorer
hehe

sumber : http://www.facebook.com/groups/openwrt/