Implementation in Javascript of the Foscam IPCamera CGI Proxy API. The aim is to be able to control the camera from NodeJS.
npm install @richnologies/foscam
The module is just a class that represents one camera. So you could instantiate as many object cameras as you need to control. The methods API is heavily based on Promises. Bellow you can find extra information for each method.
const Foscam = require('@richnologies/foscam');
const myCamera = new Foscam({
host: 'your-camera-ip',
port: 'your-camera-port',
usr: 'your-user',
pwd: 'your-password'
});
myCamera
.ptzMoveRight(4000)
.then(function(){
// DO SOMETHING AFTER THE CAMERA HAS MOVED FOR 4 SECONDS
});
In order to connect to the camera you first need to provide its access details. This will create an object for that particular camera. You can create as much objects as you need, so you can control multiple cameras.
name | type | default | description |
---|---|---|---|
host | string | localhost | Camera IP or hostname |
port | number | 80 | Camera port number |
usr | string | admin | Username |
pwd | string | root | Password |
const myCamera = new Foscam({
host: 'your-camera-ip',
port: 80,
usr: 'your-user',
pwd: 'your-password'
});
Most of the methos are based on promises. To move the camera, you just call the corresponding method, optionally indicating for how long you want the camera to move
name | type | default | description |
---|---|---|---|
time | int | Value in miliseconds before stop |
// The camera will move Up for 2 seconds
myCamera
.ptzMoveUp(2000)
.then(function() {
// THE CAMERA ALREDY MOVES FOR 2 SECONDS
);
Next methods are equivalent, just change the action they send to the camera. I think names are self explanatory.
Stops the pan/tilt movement. This won't stop the zoom movement. In order to stop zoom you must use the specific method describe zoomStop()
myCamera
.ptzStopRun()
.then(function() {
// CAMERAS ZOOM IS NOW STOPPED
});
Returns the current of pan/tilt speed of the camera. They are 5 possible values
- 0 -> Very Slow
- 1 -> Slow
- 2 -> Normal
- 3 -> Fast
- 4 -> Very Fast
myCamera
.getPTZSpeed()
.then(function(speed) {
// DO WHAT YOU NEED WITH THE SPEED
});
Update the speed of the camera. Valid values comes from 0 to 4, being 0 the slowest and 4 the fastest.
name | type | default | description |
---|---|---|---|
speed | int | Speed you want for the camera |
myCamera
.setPTZSpeed(2)
.then(function() {
// NOW THE SPEED IS NORMAL
});
The camera will zoom in for the indicated milisencons in case you pass it as a parameter, or until either you stop the zoom or it hits the maximum zoom. The zoom out function is equivalent.
name | type | default | description |
---|---|---|---|
time | int | Value in miliseconds before stop |
// The camera will zoom in for 2 seconds
myCamera
.zoomIn(2000)
.then(function() {
// THE CAMERA ALREDY ZOOMS FOR 2 SECONDS
);
Stops the zoom movement.
myCamera
.zoomStop()
.then(function() {
// CAMERAS ZOOM IS NOW STOPPED
});
Returns the current of zoom speed of the camera. They are 3 possible values
- 0 -> Very Slow
- 1 -> Normal
- 2 -> Fat
myCamera
.getZoomSpeed()
.then(function(speed) {
// DO WHAT YOU NEED WITH THE SPEED
});
Update the zoom speed of the camera. Valid values comes from 0 to 2, being 0 the slowest and 2 the fastest.
name | type | default | description |
---|---|---|---|
speed | int | Zoom speed you want for the camera |
myCamera
.setZoomSpeed(2)
.then(function() {
// NOW THE SPEED IS FAST
});
Returns the count of how many presets the camera has and a list with the names of all of the points
myCamera
.getPTZPresetPointList()
.then(function(results) {
// DO WHAT YOU NEED WITH THE RESULTS
});
Add a new preset point with the given name. The preset point is the current position of the camera, including its pan/tilt/zoom.
name | type | default | description |
---|---|---|---|
name | string | The name for the preset point |
myCamera
.ptzAddPresetPoint('MyPresetPoint')
.then(function() {
// YOUR POINT HAS BEEN ADDED
});
Deletes the preset with the given name
name | type | default | description |
---|---|---|---|
name | string | The name for the preset point |
myCamera
.ptzDeletePresetPoint('MyPresetPoint')
.then(function() {
// YOUR POINT HAS BEEN DELETED
});
The camera moves to the preset with the given name
name | type | default | description |
---|---|---|---|
name | string | The name for the preset point |
myCamera
.ptzGotoPresetPoint('MyPresetPoint')
.then(function() {
// WARNING! AT THIS POINT THE CAMERA IS NOT AT THE PRESET POINT
// ITS JUST MOVING TOWARD IT
});
The camera moves throw the points the selected cruise
name | type | default | description |
---|---|---|---|
mapName | string | The name of the cruise |
myCamera
.ptzStartCruise('MyCruiseName')
.then(function() {
// WARNING! AT THIS POINT THE CAMERA IS MOVING THROW THE CRUISE
});
The camera stops moving
myCamera
.ptzStopCruise()
.then(function() {
// AT THIS POINT THE CAMARA IS STOPPED
});