Difference between revisions of "Foscam FI9803EP"

From ZoneMinder Wiki
Jump to navigationJump to search
Line 124: Line 124:
6. Add script to crontab
6. Add script to crontab
<pre>
<pre>
# echo "*/1 * * * * /bin/foscam_restarter.php >> /var/log/foscam_restarter.php" > /etc/cron.d/foscam_restarter
# echo "*/1 * * * * /bin/foscam_restarter.php >> /var/log/foscam_restarter.log" > /etc/cron.d/foscam_restarter
# echo "" >> /etc/cron.d/foscam_restarter
# echo "" >> /etc/cron.d/foscam_restarter
</pre>
</pre>

Revision as of 14:13, 21 August 2015

Follow informations made for Foscam_FI9805W

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

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