Foscam FI9803EP

From ZoneMinder Wiki
Jump to: navigation, search

Check also informations made for Foscam_FI9805W

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

System Firmware Version 1.5.1.11
Application Firmware Version 2.22.1.143

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
Motion detection: OFF

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.

If you don't turn off motion detection in the camera Web configuration interface, the camera will slow down whenever you have motion in the frame.

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.

MJPEG Stream issues

There seems to be issues with camera and MJPEG stream. It is not able to handle much motion before dropping out. VLC is able to keep a steady stream regardless of motion. Some video settings can be changed to improve but not fix stream dropping out (9803P).

Current (New) Foscam API and Snapshots

The correct URL to use with Zoneminder for the current Foscam firmware (system firmware version 1.5.3.16, application firmware version 2.22.2.23) is:

http://(camera IP address):(port)/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=usr&pwd=pwd

For troubleshooting purposes, proper operation of the snapshot feature is verifiable using any browser. This is especially useful to confirm the snapshots are being generated in the resolution you expect.

So the settings for Zoneminder under Source are:

Source Type: Remote
Remote Protocol: HTTP
Remote Method: Simple
Remote Host Name: (your camera's IP address)
Remote Host Port: 88 [unless overridden; see below]
Remote Host Path: /cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=usr&pwd=pwd
Remote Image Colors: 24 bit color
Capture Width (pixels): 1280
Capture Height (pixels): 720

Replace "usr" and "pwd" with the username and password you have configured using the camera's Web interface.

The default port for Foscam cameras is 88. There are reports that overriding this causes problems, so using the default port is recommended.

Capture Width and Capture Height must match the configuration of the main stream in the camera's Web interface.

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 provided 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 FOR YOUR NEEDS */
define('ZM_LOG_FILE', '/var/log/zm/zm.log');
define('FOSCAM_IP', 'CAMERA_IP');
define('FOSCAM_PORT', 'PORT');
define('FOSCAM_LOGIN', 'ADMIN_LOGIN');
define('FOSCAM_PASS', 'ADMIN_PASSWORD');
define('RESTARTER_DIR', '/var/foscam_restarter/');
define('R_TIMEZONE', 'Europe/Warsaw');

/* DONT MODIFY BELOW THIS LINE UNLESS YOU KNOW WHAT ARE YOU ARE DOING */
define('LOCK_FILE', '/tmp/foscam_restarter/lock');
define('SLEEP_TIME', '120'); // sleep time in seconds

/* lock file, only one instance of this script can be run */
if ( is_file( LOCK_FILE ) ) {
   exit();
}
touch( LOCK_FILE );

class FoscamCamera {
   private $ip;
   private $port;
   private $login;
   private $password;

   public function __construct( $ip, $port, $login, $password ) {
      $this->ip = $ip;
      $this->port = $port;
      $this->login = $login;
      $this->password = $password;
   }

   public function restart() {
      $return = $this->doCommand('rebootSystem');

      if ( str_replace('<result>0</result>', '', $return) != $return) {
         return true;
      }
      return false;

   }

   private function doCommand( $command, $params = array() ) {
   
      $url = $this->getCgiUrl();
      $url.= '?cmd=' . $command;
      $url.= '&usr=' . $this->login . '&pwd=' . $this->password;

      foreach ($params as $param_key => $param_val) {
         $url.='&' . $param_key . '=' . $param_val;
      }

      return shell_exec('curl -s "' . $url . '"');

   }

   private function getCgiUrl() {
      return 'http://' . $this->ip . ':' . $this->port . '/cgi-bin/CGIProxy.fcgi';
   }

}

function endscript( $success = true ) {
   if ( $success ) {
      file_put_contents( RESTARTER_DIR . 'info_file', time() );
   }
   unlink( LOCK_FILE );
   exit();
}

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

system('mkdir -p ' . RESTARTER_DIR);

if ( !is_file( RESTARTER_DIR . 'info_file' ) ) {
   /* first run, save run time and wait for next check */
   endscript();
}

system('cat ' . ZM_LOG_FILE . ' | grep ' . FOSCAM_IP . ' | grep ERR | grep "Unable to open input" > ' . RESTARTER_DIR . 'cat001');
$error_lines = file( RESTARTER_DIR . 'cat001');

if ( count($error_lines) < 2 ) {
   // no action needed
   endscript();
}
$error_lines = array_reverse( array_filter( $error_lines, 'trim' ) );
$last_fail = new DateTime( trim( substr($error_lines[0], 0, 15) ), new DateTimeZone(R_TIMEZONE) );
$last_fail2 = new DateTime( trim( substr($error_lines[1], 0, 15) ), new DateTimeZone(R_TIMEZONE) );

$last_check_pure = file_get_contents( RESTARTER_DIR . 'info_file' );
$last_check = new DateTime();
$last_check->setTimezone( new DateTimeZone(R_TIMEZONE) );
$last_check->setTimestamp( $last_check_pure );

if (in_array('force',$argv)) {
   echo 'Forced restart!' . PHP_EOL;
}

if ( in_array('force',$argv) || ( $last_fail > $last_check && $last_fail2 > $last_check ) ) {
   echo date('d-m-Y H:i.s') . ' - fails detected restarting!' . PHP_EOL;
   $foscam = new FoscamCamera( FOSCAM_IP, FOSCAM_PORT, FOSCAM_LOGIN, FOSCAM_PASS );
   if ( $foscam->restart() ) {
      echo 'Restarted. Sleeping for ' . SLEEP_TIME . ' seconds...';
      sleep( SLEEP_TIME );
      echo 'OK' . PHP_EOL;

   } else {
      echo 'Cannot restart camera, check camera IP, PORT, LOGIN and PASSWORD. Provided user must have rights to reboot camera.' . PHP_EOL;
      endscript(false);
   }

}

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 * * * * root /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.