Difference between revisions of "Foscam FI9803EP"

From ZoneMinder Wiki
Jump to navigationJump to search
Line 170: Line 170:
                 /usr/bin/zmpkg.pl logrot 2> /dev/null > /dev/null || true
                 /usr/bin/zmpkg.pl logrot 2> /dev/null > /dev/null || true
                 /bin/rm -f /tmp/foscam_restarter/info_file
                 /bin/rm -f /tmp/foscam_restarter/info_file
                /bin/touch /tmp/foscam_restarter/info_file
         endscript
         endscript
}
}

Revision as of 14:40, 21 August 2015

Check also informations made for Foscam_FI9805W

Support only Windows while configuring - camera software need plugin which is provided as exe installer.

Currently i am using this camera settings:

Off Enhanced Vision (it always slow down when IR ON to 5fps)
User-defined
Resolution 720P
Bit Rate 4M
Frame rate 15
Key Frame Interval 10
Variable bitrate Yes

And Zoneminder settings:

Source type: FFmpeg
Source: rtsp://[LOGIN]:[PASSWORD]@10.0.0.11:88/videoMain
Remote method: RTP/RTSP
Capture width: 800
Capture height: 450

I think 720P resolution for this camera is interpolated, so i decided to decrease capture width & height to 800x450.

If you dont care about image size (and quality...) use capture width/height 1280 / 720.

Differences between FI9805W

Issues with RTSP stream also is here. There is no option 920P for this camera, use 720P while configuring via camera menu.

Commands

  1. Rebooting VIA Command line
http://[CAMERA_IP]:[CAMERA_PORT]/cgi-bin/CGIProxy.fcgi?cmd=rebootSystem&usr=[USERNAME]&pwd=[PASSWORD]

RTSP stream can hang, but API will still work fine. You can reboot camera by using URL provider above.

Auto reboot camera when it fails

Script is written in PHP (i assume You have PHP installed on Your server) Tested on Ubuntu 14.04.3 LTS

1. Paste script in /bin/foscam_restarter.php

#!/usr/bin/php
<?php
set_time_limit(0);
/* MODIFY THIS PARAMETERS TO FIT YOU NEEDS */
define('ZM_LOG_FILE', '/var/log/zm/zm.log');
define('FOSCAM_IP', 'CAMERA_IP');
define('FOSCAM_PORT', 'CAMERA_PORT');
define('FOSCAM_LOGIN', 'ADMIN RIGHTS USER');
define('FOSCAM_PASS', 'PASSWORD');

/* ITS NOT NEEDED TO MODIFY THIS LINES UNLESS YOU KNOW WHAT ARE YOU DOING */
define('LOCK_FILE', '/tmp/foscam_restarter/lock');
define('INFO_FILE', '/tmp/foscam_restarter/info_file');
define('SLEEP_TIME', '120'); // sleep time in seconds

/* DO NOT MODIFY BELOW THIS LINE UNLESS YOU KNOW WHAT ARE YOU DOING */
function endscript() {
   unlink( LOCK_FILE );
   exit();
}

function restartCamera() {
   echo 'Sending restart command...';
   system('curl -s "http://' . FOSCAM_IP . ':' . FOSCAM_PORT . '/cgi-bin/CGIProxy.fcgi?cmd=rebootSystem&usr=' . FOSCAM_LOGIN . '&pwd=' . FOSCAM_PASS . '"');
   echo 'Sleeping for ' . SLEEP_TIME . ' seconds...';
   sleep( SLEEP_TIME );
   echo 'OK' . PHP_EOL;
}

function getLastFail() {
   $last_fail = 'XXX';

   system('mkdir -p /tmp/foscam_restarter');
   system('cat ' . ZM_LOG_FILE . ' | grep ' . FOSCAM_IP . ' | grep ERR | grep "Unable to open input" > /tmp/foscam_restarter/cat001');
   $error_lines = file('/tmp/foscam_restarter/cat001');
   if ( count($error_lines) == 0 ) {
      return $last_fail;
   }
   $error_lines = array_reverse( array_filter( $error_lines, 'trim' ) );
   $last_fail = trim(substr($error_lines[0], 0, 15));
   return $last_fail;

}

if ( is_file( LOCK_FILE ) ) {
   exit();
}

touch( LOCK_FILE );

if ( !is_file( ZM_LOG_FILE ) ) {
   echo('Cannot find ZoneMinder Log File!!');
   endscript();
}

$last_fail = getLastFail();

if ( !is_file( INFO_FILE ) ) {
   file_put_contents( INFO_FILE, 'XXX' );
   $loaded_fail = 'XXX';

} else {
   $loaded_fail = file_get_contents( INFO_FILE );

}

if (in_array('force',$argv)) {
   echo 'Forced camera reset by force fail!' . PHP_EOL;
   $loaded_fail = 'YYY';
}

if ( $loaded_fail != $last_fail ) {
   echo date('d-M-Y H:I.s') . PHP_EOL;
   echo 'Camera fail detected (' . $last_fail . '), restarting camera...' . PHP_EOL;
   restartCamera();
   $last_fail = getLastFail();
   file_put_contents( INFO_FILE, $last_fail );

}
endscript();

2. Modify first five params to fit Your needs, and save file

3. Make it executable

# chmod +x /bin/foscam_restarter.php

4. OPTIONAL You can check if its working properly with (it will restart your camera!!)

# foscam_restarter.php force

5. Make log file for restarter

# touch /var/log/foscam_restarter.log

6. Add script to crontab

# echo "*/1 * * * * /bin/foscam_restarter.php >> /var/log/foscam_restarter.log" > /etc/cron.d/foscam_restarter
# echo "" >> /etc/cron.d/foscam_restarter

7. Restart cron

# service cron restart

8. If You have logrotate on zoneminder logs, modify logrotate script - add cleanup of /tmp/foscam_restarter/info_file (defined as INFO_FILE) For example, script for logrotate with restarter support:

/var/log/zm/*.log {
        daily
        missingok
        rotate 31
        compress
        delaycompress
        sharedscripts
        postrotate
                /usr/bin/zmpkg.pl logrot 2> /dev/null > /dev/null || true
                /bin/rm -f /tmp/foscam_restarter/info_file
        endscript
}

9. Probably its done, unless You have other custom modifications.