-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptz.js
63 lines (54 loc) · 1.86 KB
/
ptz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const onvif = require('onvif');
// Define your camera's ONVIF credentials and IP address
const cameraConfig = {
hostname: 'YOUR_CAMERA_IP_ADDRESS',
username: 'YOUR_USERNAME',
password: 'YOUR_PASSWORD',
port: 80, // Default ONVIF port is 80
};
// Create an ONVIF device object
const cam = new onvif.Cam(cameraConfig);
// Connect to the camera
cam.connect((err) => {
if (err) {
console.error('Error connecting to the camera:', err);
return;
}
console.log('Connected to the camera');
// Create PTZ service
const ptz = new onvif.PTZ({
xaddr: cam.services.ptz,
user: cameraConfig.username,
pass: cameraConfig.password,
});
// PTZ command to move the camera up (tilt up)
const ptzCommand = {
velocity: {
x: 0, // Pan (horizontal movement) value (0 is no movement)
y: 1, // Tilt (vertical movement) value (1 is up, -1 is down)
zoom: 0, // Zoom value (0 is no zoom)
},
timeout: 'PT5S', // Timeout for the movement (e.g., 5 seconds)
};
ptz.continuousMove(ptzCommand, (err, result) => {
if (err) {
console.error('Error sending PTZ command:', err);
} else {
console.log('PTZ command sent successfully');
}
// Stop the PTZ movement after a few seconds (optional)
setTimeout(() => {
ptz.stop((err, result) => {
if (err) {
console.error('Error stopping PTZ movement:', err);
} else {
console.log('PTZ movement stopped');
}
// Disconnect from the camera
cam.disconnect(() => {
console.log('Disconnected from the camera');
});
});
}, 5000); // Stop PTZ movement after 5 seconds (adjust as needed)
});
});