Axis has developed an extended CRON service to facilitate periodic command execution within the camera server. In practice, this service enables you to program event and/or time triggered functions within the camera server.
CRON scripts for use with the camera server can contain one or more entries that can be created using any common text editor.
Each entry contains the following elements:
It is good programming practice to start each new entry with a comment to describe its function. Comments are optional but must be proceeded by a # character, as detailed below:
#<comment> |
Example:
# This CRON entry will... |
The commands contained within each specific entry are triggered by a defined trigger condition. The trigger condition is specified by six separate fields and must be terminated with a colon ":".
Date and Time fields
The first five fields specify the time and date events,
i.e. Minute, Hour, Day, Month
and Day of the week. The
sixth field is an optional Input and Boot field that can define an
input and/or boot event.
The syntax for each field within a trigger condition is governed by the following rules:
Example:
Trigger every month, between the fourth and eighth at
10.03, 12.03 and 14.03, using the 24hr clock
3 10,12,14 4-8 * * : |
Input and Boot field
The sixth field consists of a character array. It is
optional and defines the input and boot trigger functions.
You can program the camera server to
trigger at startup, or on pre-determined logical states
present on either the Control button or the digital input ports, using
the trigger variables BOOT,
B, I1 and I2 respectively.
This table outlines the available trigger variables:
| Trigger variables |
Description |
|---|---|
BOOT |
Activate at startup |
\B |
Activate after high-low logical transition of Control button |
/B |
Activate after low-high logical transition of Control button |
1B |
Activate when Control button is logically high (pressed) |
0B |
Activate when Control button is logically low (released) |
\I1 |
Activate after high-low logical transition on Input Port 1 |
/I2 |
Activate after low-high logical transition on Input Port 2 |
1I1 |
Activate when Input Port 1 is logically high |
0I2 |
Activate when Input Port 2 is logically low |
Note:
By combining these trigger variables using a logical AND function (&), you can develop complex triggering mechanisms.
Examples:
/B |
(Control button
transition from low to high) |
\B&1I1 |
(Control button
transition from high to low and Input 1 high) |
0I2&1I1 |
(Input 2 low and
Input 1 high) |
The following table summarizes the triggering event entry fields:
| Time and Date fields | Input and Boot field (optional) |
||||
| Minute | Hour | Day | Month | Day of the week | Conditional tag |
| * | * | * | * | * | * |
| 0-59 | 0-23 | 1-31 | 1-12 | 0-6 0 = Sunday |
BOOT B I1, I2 |
Several commands can be used within an entry. All commands must be terminated with a semi-colon ";".
These commands are available:
Note:
Although the downloaded entries are effectively executed in
parallel, the commands included within each entry are executed
sequentially, i.e the second command is not executed until the
first is finished.
This example shows how several entries can be programmed into one CRON script:
# This is an example of an Axis
extended CRON script:% |
These instructions describe how to
download a CRON script, e.g. cron.txt,
to the camera server using FTP:
root, using the root password.
bin.
put cron.txt cronscript |
FTP will indicate "File transfer complete
"or similar when the file transfer is complete. The
CRON script becomes active within one minute after it has been
downloaded to the camera server.
Notes:
Syntax
alert [-host HOST] [-port PORTNUMBER] [-message STRING];
Options
-host
Specifies the host name or Internet address of the remote host.
-port
Specifies the TCP port number in the range [0..65534].
-message
Specifies the message that will be sent to the remote host. The message must be surrounded by quotation marks. Hexadecimal coded messages must be preceded by \0x, e.g. "\0x04" for the non-printed character EOT. To include a quotation mark, it must be preceded by a backslash, e.g. \".
Example
# This command will send the message "Alarm
# "0013" from camera server" to the remote host when
# input port 1 goes high.
* * * * * /I1:
alert -host 172.16.253.80 -port 2703 -message "Alarm
\"0013\" from camera server";
%
Syntax
buffer_init [1,[IMAGE],[SIZE] [:1,[IMAGE],[SIZE]]];
Options
1
Refers to the camera number, which is always 1 for the AXIS 200+.
[IMAGE]
Specifies the image type 1-3, where 1 is halfsize.jpg, 2 is fullsize.jpg and 3 is hugesize.jpg.
[SIZE]
Specifies the maximum number of images that can be stored in the buffer. Valid range is 0-255.
Notes:
Example 1
# At startup, this command will initiate one
# buffer with 25 fullsize.jpg images
# and 5 hugesize.jpg images.
* * * * * BOOT:
buffer_init 1,2,25:1,3,5;
%
Example 2
# This command will clear the buffer every Sunday.
0 0 * * 0 * :
buffer_init;
%
When invoked, the buffer_start command is executed in the background. Any subsequent command in the event entry will be executed immediately.
To retrieve the stored images, specify the source using this syntax:
http://<camera>/images/buffer.jpg?imagetype=<value>,
|
Example:
http://mycam/images/buffer.jpg?imagetype=fullsize.jpg
|
You can also retrieve the images using the mail and ftp commands.
Syntax
buffer_start [-src SOURCEFILE] [-interval TIME] [-duration TIME] [-store SIZE];
Options
-src
Specifies the source file name, i.e. halfsize.jpg, fullsize.jpg or hugesize.jpg.
-interval
Specifies the time interval between consecutive snapshots. If omitted, new snapshots will be generated without any delay. Format: h<hours>m<minutes>s<seconds>.
-duration
Specifies the total time for the command to run. If omitted, the
buffer_start command will be issued only once. Format: h<hours>m<minutes>s<seconds>.
If you specify -duration inf the command will continue to be executed until it is interrupted by any of the commands buffer_init, buffer_start or buffer_stop.
-store
Specifies the number of images to be stored in the buffer. This setting will override the duration. The maximum number of images is specified by the buffer_init command.
Example 1
# This command will keep loading fullsize.jpg images.
|
Example 2
# This command will store 10 hugesize.jpg images
|
Example 3
# At startup, the buffer is initialized to hold 15 fullsize.jpg images. |
The command is typically used together with the the buffer_start command.
Syntax
buffer_stop [-src SOURCEFILE] [-interval TIME] [-duration TIME] [-store SIZE];
Options
-src
Specifies the source file name, i.e. halfsize.jpg, fullsize.jpg or hugesize.jpg.
-interval
Specifies the time interval between consecutive snapshots. If omitted, new snapshots will be generated without any delay. Format: h<hours>m<minutes>s<seconds>.
-duration
Specifies the total time for the command to run. If omitted, the buffer_start command will be issued only once. Format: h<hours>m<minutes>s<seconds>.
If you specify -duration inf the command will continue to be executed until it is interrupted by a buffer_init command.
-store
Specifies the number of images to be stored in the buffer. This setting will override the duration. The maximum number of images is specified by the buffer_init command.
Example
# This command initiates the buffer to hold 60 halfsize.jpg |
Note:
ftp [-host HOST] [-user USERNAME] [-pass PASSWORD]
[-src SOURCEFILE] [-dest DESTINATIONFILE]
[-temp TEMPORARY_DESTINATION_NAME] [-loop LOOPTIME]
[-time TOTALTIME]
[-buffer BUFFERTYPE];
Options
-host
Specifies the name or Internet address of the remote host. If specifying the
name, performance will be slightly decreased due to
the DNS lookup. If no host is specified, the compiler will complain.
-user
Specifies the user name for logging on to the remote host. If no user name is specified, the compiler will complain.
-pass
Specifies the password for logging on to the remote host.
-src
Specifies the source file name. If omitted, the fullsize.jpg file will be sent. To include the image buffer, specify images/buffer.jpg.If an erroneous file name has been specified, no action will be taken during execution.
-dest
Specifies the name and whole path of the destination file. If omitted, the
destination file name will be the same as the source file name. The maximum length of
a destination file name is 255 characters. You can add as many
destination files as required, separated by a space.
You can add time stamps, such as time, date and file indexes, to the destination file name. This is useful for example when you are transferring a series of files.
The following table lists the available time
stamp variables. Every substitution must be
proceeded by a dollar sign '$'.
$s The current second in the range 00-59.
$m The current minute in the range 00-59.
$h The current hour in the range 00-23.
$d The current day of the month in the range 01-31.
$n The current month in the range 01-12.
$y The current year without the century in the range 00-99.
$YThe current year including the century.
$rS-E Inserts an index number starting from number S through all the numbers including the number E. If you leave out number E, it will be interpreted as a very large number. Note: The rS-E substitution can be used with the first destination file only.
-temp
Specifies a temporary name for the destination. This is to prevent someone else from accidentally reading the file during the download.
-loop
Specifies the time interval within which the command
should be repeated. Used together with the time attribute. If omitted, there will be no delay between repeated transfers. Format: h<hours>m<minutes>s<seconds>. Optional.
-time
Specifies the total time the command should loop. Used
together with the loop attribute. If omitted, the ftp command will be
issued only once. Format: h<hours>m<minutes>s<seconds>. Optional.
-buffer
Specifies the buffer type, i.e. fullsize.jpg, halfsize.jpg or hugesize.jpg. Only valid if -src is set to images/buffer.jpg.
Note:
-ctrlport
Specifies the TCP port number in the range [0..65534] to be used as the control port for the FTP server.
-dataport
Specifies the TCP port number in the range [0..65534] to be used as data port for the FTP server.
-to
Specifies the time out,
i.e. the FTP session will terminate when the specified time limit has expired. Format: h<hours>m<minutes>s<seconds>.
However, these options can only be used via a text editor.
Example 1
# This command will log in as "elvis" with the
# password "presley" on the host with the Internet
# address 123.123.123.123, download a hugesize
# image with the name "king.jpg" and put
# it in the directory "/home/elvis" on the remote
# host. During download, the file name "tmp.jpg"
# will be used.
* * * * * :
ftp -host 123.123.123.123 -user elvis -pass presley
-src hugesize.jpg -dest /home/elvis/king.jpg -temp
tmp.jpg;
%
Example 2
# This command will every hour, every five seconds
# for twenty minutes, download a fullsize image
# and save the images with a time
# stamp in the filename.
0 * * * * :
ftp -src fullsize.jpg -host an.interesting.site
-dest tmp/full$h$m$s.jpg -user billy -pass startrek
-loop s5 -time m20;
%
Example 3
# This command will send 1001 consecutive fullsize
# images to "funny.host.name". The first and last
# images will be named "fullsize1000.jpg" and
# "fullsize2000.jpg", respectively.
* * * * * :
ftp -host funny.host.name -user camera -pass secret
-src fullsize.jpg -dest
/home/camera/tmp/fullsize$r1000-2000.jpg -time m30;
%
Note:
To display the log file, you type the following in the address/location field of your Web browser:
http://<camera server>/log/messages |
Syntax
log [MESSAGE];
Options
[MESSAGE]
The message string must be surrounded by quotation marks.
Example
# This command will write a message to the log file when
|
Note:
mail [-s SUBJECT] [-a ATTACHMENTS] [-t RECIPIENTS]
[-b BUFFERTYPE] [-n NUMBER];
Options
-s
Specifies the subject text for the e-mail. A simple one-word subject
does not require quotation marks. A subject with multiple
words must be surrounded by quotation marks.
-a
Specifies attachments such as images or files. To include the
image buffer, specify images/buffer.jpg.
-t
Specifies the e-mail address of the recipient(s).
-b
Specifies the buffer type, i.e. fullsize.jpg, halfsize.jpg or hugesize.jpg. Only valid if -a is set to images/buffer.jpg.
-n
Specifies the number of buffered images to be included in the e-mail. Only valid if -src is set to images/buffer.jpg.
Example 1
# This command will send an e-mail with the
# subject "Hello" and the attached file
# fullsize.jpg to someone@company.com
* * * * * :
mail -s Hello -a fullsize.jpg -t someone@company.com;
%
Example 2
# This command will send an e-mail with the
# subject "This "fullsize.jpg" was sent from my
# camera" to two recipients.
* * * * * :
mail -s "This \"fullsize.jpg\" was sent from my camera" -a fullsize.jpg -t someone@axis.com
anotherone@axis.com;
%
Example 3
# This command will send an e-mail with five
# attachments.
* * * * * :
mail -a fullsize.jpg halfsize.jpg hugesize.ppm
cronscript config -t me@at.home;
%
Syntax
offline;
Syntax
online [-dial NUMBERS] [-dial_attempts NUM] [-user USERNAME -pass PASSWORD]
[-timeout TIME] [-script "send expect send expect ..."];
Options
-dial
Specifies the phone numbers that will be sent to the modem as ATDT<phone number>. It is possible to have more than one phone number in case the the previous didn't work. As soon as a server answers the call to one phone number, the rest of the numbers will be ignored for this time. The numbers are separated by spaces and thus the numbers cannot include spaces.
-redial_attempts
If it is difficult to get connected to a busy server, it is possible to try many times. The argument to the redial_attempts switch must be a number between 0 and 30. The default is 0.
-user
Specifies the user name used for authentication. Note that spaces are not allowed in the user name. Optional.
It is possible to have '%' characters i the username and in the password. One have to escape the '%' character with a backslash '\' though.
-pass
Specifies the password. Required if a user name is specified.
-timeout
Resets the camera server when the specified time limit has exceeded. Format: h<hours>m<minutes>s<seconds>. Optional.
-script
Specifies an optional script string of expect-send pairs to be sent over the line. This must be the last option in the command.
If a send word is empty, i.e. if it contains single quotes (''), nothing will be sent until the expect word is received.
For a login sequence, you can use the words $(USER) and $(PASS). They will be replaced by the arguments specified in the -user and -pass options, respectively.
If the string does not include an escape code, a carriage return character will be appended automatically at the end of the string. Valid escape codes are: \r (carriage return), \n (line feed) and \t (tab).
At the end of the script, the camera server will enter the negotiation phase.
Example
# This command will first dial up a server with the
# phone number 555-1234, and if that fails it will dial
# the number 555-5678. This procedure should be repeated
# one more time if none of the servers answered.
#
# Once we have contact with a server we should login with
# user name "john" and password "xyz%hej". It will first
# wait for the string "ogin:" and send the user name. It
# will then wait for the string "ass:" and send the password.
#
* * * * * :
online -dial 555-1234 555-5678 -redial_attempts 1
-user "john" -pass "xyz\%hej"
-script "'' 'ogin:' '$(USER)' 'ass:' '$(PASS)'";
%
Syntax
reset [-soft | -hard];
Options
-soft
Reinitiates the camera server protocols.
-hard
Performs a complete reboot of the camera server.
Example
# This command will reset the camera server hardware
# once a day.
0 0 * * * :
reset -hard;
%
Syntax
sleep <seconds>;
Specifies the number of seconds to wait before proceeding with the next command in the event entry.
Example
# This command will result in a 30 seconds pause
# in the CRON script execution.
* * * * * :
sleep 30;
%
lastshot.jpg image.
The command can also be used for controlling the relay switch.
Syntax
snapshot [-l LOOPTIME] [-t TOTALTIME] [FILE];
Options
-l
Specifies the time between two consecutive image updates.
-t
Specifies the duration of the command. Format: h<hours>m<minutes>s<seconds>.
[FILE]
Specifies the image type: fullsize.jpg or halfsize.jpg.
If using the command for controlling the relay switch, you specify io/relayon.txt and io/relayoff.txt, respectively.
Example 1
# This command will update the lastshot.jpg image
# with a fullsize image.
* * * * * :
snapshot fullsize.jpg;
%
Example 2
# During one minute, the lastshot image will be
# updated as halfsize.jpg with two-seconds
# intervals.
* * * * * :
snapshot -l s2 -t m1 halfsize.jpg;
%
Tech-Support@axis.com