blib/lib/IPCamera/Reolink.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package IPCamera::Reolink;
2 #ABSTRACT: HTTP(S)/REST interface to Reolink IP Cameras and NVRs per Reolink document "Camera HTTP API User Guide Version 8 2023-4"
3  
4 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶use REST::Client;
Subroutine BEGIN: called CC=1 SCAR=2.6
9 use IO::Socket::SSL;
10 use JSON;
11 use Data::Dumper;
12 use Time::HiRes;
13 use String::Random;
14  
15 # IPCamera::Reolink channel values.
16 use constant ChannelDefault => 0;
17  
18 # IPCamera::Reolink::PtzCtrl() op value.
19 use constant PTZ_Auto => 'Auto';
20 use constant PTZ_Down => 'Down';
21 use constant PTZ_Left => 'Left';
22 use constant PTZ_LeftDown => 'LeftDown';
23 use constant PTZ_LeftUp => 'LeftUp';
24 use constant PTZ_Right => 'Right';
25 use constant PTZ_RightDown => 'RightDown';
26 use constant PTZ_RightUp => 'RightUp';
27 use constant PTZ_Stop => 'Stop';
28 use constant PTZ_Up => 'Up';
29 use constant PTZ_ZoomInc => 'ZoomInc';
30 use constant PTZ_ZoomDec => 'ZoomDec';
31 use constant PTZ_IrisDec => 'IrisDec'; # Iris shrink in the specified speed.
32 use constant PTZ_IrisInc => 'IrisInc'; # Iris enlarge in the specified speed.
33 use constant PTZ_FocusDec => 'FocusDec'; # Focus backwards in the specified speed.
34 use constant PTZ_FocusInc => 'FocusInc'; # Focus forwards in the specified speed.
35 use constant PTZ_StartPatrol => 'StartPatrol'; # PTZ patrol in the specified speed.
36 use constant PTZ_StopPatrol => 'StopPatrol'; # PTZ stop patrol.
37 use constant PTZ_ToPos => 'ToPos'; # PTZ turn to a specified preset in the specified speed.
38  
39 # IPCamera::Reolink::PtzCtrl() op values as list.
40 our @PTZ_op_list = (PTZ_Auto, PTZ_Down, PTZ_Left, PTZ_LeftDown, PTZ_LeftUp, PTZ_Right, PTZ_RightDown, PTZ_RightUp, PTZ_Stop, PTZ_Up, PTZ_ZoomInc, PTZ_ZoomDec, PTZ_IrisDec, PTZ_IrisInc, PTZ_FocusDec, PTZ_FocusInc, PTZ_StartPatrol, PTZ_StopPatrol, PTZ_ToPos, );
41  
42 # IPCamera::Reolink::PtzCtrl() speed values.
43 use constant PTZ_SpeedMin => 1;
44 use constant PTZ_SpeedMax => 64;
45 use constant PTZ_SpeedHalf => 32;
46  
47 # IPCamera::Reolink::PtzCtrl() speed values as list.
48 our @PTZ_speed_list = (PTZ_SpeedMin ... PTZ_SpeedMax);
49  
50 # IPCamera::Reolink::PtzCtrl() preset values.
51 use constant PTZ_PresetMin => 0;
52 use constant PTZ_PresetMax => 63;
53  
54 # IPCamera::Reolink::PtzCtrl() preset values as list.
55 our @PTZ_preset_list = (PTZ_PresetMin ... PTZ_PresetMax);
56  
57 # IPCamera::Reolink::SetPtzPreset() maximum preset name length.
58 use constant PTZ_PresetMaxNameLength => 31;
59  
60 # IPCamera::Reolink::StartZoomFocus() op values.
61 use constant ZF_ZoomPos => 'ZoomPos'; # set camera zoom to specified value
62  
63 # IPCamera::Reolink::StartZoomFocus() op ZoomPos values.
64 use constant ZF_ZoomPosMin => 0;
65 use constant ZF_ZoomPosMax => 32;
66  
67 # IPCamera::Reolink::StartZoomFocus() op ZoomPos values as list.
68 our @PTZ_ZoomPos_list = (ZF_ZoomPosMin ... ZF_ZoomPosMax);
69  
70 # IPCamera::Reolink::StartZoomFocus() FocusPos op values.
71 use constant ZF_FocusPos => 'FocusPos'; # set camera focus to specified value
72  
73 # IPCamera::Reolink::StartZoomFocus() op FocusPos values.
74 use constant ZF_FocusPosMin => 0;
75 use constant ZF_FocusPosMax => 248;
76  
77 # IPCamera::Reolink::StartZoomFocus() op FocusPos values as list.
78 our @PTZ_FocusPos_list = (ZF_FocusPosMin ... ZF_FocusPosMax);
79  
80 # IPCamera::Reolink:SetOsd() pos values.
81 use constant OSD_UpperLeft => "Upper Left";
82 use constant OSD_TopCenter => "Top Center";
83 use constant OSD_UpperRight => "Upper Right";
84 use constant OSD_LowerLeft => "Lower Left";
85 use constant OSD_BottomCenter => "Bottom Center";
86 use constant OSD_LowerRight => "Lower Right";
87 use constant OSD_OtherConfiguration => "Other Configuration";
88  
89 # IPCamera::Reolink:SetOsd() pos values as list.
90 our @OSD_pos_list = (OSD_UpperLeft, OSD_TopCenter, OSD_UpperRight, OSD_LowerLeft, OSD_BottomCenter, OSD_LowerRight, OSD_OtherConfiguration, );
91  
92 # IPCamera::Reolink::SetWhiteLed() and IPCamera::Reolink::GetWhiteLed() state values
93 use constant WhiteLed_StateOff => 0;
94 use constant WhiteLed_StateOn => 1;
95  
96 # IPCamera::Reolink::SetWhiteLed() and IPCamera::Reolink::GetWhiteLed() mode values
97 use constant WhiteLed_ModeOff => 0;
98 use constant WhiteLed_ModeNightSmart => 1;
99 use constant WhiteLed_ModeTimer => 3;
100  
101 # IPCamera::Reolink::SetWhiteLed() and IPCamera::Reolink::GetWhiteLed() mode values as list
102 our @WhiteLed_Mode_list = (WhiteLed_ModeOff, WhiteLed_ModeNightSmart, WhiteLed_ModeTimer, );
103  
104 # IPCamera::Reolink::SetWhiteLed() and IPCamera::Reolink::GetWhiteLed() bright values
105 use constant WhiteLed_BrightMin => 1;
106 use constant WhiteLed_BrightMax => 100;
107  
108 # IPCamera::Reolink::SetWhiteLed() and IPCamera::Reolink::GetWhiteLed() LightingSchedule values
109 package IPCamera::Reolink::LightingSchedule
110 {
111 my %hash;
112 sub new($$$$){
113 my($StartHour, $StartMin, $EndHour, $EndMin) = @_;
114 $hash{StartHour} = $StartHour;
115 $hash{StartMin} = $StartMin;
116 $hash{EndHour} = $EndHour;
117 $hash{EndMin} = $EndMin;
118  
119 return \%hash;
120 } # new
121 } # package IPCamera::Reolink::LightingSchedule
122  
123 # IPCamera::Reolink::SetWhiteLed() and IPCamera::Reolink::GetWhiteLed() wlAiDetectType values
124 package IPCamera::Reolink::wlAiDetectType
125 {
126 my %hash;
127 sub new($$$){
128 my($dog_cat, $people, $vehicle) = @_;
129 $hash{dog_cat} = $dog_cat;
130 $hash{people} = $people;
131 $hash{vehicle} = $vehicle;
132  
133 return \%hash;
134 } # new
135 } # package IPCamera::Reolink::wlAiDetectType
136  
137 # IPCamera::Reolink:AudioAlarmPlay() alarm_mode values.
138 use constant AAP_AlarmModeTimes => "times"; # play # times specified by times
139 use constant AAP_AlarmModeManual => "manu"; # play continuously until next AudioAlarmPlay command
140  
141 # IPCamera::Reolink:AudioAlarmPlay() alarm_mode values as list.
142 our @AAP_AlarmMode_list = (AAP_AlarmModeTimes, AAP_AlarmModeManual, );
143  
144 # IPCamera::Reolink::GetIrLights() and IPCamera::Reolink::SetIrLights() IrLights_State values
145 use constant IrLights_State_Auto => "Auto"; # IR lights will automatically turn on in dim light and turn off when there is sufficient lighting.
146 use constant IrLights_State_Off => "Off"; # IR lights will stay off
147 use constant IrLights_State_On => "On"; # IR lights will stay on
148  
149 our @IrLights_State_list = (IrLights_State_Auto. IrLights_State_Off, IrLights_State_On, );
150  
151 our $VERSION = '1.10';
152  
153 our $DEBUG = 0; # > 0 for debug output to STDERR
154  
155 sub new {
156 my $class = shift;
157 my $hash_ref = $_[0];
158 my $self;
159 if(ref($hash_ref) eq ref({})){
160 # { camera_url => 'http://192.168.1.166', camera_user_name => 'api', camera_password => 'this-is-a-bad-password', camera_X509_certificate_file => 'camera.crt', camera_X509_key_file => 'camera.key', camera_certificate_authority_file => 'camera.ca', }}
161 $self = bless($hash_ref, $class);
162 $self->{_is_hash_ref} = 1;
163 }else{
164 $self = bless({}, $class);
165 my($camera_url, $camera_user_name, $camera_password, $camera_X509_certificate_file, $camera_X509_key_file, $camera_certificate_authority_file) = @_;
166 $self->{camera_url} = $camera_url;
167 $self->{camera_user_name} = $camera_user_name;
168 $self->{camera_password} = $camera_password;
169 $self->{camera_x509_certificate_file} = $camera_X509_certificate_file;
170 $self->{camera_x509_key_file} = $camera_X509_key_file;
171 $self->{camera_certificate_authority_file} = $camera_certificate_authority_file;
172 $self->{_is_hash_ref} = 0;
173 } # if
174 $self->{_camera_rest_client} = undef; # defer REST connection to camera until first Login()
175 $self->{_camera_login_token} = undef; # pass to other API functions
176 $self->{_camera_login_lease_time} = 0; # time in seconds that the login token is valid, force initial Login()
177 $self->{_camera_login_lease_start_time} = time(); # time that the login token was acquired, force initial Login()
178 my $camera_url = $self->{camera_url};
179 if($camera_url =~ m/^https/i){
180 $self->{_is_https} = 1;
181 }else{
182 $self->{_is_https} = 0;
183 } # if
184 return $self;
185 } # new()
186  
187 # _sendCameraCommand() - send command to camera and return response
188 sub _sendCameraCommand($$$$){
189 my($camera_rest_client, $camera_command, $request_r, $token) = @_;
190  
191 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): enter: camera_command '$camera_command' request_r '" . Dumper($request_r) . "'\n" if($DEBUG > 2);
192  
193 my $t1 = Time::HiRes::time() if($DEBUG > 1);
194 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): " . $t1 . ": call JSON::encode_json()\n" if($DEBUG > 2);
195 my $encoded_request = JSON::encode_json($request_r);
196  
197 my $t2 = Time::HiRes::time() if($DEBUG > 2);
198  
199 if(defined($token)){
200 if($camera_command eq 'Snap'){
201 # Snap command returns JPG data not JSON, rs is a random string used to prevent browser caching of the image data.
202 my $url = 'api.cgi?cmd=' . $camera_command . '&token=' . $token . '&rs=' . @$request_r[0]->{param}->{rs};
203 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): " . $t2 . ": call POST($url)\n" if($DEBUG > 2);
204 $camera_rest_client->POST($url, $encoded_request);
205 }else{
206 # Returns JSON data.
207 my $url = 'api.cgi?cmd=' . $camera_command . '&token=' . $token;
208 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): " . $t2 . ": call POST($url)\n" if($DEBUG > 2);
209 $camera_rest_client->POST($url, $encoded_request);
210 } # if
211 }else{
212 # $token undefined for Login
213 my $url = 'api.cgi?cmd=' . $camera_command;
214 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): " . $t2 . ": call POST($url)\n" if($DEBUG > 2);
215 $camera_rest_client->POST($url, $encoded_request);
216 } # if
217  
218 my $t3 = Time::HiRes::time() if($DEBUG > 2);
219 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): " . $t3 . ": call responseCode()\n" if($DEBUG > 2);
220 my $response_code = $camera_rest_client->responseCode();
221  
222 my $t4 = Time::HiRes::time() if($DEBUG > 2);
223 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): " . $t4 . ": call responseContent()\n" if($DEBUG > 2);
224 my $response_content = $camera_rest_client->responseContent(); # JSON
225  
226 if($camera_command eq 'Snap'){
227 # responseContent is not JSON but the actual JPG image data
228 #
229 # Content-Type: image/jpeg
230 # Content-Length: 171648
231 # Connection: keep-alive
232 # X-Frame-Options: SAMEORIGIN
233 # X-XSS-Protection: 1; mode=block
234 # X-Content-Type-Options: nosniff
235 # .............................(JPG data)
236 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): " . $t4 . ": jpg responseContent() length " . length($response_content) . "\n" if($DEBUG > 2);
237 my $t6 = Time::HiRes::time() if($DEBUG > 1);
238 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): " . ($t2 - $t1) . " POST " . ($t3 - $t2) . " responseCode " . ($t4 - $t3) . " responseContent " . ($t6 - $t4) . " TOTAL " . ($t6 - $t1) . "\n" if($DEBUG > 2);
239 if($DEBUG > 1){
240 if($DEBUG > 3){
241 my @headers = $camera_rest_client->responseHeaders();
242 foreach my $header (@headers){
243 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): header '" . $header . "' '" . $camera_rest_client->responseHeader($header) . "' \n";
244 } # for
245 } # if
246 my $save_linewidth = $Data::Dump::LINEWIDTH;
247 $Data::Dump::LINEWIDTH = 500; # no linebreak
248 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): command '" . $camera_command . "' token '" . (defined($token) ? $token : 'undef') . "' request '" . Dumper($request_r) . "' response length " . length($response_content) . " time " . ($t6 - $t1) . " seconds\n";
249 $Data::Dump::LINEWIDTH = $save_linewidth;
250 } # if
251 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): exit OK\n" if($DEBUG > 2);
252 return $response_content;
253 }else{
254 my $t5 = Time::HiRes::time() if($DEBUG > 2);
255 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): " . $t5 . ": call JSON::decode_json()\n" if($DEBUG > 2);
256  
257 my $response_r;
258 eval{
259 $response_r = JSON::decode_json($response_content);
260 };
261 if($@){
262 print STDERR scalar(localtime()) . ": error: IPCamera::Reolink::_sendCameraCommand($camera_command): JSON::decode_json() failed - '$@' - responseContent '$response_content'\n";
263 return undef;
264 } # if
265  
266 my $t6 = Time::HiRes::time() if($DEBUG > 1);
267 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): JSON encode " . ($t2 - $t1) . " POST " . ($t3 - $t2) . " responseCode " . ($t4 - $t3) . " responseContent " . ($t5 - $t4) . " JSON decode " . ($t6 - $t5) . " TOTAL " . ($t6 - $t1) . "\n" if($DEBUG > 2);
268 if($DEBUG > 1){
269 if($DEBUG > 3){
270 my @headers = $camera_rest_client->responseHeaders();
271 foreach my $header (@headers){
272 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): header '" . $header . "' '" . $camera_rest_client->responseHeader($header) . "' \n";
273 } # for
274 } # if
275 my $save_linewidth = $Data::Dump::LINEWIDTH;
276 $Data::Dump::LINEWIDTH = 500; # no linebreak
277 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): command '" . $camera_command . "' token '" . (defined($token) ? $token : 'undef') . "' request '" . Dumper($request_r) . "' response '" . Dumper($response_r) . "' time " . ($t6 - $t1) . " seconds\n";
278 $Data::Dump::LINEWIDTH = $save_linewidth;
279 } # if
280  
281 my $code = @$response_r[0]->{code};
282 if($response_code ne '200' || $code != 0){
283 print STDERR scalar(localtime()) . ": error: IPCamera::Reolink::_sendCameraCommand($camera_command): exit ERROR: response_code '$response_code ' code '$code'\n" if($DEBUG > 2);
284 return undef;
285 }else{
286 print STDERR scalar(localtime()) . ": debug: IPCamera::Reolink::_sendCameraCommand($camera_command): exit OK response_code '$response_code ' code '$code'\n" if($DEBUG > 2);
287 return $response_r;
288 } # if
289 } # if
290 } # _sendCameraCommand()
291  
292 # _checkLoginLeaseTime() - determine if camera Login lease for Login token has expired and reacquire on expiry
293 sub _checkLoginLeaseTime($){
294 my($self) = @_;
295 my $now = time();
296 my($_camera_login_lease_time, $_camera_login_lease_start_time) = ($self->{_camera_login_lease_time}, $self->{_camera_login_lease_start_time});
297 if($now >= $_camera_login_lease_start_time + $_camera_login_lease_time){
298 # Perhaps re-establish the REST connection as long intervals with no activity seem to make the camera "forget" the connection. @@@
299 my($login_token, $login_lease_time) = Login();
300 if(defined($login_token)){
301 $self->{_camera_login_lease_start_time} = $now; # New Login token lease time
302 $self->{_camera_login_lease_time} = $login_lease_time; # New Login token
303 return 1; # new Login token
304 }else{
305 return 0; # failed to acquire new Login token
306 } # if
307 }else{
308 return 1; # Login token still valid
309 } # if
310 } # _checkLoginLeaseTime()
311  
312 # Login() - provides login credentials (username/password) to camera and returns API access token good for specified number of seconds
313 sub Login(){
314 my($self) = @_;
315 my($_camera_rest_client, $camera_url, $camera_user_name, $camera_password, $camera_X509_certificate_file, $camera_X509_key_file, $camera_certificate_authority_file, $_is_https) = ($self->{_camera_rest_client}, $self->{camera_url}, $self->{camera_user_name}, $self->{camera_password}, $self->{camera_x509_certificate_file}, $self->{camera_x509_key_file}, $self->{camera_certificate_authority_file}, $self->{_is_https}, );
316 if(!defined($_camera_rest_client)){
317 # disable check for valid certificate matching the expected hostname
318 $_camera_rest_client = REST::Client->new(host => $camera_url, timeout => 10, cert => $camera_X509_certificate_file, key => $camera_X509_key_file, ca => $camera_certificate_authority_file);
319 $_camera_rest_client->getUseragent()->ssl_opts(verify_hostname => 0);
320 $_camera_rest_client->getUseragent()->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE);
321 $self->{_camera_rest_client} = $_camera_rest_client;
322 } # if
323 my $login_r = [ {cmd => "Login", param => { User => { Version => "0", userName => $camera_user_name, password => $camera_password, }}} ];
324 my $response_r = _sendCameraCommand($_camera_rest_client, 'Login', $login_r, undef);
325 if(defined($response_r)){
326 $self->{_camera_login_token} = @$response_r[0]->{value}->{Token}->{name};
327 $self->{_camera_login_lease_time} = @$response_r[0]->{value}->{Token}->{leaseTime};
328 $self->{_camera_login_lease_start_time} = time(); # detect lease expiry
329 print STDERR scalar(localtime()) . ": info: Camera Login for user '" . $self->{camera_user_name} . "' OK, token leaseTime '" . $self->{_camera_login_lease_time} . "' name '" . $self->{_camera_login_token} . "'\n" if($DEBUG > 0);
330 return ($self->{_camera_login_token}, $self->{_camera_login_lease_time});
331 }else{
332 print STDERR scalar(localtime()) . ": error: Camera Login for user '" . $self->{camera_user_name} . "' failed\n" if($DEBUG > 0);
333 return (undef, undef);
334 } # if
335 } # Login()
336  
337 # Logout() - release login credentials from previous Login()
338 sub Logout(){
339 my($self) = @_;
340 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
341 if(defined($_camera_rest_client)){
342 $self->{_camera_login_token} = undef;
343 $self->{_camera_login_lease_time} = 0;
344 $self->{_camera_login_lease_start_time} = time();
345 }else{
346 # No Login()
347 return 0;
348 } # if
349 my $logout_r = [ {cmd => "Logout", param => { }} ];
350 my $response_r = _sendCameraCommand($_camera_rest_client, 'Logout', $logout_r, $_camera_login_token);
351 $self->{_camera_rest_client} = undef; # hopefully drops the REST connection
352 if(defined($response_r)){
353 return 1;
354 }else{
355 return 0;
356 } # if
357 } # Logout()
358  
359 # GetChannelstatus() - implement camera API GetChannelstatus interface.
360 sub GetChannelstatus($){
361 my($self) = @_;
362 if(!_checkLoginLeaseTime($self)){
363 return (undef, undef);
364 } # if
365 my $get_channelstatus_r = [ {cmd => "GetChannelstatus", } ];
366 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
367 my $response_r = _sendCameraCommand($_camera_rest_client, 'GetChannelstatus', $get_channelstatus_r, $_camera_login_token);
368 if(defined($response_r)){
369 return (@$response_r[0]->{value}->{count}, @$response_r[0]->{value}->{status});
370 }else{
371 return (undef, undef);
372 } # if
373 } # GetChannelstatus()
374  
375 # GetDevInfo() - implement camera API GetDevInfo interface.
376 sub GetDevInfo($){
377 my($self) = @_;
378 if(!_checkLoginLeaseTime($self)){
379 return undef;
380 } # if
381 my $get_dev_info_r = [ {cmd => "GetDevInfo", } ];
382 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
383 my $response_r = _sendCameraCommand($_camera_rest_client, 'GetDevInfo', $get_dev_info_r, $_camera_login_token);
384 if(defined($response_r)){
385 return @$response_r[0]->{value}->{DevInfo};
386 }else{
387 return undef;
388 } # if
389 } # GetDevInfo()
390  
391 # PtzCtrl() - implement camera API PtzCtrl interface, used to control the operation of PTZ (Pan/Tilt/Zoom).
392 sub PtzCtrl($$$$;$){
393 my($self, $channel, $op, $speed, $preset_id) = @_;
394 if(!_checkLoginLeaseTime($self)){
395 return 0;
396 } # if
397 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
398 # speed : 1 (lent) -> 64 (rapide)
399 my $ptzctrl_r;
400 if($op eq PTZ_Stop){
401 # No 'speed' field for op PTZ_Stop
402 $ptzctrl_r = [ {cmd => "PtzCtrl", action => 0, param => { channel => int($channel), op => $op, }}];
403 }elsif($op eq PTZ_ToPos){
404 # Preset id field for op PTZ_ToPos
405 $ptzctrl_r = [ {cmd => "PtzCtrl", action => 0, param => { channel => int($channel), speed => int($speed), op => $op, id => int($preset_id) }}]; # the int($speed) and int($preset_id) is important otherwise the field could be encoded as a real which will be rejected by the camera
406 }else{
407 $ptzctrl_r = [ {cmd => "PtzCtrl", action => 0, param => { channel => int($channel), speed => int($speed), op => $op, }}]; # the int($speed) is important otherwise the field could be encoded as a real which will be rejected by the camera
408 } # if
409 my $response_r = _sendCameraCommand($_camera_rest_client, 'PtzCtrl', $ptzctrl_r, $_camera_login_token);
410 if(defined($response_r)){
411 return 1;
412 }else{
413 return 0;
414 } # if
415 } # PtzCtrl()
416  
417 # GetZoomFocus() - implement camera API GetZoomFocus interface, used to get the current Zoom and Focus values.
418 sub GetZoomFocus($){
419 my($self, $channel) = @_;
420 if(!_checkLoginLeaseTime($self)){
421 return undef;
422 } # if
423 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
424 my $getzoomfocus_r = [ {cmd => "GetZoomFocus", action => 0, param => { channel => int($channel), }} ];
425 my $response_r = _sendCameraCommand($_camera_rest_client, 'GetZoomFocus', $getzoomfocus_r, $_camera_login_token);
426 if(defined($response_r)){
427 return @$response_r[0]->{value}->{ZoomFocus};
428 }else{
429 return undef;
430 } # if
431 } # GetZoomFocus()
432  
433 # StartZoomFocus() - implement camera API StartZoomFocus interface, used to set the Zoom and Focus to specified values.
434 sub StartZoomFocus($$$){
435 my($self, $channel, $op, $pos) = @_;
436 if(!_checkLoginLeaseTime($self)){
437 return 0;
438 } # if
439 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
440 my $startzoomfocus_r = [ {cmd => "StartZoomFocus", action => 0, param => {"ZoomFocus" => { channel => int($channel), pos => int($pos), op => $op, }}} ];
441 my $response_r = _sendCameraCommand($_camera_rest_client, 'StartZoomFocus', $startzoomfocus_r, $_camera_login_token);
442 if(defined($response_r)){
443 return 1;
444 }else{
445 return 0;
446 } # if
447 } # StartZoomFocus()
448  
449 # GetOsd() - implement camera API GetOsd interface, used to get the On Screen Display (OSD) values.
450 sub GetOsd($){
451 my($self, $channel) = @_;
452 if(!_checkLoginLeaseTime($self)){
453 return (undef, undef, undef);
454 } # if
455 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
456 my $getosd_r = [ {cmd => "GetOsd", action => 1, param => { channel => int($channel), }} ];
457 my $response_r = _sendCameraCommand($_camera_rest_client, 'GetOsd', $getosd_r, $_camera_login_token);
458 if(defined($response_r)){
459 return (@$response_r[0]->{value}, @$response_r[0]->{range}, @$response_r[0]->{initial}, );
460 }else{
461 return (undef, undef, undef);
462 } # if
463 } # GetOsd()
464  
465 # SetOsd() - implement camera API SetOsd interface, used to set the On Screen Display (OSD) values.
466 sub SetOsd($$$$$$){
467 my($self, $channel, $enableChannel, $channelName, $channelPos, $enableTime, $timePos) = @_;
468 if(!_checkLoginLeaseTime($self)){
469 return 0;
470 } # if
471 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
472 my $setosd_r = [ {cmd => "SetOsd", param => { Osd => { channel => int($channel), osdChannel => { enable => int($enableChannel), name => $channelName, pos => $channelPos, }, osdTime => {enable => int($enableTime), pos => $timePos, }}}} ];
473 my $response_r = _sendCameraCommand($_camera_rest_client, 'SetOsd', $setosd_r, $_camera_login_token);
474 if(defined($response_r)){
475 return 1;
476 }else{
477 return 0;
478 } # if
479 } # SetOsd()
480  
481 # GetIrLights() - implement camera API GetIrLights interface, used to get the IrLights values.
482 sub GetIrLights($){
483 my($self, $channel) = @_;
484 if(!_checkLoginLeaseTime($self)){
485 return (undef, undef, undef);
486 } # if
487 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
488 my $getirlights_r = [ {cmd => "GetIrLights", action => 1, param => { channel => int($channel), }} ];
489 my $response_r = _sendCameraCommand($_camera_rest_client, 'GetIrLights', $getirlights_r, $_camera_login_token);
490 if(defined($response_r)){
491 return (@$response_r[0]->{value}, @$response_r[0]->{range}, @$response_r[0]->{initial}, );
492 }else{
493 return (undef, undef, undef);
494 } # if
495 } # GetIrLights()
496  
497 # SetIrLights() - implement camera API SetIrLights interface, used to set the IrLights State value.
498 sub SetIrLights($$$){
499 my($self, $channel, $irlightsState) = @_;
500 if(!_checkLoginLeaseTime($self)){
501 return 0;
502 } # if
503 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
504 my $setirlights_r = [ {cmd => "SetIrLights", param => { IrLights => { channel => int($channel), state => $irlightsState, }}} ];
505 my $response_r = _sendCameraCommand($_camera_rest_client, 'SetIrLights', $setirlights_r, $_camera_login_token);
506 if(defined($response_r)){
507 return 1;
508 }else{
509 return 0;
510 } # if
511 } # SetIrLights()
512  
513 # GetPtzPreset() - implement camera API GetPtzPreset iterface, used to get configuration of Ptz Preset.
514 sub GetPtzPreset($){
515 my($self, $channel) = @_;
516 if(!_checkLoginLeaseTime($self)){
517 return (undef, undef, undef);
518 } # if
519 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
520 my $getptzpreset_r = [ {cmd => "GetPtzPreset", action => 1, param => { channel => int($channel), }} ];
521 my $response_r = _sendCameraCommand($_camera_rest_client, 'GetPtzPreset', $getptzpreset_r, $_camera_login_token);
522 if(defined($response_r)){
523 return (@$response_r[0]->{value}, @$response_r[0]->{range}, @$response_r[0]->{initial}, );
524 }else{
525 return (undef, undef, undef);
526 } # if
527 } # GetPtzPreset()
528  
529 # SetPtzPreset() - implement camera API SetPtzPreset iterface, used to set configuration of Ptz Preset.
530 sub SetPtzPreset($$$$){
531 my($self, $channel, $enable, $id, $name) = @_;
532 if(!_checkLoginLeaseTime($self)){
533 return (undef, undef, undef);
534 } # if
535 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
536 my $setptzpreset_r = [ {cmd => "SetPtzPreset", action => 0, param => { PtzPreset => { channel => int($channel), enable => int($enable), id => $id, name => $name, }}} ];
537 my $response_r = _sendCameraCommand($_camera_rest_client, 'SetPtzPreset', $setptzpreset_r, $_camera_login_token);
538 if(defined($response_r)){
539 return 1;
540 }else{
541 return 0;
542 } # if
543 } # SetPtzPreset()
544  
545 # Snap() - It is used to capture an image.
546 sub Snap($$){
547 my($self, $channel) = @_;
548 if(!_checkLoginLeaseTime($self)){
549 return undef;
550 } # if
551 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
552  
553 my $r = String::Random->new;
554 $r->{'A'} = [ 'A'..'Z', 'a'..'z', '0' .. '9', ];
555 my $rs = $r->randpattern('AAAAAAAAAAAAAAAA'); # Random character with fixed length. It’s used to prevent browser caching.
556  
557 my $snap_r = [ {cmd => "Snap", action => 1, param => { channel => int($channel), rs => $rs, }} ];
558 my $response_r = _sendCameraCommand($_camera_rest_client, 'Snap', $snap_r, $_camera_login_token); # response is not JSON but binary JPG image data for the snapshot
559 if(defined($response_r)){
560 return $response_r;
561 }else{
562 return undef;
563 } # if
564 } # Snap()
565  
566 # Reboot() - reboot the camera, on return must IPCamera::Reolink->new() to access the camera
567 sub Reboot($){
568 my($self) = @_;
569 if(!_checkLoginLeaseTime($self)){
570 return 0;
571 } # if
572 my $reboot_r = [ {cmd => "Reboot", } ];
573 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
574 my $response_r = _sendCameraCommand($_camera_rest_client, 'Reboot', $reboot_r, $_camera_login_token);
575 if(defined($response_r)){
576 return 1;
577 }else{
578 return 0;
579 } # if
580 } # Reboot()
581  
582 # AudioAlarmPlay() - play audio alarm
583 sub AudioAlarmPlay($$$$$){
584 my($self, $channel, $manual_switch, $num_times, $alarm_mode) = @_;
585 if(!_checkLoginLeaseTime($self)){
586 return 0;
587 } # if
588 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
589 my $audioalarmplay_r = [ {cmd => "AudioAlarmPlay", action => 0, param => { channel => int($channel), manual_switch => int($manual_switch), times => int($num_times), alarm_mode => $alarm_mode }} ];
590 my $response_r = _sendCameraCommand($_camera_rest_client, 'AudioAlarmPlay', $audioalarmplay_r, $_camera_login_token);
591 if(defined($response_r)){
592 return 1;
593 }else{
594 return 0;
595 } # if
596 } # AudioAlarmPlay()
597  
598 # SetWhiteLed() - set configuration of white led (spot light)
599 sub SetWhiteLed($$$$$$$){
600 my($self, $channel, $state, $mode, $bright, $lighting_schedule_r, $ai_detect_type_r) = @_;
601 if(!_checkLoginLeaseTime($self)){
602 return 0;
603 } # if
604 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
605 #my $setwhiteled_r = [ {cmd => "SetWhiteLed", param => { WhiteLed => { channel => int($channel), state => int($state), mode => int($mode), bright => int($bright), }}} ];
606 my $setwhiteled_r = [ {cmd => "SetWhiteLed", param => { WhiteLed => { channel => int($channel), }}} ];
607 if(defined($state)){
608 ${$setwhiteled_r->[0]->{param}->{WhiteLed}}{state} = int($state);
609 } # if
610 if(defined($mode)){
611 ${$setwhiteled_r->[0]->{param}->{WhiteLed}}{mode} = int($mode);
612 } # if
613 if(defined($bright)){
614 ${$setwhiteled_r->[0]->{param}->{WhiteLed}}{bright} = int($bright);
615 } # if
616 if(defined($lighting_schedule_r)){
617 ${$setwhiteled_r->[0]->{param}->{WhiteLed}}{LightingSchedule} = $lighting_schedule_r;
618 } # if
619 if(defined($ai_detect_type_r)){
620 ${$setwhiteled_r->[0]->{param}->{WhiteLed}}{wlAiDetectType} = $ai_detect_type_r;
621 } # if
622 my $response_r = _sendCameraCommand($_camera_rest_client, 'SetWhiteLed', $setwhiteled_r, $_camera_login_token);
623 if(defined($response_r)){
624 return 1;
625 }else{
626 return 0;
627 } # if
628 } # SetWhiteLed()
629  
630 # GetWhiteLed() - get configuration of white led (spot light)
631 sub GetWhiteLed($$){
632 my($self, $channel) = @_;
633 if(!_checkLoginLeaseTime($self)){
634 return 0;
635 } # if
636 my($_camera_rest_client, $_camera_login_token) = ($self->{_camera_rest_client}, $self->{_camera_login_token});
637 my $getwhiteled_r = [ {cmd => "GetWhiteLed", action => 0, param => { channel => int($channel), }} ];
638 my $response_r = _sendCameraCommand($_camera_rest_client, 'GetWhiteLed', $getwhiteled_r, $_camera_login_token);
639 if(defined($response_r)){
640 return (@$response_r[0]->{value}, @$response_r[0]->{range}, @$response_r[0]->{initial}, );
641 }else{
642 return (undef, undef, undef);
643 } # if
644 } # GetWhiteLed()
645  
646 =pod
647  
648 =encoding UTF-8
649  
650 =head1 NAME
651  
652 IPCamera::Reolink - Reolink API provides access to the System, Security, Network, Video input, Enc, Record, PTZ, and Alarm functions of a Reolink IP Camera or NVR via HTTP(S)/REST
653  
654 =head1 VERSION
655  
656 1.10
657  
658 =head1 SYNOPSIS
659  
660 use IPCamera::Reolink;
661  
662 my $camera_url = "http://192.168.1.160";
663 my $camera_user_name = "vlc"; # non-admin user recommended
664 my $camera_password = 'this-is-a-bad-password';
665  
666 my $camera = IPCamera::Reolink->new($camera_url, $camera_user_name, $camera_password);
667 # or
668 # my $camera = IPCamera::Reolink->new( {camera_url => $camera_url_http, camera_user_name => $camera_user_name, camera_password => $camera_password, camera_x509_certificate_file => undef, camera_x509_key_file => undef, camera_certificate_authority_file => undef, })
669  
670 # Optionally Login to the camera immmediately to validate the camera URL and credentials, otherwise a Login will be implicitly performed by the API on the first camera command.
671  
672 die "IPCamera::Reolink::Login failed" if(!$camera->Login());
673  
674 # Some camera info
675  
676 my $devinfo_r = $camera->GetDevInfo();
677 print "Camera model : " . $devinfo_r->{model} . "\n";
678 print "Camera name : " . $devinfo_r->{name} . "\n";
679  
680 # Camera presets
681  
682 my($ptzpreset_value_r, $ptzpreset_range_r, $ptzpreset_initial_r) = $camera->GetPtzPreset(IPCamera::Reolink::ChannelDefault);
683 my $ptzpresets_r = $ptzpreset_value_r->{PtzPreset};
684 foreach my $ptzpreset (@$ptzpresets_r){
685 my $enable = $ptzpreset->{enable};
686 if($enable){
687 my $preset_id = $ptzpreset->{id};
688 $camera->PtzCtrl(IPCamera::Reolink::ChannelDefault, IPCamera::Reolink::PTZ_ToPos, IPCamera::Reolink::PTZ_SpeedMax, $preset_id);
689 } # if
690 } # foreach
691  
692 # Start a camera pan to the left.
693  
694 $camera->PtzCtrl(IPCamera::Reolink::ChannelDefault, IPCamera::Reolink::PTZ_Left, IPCamera::Reolink::PTZ_SpeedMax);
695  
696 # Times passes, stop the last camera PTZ function.
697  
698 $camera->PtzCtrl(IPCamera::Reolink::ChannelDefault, IPCamera::Reolink::PTZ_Stop, IPCamera::Reolink::PTZ_SpeedMin);
699  
700 # Camera snapshot
701
702 my $jpg_image_data = $camera->Snap(IPCamera::Reolink::ChannelDefault);
703 die "IPCamera::Reolink::Snap() failed\n" if(!defined($jpg_image_data));
704  
705 my $now = time();
706 my($sec, $min, $hour, $dd, $mon, $yr, $wday, $yday, $isdst) = localtime($now);
707 ($dd < 10) && ($dd = "0" . $dd);
708 my $mm = $mon + 1;
709 ($mm < 10) && ($mm = "0" . $mm);
710 ($hour < 10) && ($hour = "0" . $hour);
711 my $yyyy = $yr + 1900;
712  
713 my $file_name = sprintf("%04d%02d%02d-%2s%02d%02d.jpg", $yyyy, $mm, $dd, $hour, $min, $sec);
714 my $fh;
715 open $fh, ">$file_name" || die("open($file_name) failed - $!");
716 my $l = length($jpg_image_data);
717 (syswrite($fh, $jpg_image_data, $l) == $l) || die("syswrite($file_name, $l) failed - $!\n");
718 close($fh);
719  
720 # Play Audio Alarm 1 time
721
722 my $r = $camera->AudioAlarmPlay(IPCamera::Reolink::ChannelDefault, 0, 1, IPCamera::Reolink::AAP_AlarmModeTimes);
723  
724 # Turn the spotlight on.
725
726 $camera->SetWhiteLed(IPCamera::Reolink::ChannelDefault, IPCamera::Reolink::WhiteLed_StateOn, undef, undef, undef, undef);
727  
728 # Turn the spotlight off.
729
730 $camera->SetWhiteLed(IPCamera::Reolink::ChannelDefault, IPCamera::Reolink::WhiteLed_StateOff, undef, undef, undef, undef);
731  
732 # Set the spotlight brightness to maximum.
733
734 my $whiteled_bright = IPCamera::Reolink::WhiteLed_BrightMax;
735 $camera->SetWhiteLed(IPCamera::Reolink::ChannelDefault, undef, undef, $whiteled_bright, undef, undef);
736  
737 # Get the spotlight values.
738
739 my ($whiteled_value_r, $whiteled_range_r, $whiteled_initial_r) = $camera->GetWhiteLed(IPCamera::Reolink::ChannelDefault);
740 die "IPCamera::Reolink::GetWhiteLed() failed\n" if(!defined($whiteled_value_r));
741 print STDERR "White Led Value: bright=" . $whiteled_value_r->{WhiteLed}->{bright};
742 print STDERR "White Led Value: mode=" . $whiteled_value_r->{WhiteLed}->{mode};
743 print STDERR "White Led Value: state=" . $whiteled_value_r->{WhiteLed}->{state};
744 print STDERR "White Led Value: LightingSchedule: StartHour=" . $whiteled_value_r->{WhiteLed}->{LightingSchedule}->{StartHour}, 0);
745  
746 # Current IR leds state
747  
748 my($irlights_value_r, $irlights_range_r, $irlights_initial_r) = $camera->GetIrLights(IPCamera::Reolink::ChannelDefault);
749 die "IPCamera::Reolink::GetIrLights() failed\n" if(!defined($irlights_value_r));
750 my $irlights_state = $irlights_value_r->{IrLights}->{state};
751 print STDERR "IrLights State Value: " . $irlights_state;
752  
753 # Set IR leds state to auto, IR lights will automatically turn on in dim light and turn off when there is sufficient lighting.
754
755 die "IPCamera::Reolink::SetIrLights() failed\n" if(!$camera->SetIrLights(IPCamera::Reolink::ChannelDefault, IPCamera::Reolink::IrLights_State_Auto));
756  
757 # Logout of camera
758  
759 $camera->Logout();
760  
761 =head1 DESCRIPTION
762  
763 IPCamera::Reolink provides a simple way to interact with Reolink IP cameras and NVRs via the device HTTP(S)/REST interface.
764  
765 Based on the "Reolink Camera API User Guide_V8 (Updated in April 2023)" document, available here:
766  
767 https://github.com/mnpg/Reolink_api_documentations
768  
769  
770 As the author is primarily interested in accessing the Pan/Tilt/Zoom (PTZ) functions of his Reolink RLC-823S2 IP camera,
771 a subset of functions described in the above document needed to access these features have been implemented as well as some non PTZ functions.
772  
773 Other cameras tested include the RLC-1240A and Duo 3 PoE, the non PTZ functions all work.
774  
775  
776 Other functions may be added in the future based on the need/whims of the author and requests from other (if any) users of this module.
777  
778 =head1 ATTRIBUTES
779  
780 =head2 DEBUG
781  
782 Set I<$IPCamera::Reolink::DEBUG> to a value > 0 for increasingly detailed debug output to STDERR.
783  
784 default is 0 for no debug output.
785  
786 =over 4
787  
788 =item DEBUG = 0
789  
790 No debug output
791  
792 =item DEBUG = 1
793  
794 Log camera REST/JSON requests and responses.
795  
796 =item DEBUG = 2
797  
798 Log camera REST/JSON request and response times.
799  
800 =back
801  
802 =head2 VERSION
803  
804 I<$IPCamera::Reolink::VERSION> is the version of this module.
805  
806 =head2 IPCamera::Reolink::ChannelDefault
807  
808 I<IPCamera::Reolink::ChannelDefault> is the default Reolink channel (0).
809  
810 =head2 IPCamera::Reolink::PtzCtrl() op values.
811  
812 =over 4
813  
814 =item IPCamera::Reolink::PTZ_Stop
815  
816 PTZ stop turning.
817  
818 =item IPCamera::Reolink::PTZ_Left
819  
820 PTZ turn left at the specified speed.
821  
822 =item IPCamera::Reolink::PTZ_Right
823  
824 PTZ turn right at the specified speed.
825  
826 =item IPCamera::Reolink::PTZ_Up
827  
828 PTZ turn up in the specified speed.
829  
830 =item IPCamera::Reolink::PTZ_Down
831  
832 PTZ turn down at the specified speed.
833  
834 =item IPCamera::Reolink::PTZ_LeftUp
835  
836 PTZ turn left-up at the specified speed.
837  
838 =item IPCamera::Reolink::PTZ_LeftDown
839  
840 PTZ turn left-down at the specified speed.
841  
842 =item IPCamera::Reolink::PTZ_RightUp
843  
844 PTZ turn right-up at the specified speed.
845  
846 =item IPCamera::Reolink::PTZ_RightDown
847  
848 PTZ turn right-down at the specified speed.
849  
850 =item IPCamera::Reolink::PTZ_IrisDec
851  
852 Iris shrink at the specified speed.
853  
854 =item IPCamera::Reolink::PTZ_IrisInc
855  
856 Iris enlarge at the specified speed.
857  
858 =item IPCamera::Reolink::PTZ_ZoomDec
859  
860 Zoom in at the specified speed.
861  
862 =item IPCamera::Reolink::PTZ_ZoomInc
863  
864 Zoom out at the specified speed.
865  
866 =item IPCamera::Reolink::PTZ_FocusDec
867  
868 Focus backwards at the specified speed.
869  
870 =item IPCamera::Reolink::PTZ_FocusInc
871  
872 Focus forwards at the specified speed.
873  
874 =item IPCamera::Reolink::PTZ_Auto
875  
876 PTZ turn auto at the specified speed.
877  
878 =item IPCamera::Reolink::PTZ_StartPatrol
879  
880 PTZ patrol at the specified speed.
881  
882 =item IPCamera::Reolink::PTZ_StopPatrol
883  
884 PTZ stop patrol.
885  
886 =item IPCamera::Reolink::PTZ_ToPos
887  
888 PTZ turn to the specified preset at the specified speed.
889  
890 =back
891  
892 =head2 IPCamera::Reolink::PtzCtrl() speed values.
893  
894 =over 4
895  
896 =item IPCamera::Reolink::PTZ_SpeedMin => 1;
897  
898 =item IPCamera::Reolink::PTZ_SpeedMax => 64;
899  
900 =item IPCamera::Reolink::PTZ_SpeedHalf => 32;
901  
902 =back
903  
904 =head2 IPCamera::Reolink::PtzCtrl() preset values.
905  
906 =over 4
907  
908 =item IPCamera::Reolink::PTZ_PresetMin => 0;
909  
910 =item IPCamera::Reolink::PTZ_PresetMax => 63;
911  
912 =back
913  
914 =head2 IPCamera::Reolink::StartZoomFocus() op ZoomPos values.
915  
916 =over 4
917  
918 =item IPCamera::Reolink::ZF_ZoomPosMin => 0;
919  
920 =item IPCamera::Reolink::ZF_ZoomPosMax => 32;
921  
922 =back
923  
924 =head2 IPCamera::Reolink::StartZoomFocus() op FocusPos values.
925  
926 =over 4
927  
928 =item IPCamera::Reolink::ZF_FocusPosMin => 0;
929  
930 =item IPCamera::Reolink::ZF_FocusPosMax => 248;
931  
932 =back
933  
934 =head2 IPCamera::Reolink:SetOsd() pos values.
935  
936 =over 4
937  
938 =item IPCamera::Reolink::OSD_UpperLeft => "Upper Left";
939  
940 =item IPCamera::Reolink::OSD_TopCenter => "Top Center";
941  
942 =item IPCamera::Reolink::OSD_UpperRight => "Upper Right";
943  
944 =item IPCamera::Reolink::OSD_LowerLeft => "Lower Left";
945  
946 =item IPCamera::Reolink::OSD_BottomCenter => "Bottom Center";
947  
948 =item IPCamera::Reolink::OSD_LowerRight => "Lower Right";
949  
950 =item IPCamera::Reolink::OSD_OtherConfiguration => "Other Configuration";
951  
952 =back
953  
954 =head2 IPCamera::Reolink::AudioAlarmPlay() alarm_mode values.
955  
956 =over 4
957  
958 =item AAP_AlarmModeTimes => "times";
959  
960 play # times specified by times
961  
962 =item AAP_AlarmModeManual => "manu";
963  
964 play continuously until next AudioAlarmPlay command
965  
966 =back
967  
968 =head2 IPCamera::Reolink::SetWhiteLed() state values.
969  
970 =over 4
971  
972 =item WhiteLed_StateOff => 0;
973  
974 White Led off.
975  
976 =item WhiteLed_StateOn => 1;
977  
978 White Led off.
979  
980 =back
981  
982 =head2 IPCamera::Reolink::SetWhiteLed() mode values.
983  
984 =over 4
985  
986 =item IPCamera::Reolink::WhiteLed_ModeOff => 0;
987  
988 White Led always light at night.
989  
990 =item IPCamera::Reolink::WhiteLed_ModeNightSmart => 1;
991  
992 White led alarm trigger mode
993  
994 =item IPCamera::Reolink::WhiteLed_ModeTimer => 3;
995  
996 White led light on for specific periods
997  
998 =back
999  
1000 =head2 IPCamera::Reolink::SetPtzPreset() maximum length of preset name.
1001  
1002 =over 4
1003  
1004 =item PTZ_PresetMaxNameLength => 31;
1005  
1006 IPCamera::Reolink::SetPtzPrest() maximum length of preset name.
1007  
1008 =back
1009  
1010 =head2 IPCamera::Reolink::GetIrLights() and IPCamera::Reolink::SetIrLights() IrLights_State values
1011  
1012 =over 4
1013  
1014 =item IrLights_State_Auto => "Auto";
1015  
1016 I<$IPCamera::Reolink::IrLights_State_Auto> IR lights will automatically turn on in dim light and turn off when there is sufficient lighting.
1017  
1018 =item IrLights_State_Off => "Off";
1019  
1020 I<$IPCamera::Reolink::IrLights_State_Off> IR lights will stay off
1021  
1022 =item IrLights_State_On => "On";
1023  
1024 I<$IPCamera::Reolink::IrLights_State_On> IR lights will stay on
1025  
1026 =back
1027  
1028 =head2 PTZ_op_list
1029  
1030 I<$IPCamera::Reolink::PTZ_op_list> is the IPCamera::Reolink::PtzCtrl() op values as list.
1031  
1032 =head2 PTZ_speed_list
1033  
1034 I<$IPCamera::Reolink::PTZ_speed_list> is the IPCamera::Reolink::PtzCtrl() speed values as list.
1035  
1036 =head2 PTZ_preset_list
1037  
1038 I<$IPCamera::Reolink::PTZ_preset_list> is the IPCamera::Reolink::PtzCtrl() preset values as list.
1039  
1040 =head2 PTZ_ZoomPos_list
1041  
1042 I<$IPCamera::Reolink::PTZ_ZoomPos_list> is the IPCamera::Reolink::StartZoomFocus() zoom pos values as list.
1043  
1044 =head2 PTZ_FocusPos_list
1045  
1046 I<$IPCamera::Reolink::PTZ_FocusPos_list> is the IPCamera::Reolink::StartZoomFocus() focus pos values as list.
1047  
1048 =head2 OSD_pos_list
1049  
1050 I<$IPCamera::Reolink::OSD_pos_list> is the IPCamera::Reolink::SetOsd() pos values as list.
1051  
1052 =head2 AAP_AlarmMode_list
1053  
1054 I<IPCamera::Reolink::AAP_AlarmMode_list> is the IPCamera::Reolink::AudioAlarmPlay() alarm_mode values as list.
1055  
1056 =head2 IrLights_State_list
1057  
1058 I<$IPCamera::Reolink::IrLights_State_list> is the IPCamera::Reolink::GetIrLights() and IPCamera::Reolink::SetIrLights() IrLights_State values as list.
1059  
1060 =head1 METHODS
1061  
1062 =head2 new({camera_url => "http://192.168.1.99/", camera_user_name => "admin", camera_password => "password", camera_x509_certificate_file => undef, camera_x509_key_file => undef, camera_certificate_authority_file => undef, })
1063  
1064 Hash reference version.
1065  
1066 See below for details.
1067  
1068 =head2 new($camera_url, $camera_user_name, $camera_password)
1069  
1070 Construct a new IPCamera::Reolink object.
1071  
1072 Takes the following manditory parameters:
1073  
1074 =over 4
1075  
1076 =item $camera_url
1077  
1078 The camera URL for access via HTTP(S), i.e. "http://192.168.1.123".
1079  
1080 =item $camera_user_name
1081  
1082 The camera account name for access via HTTP(S), i.e. "vlc".
1083  
1084 You should set up a non admin acccount for access via this API, the admin account will work as well but is not recommended.
1085  
1086 But just to complicate things, certain methods (described below) require admin access to use with the current version of the camera firmware.
1087  
1088 Reolink may fix this in the future.
1089  
1090 =item $camera_password
1091  
1092 The camera account password for access via HTTP(S), i.e. "this-is-a-bad-password".
1093  
1094 =item $camera_x509_certificate_file
1095  
1096 TBD.
1097  
1098 =item $camera_x509_key_file
1099  
1100 TBD.
1101  
1102 =item $camera_x509_authority_file
1103  
1104 TBD.
1105  
1106 =back
1107  
1108 =head2 Login()
1109  
1110 Login to the camera using the credentials provided to new() (above).
1111  
1112 Upon successful Login the camera passes back a Login token and lease time that are used internally by other IPCamera::Reolink camera API methods.
1113  
1114 The token is valid for the specified lease time.
1115  
1116 IPCamera::Reolink will manage the Login token and will call Login() internally as needed when the Login token expires.
1117  
1118 This should all be invisible to the caller.
1119  
1120 =over 4
1121  
1122 =item return
1123  
1124 Returns (undef, undef) if the Login was rejected by the camera.
1125  
1126 Returns ($camera_login_token, $camera_login_lease_time) if the Login is successful,
1127 where $camera_login_token is the token passed to other API methods and $camera_login_lease_time is the time in seconds for which the token is valid, after which a new token must be aquired.
1128  
1129 Usually the caller is not interested in these values as they are used internally by IPCamera::Reolink.
1130  
1131 =back
1132  
1133 =head2 Logout()
1134  
1135 Release Login() credentials.
1136  
1137 =over 4
1138  
1139 =item return
1140  
1141 Returns 1 if Logout() succeeded else 0 (zero) on failure, typically if Login() not called.
1142  
1143 =back
1144  
1145 =head2 GetChannelstatus()
1146  
1147 Return camera/NVR per channel status.
1148  
1149 =over 4
1150  
1151 =item return
1152  
1153 Returns ($count, $status_r) if GetChannelstatus() succeeded.
1154  
1155 =over 4
1156  
1157 =item $count
1158  
1159 The number of channels in the camera/NVR, typically 1 for a camera.
1160  
1161 The number of elements in the I<@status> array.
1162  
1163 =item $status_r
1164  
1165 reference to Per channel status array with I<$count> elements.
1166  
1167 =over 4
1168  
1169 =item $statu_r->[$i]->{channel} (0)
1170  
1171 Channel index, 0 < $i < $count.
1172  
1173 =item $status_r->[$i]->{name} ("CAM1")
1174  
1175 Channel name.
1176  
1177 =item $status_r->[$i]->{online} (1)
1178  
1179 0 if channel offline, 1 if channel online.
1180  
1181 =item $status_r->[$i]->{typeInfo} ("CAM1")
1182  
1183 Channel description.
1184  
1185 =back
1186  
1187 =back
1188  
1189 Returns (undef, undef) if GetChannelstatus() failed.
1190  
1191 =back
1192  
1193 =head2 GetDevInfo()
1194  
1195 Return useful information about the camera.
1196  
1197 =over 4
1198  
1199 =item return
1200  
1201 Returns undef if the GetDevInfo function failed.
1202  
1203 Returns $devinfo_r hash reference to device information if successful, fields most likely subject to change (typical values in parenthesis):
1204  
1205 =over 4
1206  
1207 =item $devinfo_r->{audioNum} (1)
1208  
1209 The number of audio channels.
1210  
1211 =item $devinfo_r->{B485} (0)
1212  
1213 0: no 485, 1: have 485
1214  
1215 =item $devinfo_r->{buildDay} ("build 23061923")
1216  
1217 The establish date.
1218  
1219 =item $devinfo_r->{cfgVer} ("v3.1.0.0")
1220  
1221 The version number of configuration information.
1222  
1223 =item $devinfo_r->{channelNum} (1)
1224  
1225 The number of channels.
1226  
1227 =item $devinfo_r->{detail} ("IPC_523SD10S16E1W01100000001")
1228  
1229 The details of device information.
1230  
1231 =item $devinfo_r->{diskNum} (1)
1232  
1233 The number of USB disk or SD card.
1234  
1235 =item $devinfo_r->{exactType} ("IPC")
1236  
1237 Product type.
1238  
1239 =item $devinfo_r->{firmVer} ("v3.1.0.2347_23061923_v1.0.0.93")
1240  
1241 The version number of the firmware.
1242  
1243 =item $devinfo_r->{frameworkVer} (1)
1244  
1245 Architecture version.
1246  
1247 =item $devinfo_r->{hardVer} ("IPC_523SD10")
1248  
1249 The version number of the hardware.
1250  
1251 =item $devinfo_r->{IOInputNum} (0)
1252  
1253 The number of IO input port.
1254  
1255 =item $devinfo_r->{IOOutputNum} (0)
1256  
1257 The number of IO output port.
1258  
1259 =item $devinfo_r->{model} ("RLC-823A 16X")
1260  
1261 Camera/NVR model.
1262  
1263 =item $devinfo_r->{name} ("rlc-823a-16x")
1264  
1265 Device name.
1266  
1267 =item $devinfo_r->{pakSuffix} ("pak,paks")
1268  
1269 ?
1270  
1271 =item $devinfo_r->{serial} ("00000000000000")
1272  
1273 ?
1274  
1275 =item $devinfo_r->{type} ("IPC")
1276  
1277 Device type, "IPC" for IP camera or "NVR" for network video recorder.
1278  
1279 =item $devinfo_r->{wifi} (0)
1280  
1281 0: no WIFI, 1: have WIFI.
1282  
1283 =back
1284  
1285 =back
1286  
1287 =head2 PtzCtrl($camera_channel, $camera_operation, $camera_operation_speed, $camera_preset_id)
1288  
1289 Control camera PTZ functions.
1290  
1291 Upon successful return the camera asynchronously executes the requested operation until another operation is specified by PtzCtrl() or until the camera limit is reached for the specified operation, for example the camera has tilted as far Down as physically possible.
1292  
1293 Some operations like IPCamera::Reolink::PTZ_Left will execute forever until another PtzCtrl command is executed.
1294  
1295 =over 4
1296  
1297 =item return
1298  
1299 Returns 1 if PtzCtrl() succeeded else 0 (zero) on failure, typically due to using non-admin account for admin access operations.
1300  
1301 =back
1302  
1303 =over 4
1304  
1305 =item $camera_channel
1306  
1307 Perform camera operation on specified camera channel:
1308  
1309 =over 4
1310  
1311 =item IPCamera::Reolink::ChannelDefault
1312  
1313 If you are connected to a camera then there is (usually) only 1 channel.
1314  
1315 =item integer >= 0
1316  
1317 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
1318  
1319 =back
1320  
1321 =item $camera_operation
1322  
1323 Camera operation to perform:
1324  
1325 =over 4
1326  
1327 =item IPCamera::Reolink::PTZ_Stop
1328  
1329 PTZ stop turning.
1330  
1331 =item IPCamera::Reolink::PTZ_Left
1332  
1333 PTZ turn left at the specified speed.
1334  
1335 =item IPCamera::Reolink::PTZ_Right
1336  
1337 PTZ turn right at the specified speed.
1338  
1339 =item IPCamera::Reolink::PTZ_Up
1340  
1341 PTZ turn up in the specified speed.
1342  
1343 =item IPCamera::Reolink::PTZ_Down
1344  
1345 PTZ turn down at the specified speed.
1346  
1347 =item IPCamera::Reolink::PTZ_LeftUp
1348  
1349 PTZ turn left-up at the specified speed.
1350  
1351 =item IPCamera::Reolink::PTZ_LeftDown
1352  
1353 PTZ turn left-down at the specified speed.
1354  
1355 =item IPCamera::Reolink::PTZ_RightUp
1356  
1357 PTZ turn right-up at the specified speed.
1358  
1359 =item IPCamera::Reolink::PTZ_RightDown
1360  
1361 PTZ turn right-down at the specified speed.
1362  
1363 =item IPCamera::Reolink::PTZ_IrisDec
1364  
1365 Iris shrink at the specified speed.
1366  
1367 =item IPCamera::Reolink::PTZ_IrisInc
1368  
1369 Iris enlarge at the specified speed.
1370  
1371 =item IPCamera::Reolink::PTZ_ZoomDec
1372  
1373 Zoom in at the specified speed.
1374  
1375 =item IPCamera::Reolink::PTZ_ZoomInc
1376  
1377 Zoom out at the specified speed.
1378  
1379 =item IPCamera::Reolink::PTZ_FocusDec
1380  
1381 Focus backwards at the specified speed.
1382  
1383 =item IPCamera::Reolink::PTZ_FocusInc
1384  
1385 Focus forwards at the specified speed.
1386  
1387 =item IPCamera::Reolink::PTZ_Auto
1388  
1389 PTZ turn auto at the specified speed.
1390  
1391 =item IPCamera::Reolink::PTZ_StartPatrol
1392  
1393 PTZ patrol at the specified speed.
1394  
1395 =item IPCamera::Reolink::PTZ_StopPatrol
1396  
1397 PTZ stop patrol.
1398  
1399 =item IPCamera::Reolink::PTZ_ToPos
1400  
1401 PTZ turn to at specified preset at the specified speed.
1402  
1403 =back
1404  
1405 =item $camera_operation_speed
1406  
1407 Perform camera operation at the specified speed:
1408  
1409 =over 4
1410  
1411 =item IPCamera::Reolink::PTZ_SpeedMin
1412  
1413 Minimum camera operation speed.
1414  
1415 =item PTZ_SpeedMin::PTZ_SpeedMax
1416  
1417 Maximum camera operation speed.
1418  
1419 =item PTZ_SpeedMin::PTZ_SpeedHalf
1420  
1421 1/2 Maximum camera operation speed.
1422  
1423 =back
1424  
1425 =item $camera_preset_id
1426  
1427 Move camera to specfied camera preset, >= IPCamera::Reolink::PTZ_PresetMin, <= IPCamera::Reolink::PTZ_PresetMax.
1428  
1429 Used only for IPCamera::Reolink::PTZ_ToPos camera operation.
1430  
1431 =back
1432  
1433 =head2 GetZoomFocus($camera_channel)
1434  
1435 Return camera current Zoom and Focus values.
1436  
1437 =over 4
1438  
1439 =item $camera_channel
1440  
1441 Perform camera operation on specified camera channel:
1442  
1443 =over 4
1444  
1445 =item IPCamera::Reolink::ChannelDefault
1446  
1447 If you are connected to a camera then there is (usually) only 1 channel.
1448  
1449 =item integer >= 0
1450  
1451 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
1452  
1453 =back
1454  
1455 =item return
1456  
1457 Returns undef if the GetZoomFocus function failed.
1458  
1459 Returns $zoom_focus_r hash reference to Zoom/Focus information if successful, fields most likely subject to change (typical values in parenthesis):
1460  
1461 =over 4
1462  
1463 =item $zoom_focus_r->{channel} (0)
1464  
1465 Camera channel.
1466  
1467 =item $zoom_focus_r->{focus}->{pos} (23)
1468  
1469 Current camera focus value in the range IPCamera::Reolink::ZF_FocusPosMin, IPCamera::Reolink::ZF_FocusPosMax.
1470  
1471 =item $zoom_focus_r->{zoom}->{pos} (0)
1472  
1473 Current camera zoom value in the range IPCamera::Reolink::ZF_ZoomPosMin, IPCamera::Reolink::ZF_ZoomPosMax.
1474  
1475 =back
1476  
1477 =back
1478  
1479 =head2 StartZoomFocus($camera_channel, $camera_operation, $camera_zoom_pos|$camera_focus_pos)
1480  
1481 Set camera current Zoom or Focus value.
1482  
1483 Note that the current version of the firmware on the authors camera (Firmware Version v3.1.0.2347_23061923_v1.0.0.93) requires a Login() using admin credentials to use this function.
1484 According to Reolink this may be fixed in a future firmware version.
1485  
1486 If in doubt, set $DEBUG to 1 and if you see a log message of the form:
1487  
1488 Tue Dec 19 18:17:07 2023: debug: IPCamera::Reolink::_sendCameraCommand(): command 'StartZoomFocus' token '5b34aab0bb481ba' request '[{ action => 0, cmd => "StartZoomFocus", param => { ZoomFocus => { channel => 0, op => "ZoomPos", pos => 1 } } }]' response '[{ cmd => "StartZoomFocus", code => 1, error => { detail => "ability error", rspCode => -26 } }]' time 0.0480499267578125 seconds
1489  
1490 then you need to use admin credentials to use this function.
1491  
1492 =over 4
1493  
1494 =item return
1495  
1496 Returns 1 if StartZoomFocus() succeeded else 0 (zero) on failure.
1497  
1498 =back
1499  
1500 =over 4
1501  
1502 =item $camera_channel
1503  
1504 Perform camera operation on specified camera channel.
1505  
1506 =over 4
1507  
1508 =item IPCamera::Reolink::ChannelDefault
1509  
1510 If you are connected to a camera then there is (usually) only 1 channel.
1511  
1512 =item integer >= 0
1513  
1514 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
1515  
1516 =back
1517  
1518 =item $camera_operation
1519  
1520 Camera operation to perform.
1521  
1522 =over 4
1523  
1524 =item IPCamera::Reolink::ZF_ZoomPos
1525  
1526 Set Zoom to specified pos value.
1527  
1528 =over 4
1529  
1530 =item $camera_zoom_pos
1531  
1532 Set the camera Zoom to the specified pos value in the range:
1533  
1534 =over 4
1535  
1536 =item IPCamera::Reolink::ZF_ZoomPosMin
1537  
1538 Minimum camera zoom value.
1539  
1540 =item IPCamera::Reolink::ZF_ZoomPosMax
1541  
1542 Maximum camera zoom value.
1543  
1544 =back
1545  
1546 =back
1547  
1548 =item IPCamera::Reolink::ZF_FocusPos
1549  
1550 Set Focus to specified pos value.
1551  
1552 =over 4
1553  
1554 =item $camera_focus_pos
1555  
1556 Set the camera Focus to the specified pos value in the range:
1557  
1558 =over 4
1559  
1560 =item IPCamera::Reolink::ZF_FocusPosMin
1561  
1562 Minimum camera focus value.
1563  
1564 =item IPCamera::Reolink::ZF_FocusPosMax
1565  
1566 Maximum camera focus value.
1567  
1568 =back
1569  
1570 =back
1571  
1572 =back
1573  
1574 =back
1575  
1576 =head2 GetOsd($camera_channel)
1577  
1578 Return camera current, range and inital On Screen Display (OSD) values.
1579  
1580 =over 4
1581  
1582 =item $camera_channel
1583  
1584 Perform camera operation on specified camera channel.
1585  
1586 =over 4
1587  
1588 =item IPCamera::Reolink::ChannelDefault
1589  
1590 If you are connected to a camera then there is (usually) only 1 channel.
1591  
1592 =item integer >= 0
1593  
1594 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
1595  
1596 =back
1597  
1598 =item return
1599  
1600 Returns (undef, undef, undef) if the GetOsd function failed or ($osd_value_r, $osd_range_r, $osd_initial_r) on success, hash references to OSD current value, range and initial values information if successful, fields most likely subject to change (typical values in parenthesis):
1601  
1602 =over 4
1603  
1604 =item $osd_value_r
1605  
1606 Hash reference to current camera OSD values.
1607  
1608 =over 4
1609  
1610 =item $osd_value_r->{Osd}
1611  
1612 Current camera OSD values.
1613  
1614 =over 4
1615  
1616 =item $osd_value_r->{Osd}->{bgcolor} (0/1)
1617  
1618 Current camera OSD background color disabled (0) or enabled (1).
1619  
1620 =item $osd_value_r->{Osd}->{channel} (0)
1621  
1622 =over 4
1623  
1624 =item IPCamera::Reolink::ChannelDefault
1625  
1626 If you are connected to a camera then there is (usually) only 1 channel.
1627  
1628 =item integer >= 0
1629  
1630 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
1631  
1632 =back
1633  
1634 =item $osd_value_r->{Osd}->{osdChannel}
1635  
1636 Current OSD values for specified camera channel.
1637  
1638 =over 4
1639  
1640 =item $osd_value_r->{Osd}->{osdChannel}->{enable} (0/1)
1641  
1642 OSD enabled if 1 else disabled if 0.
1643  
1644 =item $osd_value_r->{Osd}->{osdChannel}->{name} ("rlc-823a-16x")
1645  
1646 OSD display value.
1647  
1648 =item $osd_value_r->{Osd}->{osdChannel}->{pos} ("Lower Right")
1649  
1650 OSD display position.
1651  
1652 =back
1653  
1654 =item $osd_value_r->{Osd}->{osdTime}
1655  
1656 Current OSD time display values for specified camera channel.
1657  
1658 =over 4
1659  
1660 =item $osd_value_r->{Osd}->{osdTime}->{enable} (0/1)
1661  
1662 OSD time display enabled if 1 else disabled if 0.
1663  
1664 =item $osd_value_r->{Osd}->{osdTime}->{pos} ("Lower Right")
1665  
1666 OSD time display position.
1667  
1668 =back
1669  
1670 =back
1671  
1672 =back
1673  
1674 =item $osd_range_r
1675  
1676 Hash reference to camera OSD value ranges.
1677  
1678 =over 4
1679  
1680 =item TBD
1681  
1682 =back
1683  
1684 =item $osd_initial_r
1685  
1686 Hash reference to camera OSD initial values.
1687  
1688 =over 4
1689  
1690 =item TBD
1691  
1692 =back
1693  
1694 =back
1695  
1696 =back
1697  
1698  
1699 =head2 SetOsd($camera_channel, $enableChannel, $channelName, $channelPos, $enableTime, $timePos)
1700  
1701 Set camera On Screen Display (OSD) values.
1702  
1703 Note that the current version of the firmware on the authors camera
1704 (Firmware Version v3.1.0.2347_23061923_v1.0.0.93) requires a Login()
1705 using admin credentials to use this function.
1706  
1707 =over 4
1708  
1709 =item return
1710  
1711 Returns 1 if SetOsd() succeeded else 0 (zero) on failure.
1712  
1713 =back
1714  
1715 =over 4
1716  
1717 =item $camera_channel
1718  
1719 Perform camera operation on specified camera channel.
1720  
1721 =over 4
1722  
1723 =item IPCamera::Reolink::ChannelDefault
1724  
1725 If you are connected to a camera then there is (usually) only 1 channel.
1726  
1727 =item integer >= 0
1728  
1729 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
1730  
1731 =back
1732  
1733 =item $enableChannel (0/1)
1734  
1735 1 to enable display of channelName else 0.
1736  
1737 =item $channelName ("rlc-823a-16x")
1738  
1739 Channel OSD text to display
1740  
1741 =item $channelPos (IPCamera::Reolink::OSD_UpperLeft)
1742  
1743 Channel OSD text position:
1744  
1745 =over 4
1746  
1747 =item IPCamera::Reolink::OSD_UpperLeft
1748  
1749 OSD position "Upper Left"
1750  
1751 =item IPCamera::Reolink::OSD_TopCenter
1752  
1753 OSD position "Top Center"
1754  
1755 =item IPCamera::Reolink::OSD_UpperRight
1756  
1757 OSD position "Upper Right"
1758  
1759 =item IPCamera::Reolink::OSD_LowerLeft
1760  
1761 OSD position "Lower Left"
1762  
1763 =item IPCamera::Reolink::OSD_BottomCenter
1764  
1765 OSD position "Bottom Center"
1766  
1767 =item IPCamera::Reolink::OSD_LowerRight
1768  
1769 OSD position "Lower Right"
1770  
1771 =back
1772  
1773 =item $enableTime
1774  
1775 1 to enable display of date/time else 0.
1776  
1777 =item $timePos ("Upper Left")
1778  
1779 Date/Time OSD text position:
1780  
1781 =over 4
1782  
1783 =item IPCamera::Reolink::OSD_UpperLeft
1784  
1785 OSD position "Upper Left"
1786  
1787 =item IPCamera::Reolink::OSD_TopCenter
1788  
1789 OSD position "Top Center"
1790  
1791 =item IPCamera::Reolink::OSD_UpperRight
1792  
1793 OSD position "Upper Right"
1794  
1795 =item IPCamera::Reolink::OSD_LowerLeft
1796  
1797 OSD position "Lower Left"
1798  
1799 =item IPCamera::Reolink::OSD_BottomCenter
1800  
1801 OSD position "Bottom Center"
1802  
1803 =item IPCamera::Reolink::OSD_LowerRight
1804  
1805 OSD position "Lower Right"
1806  
1807 =back
1808  
1809 =back
1810  
1811 =head2 GetIrLights($camera_channel)
1812  
1813 Return camera IrLights state value.
1814  
1815 =over 4
1816  
1817 =item $camera_channel
1818  
1819 Perform camera operation on specified camera channel.
1820  
1821 =over 4
1822  
1823 =item IPCamera::Reolink::ChannelDefault
1824  
1825 If you are connected to a camera then there is (usually) only 1 channel.
1826  
1827 =item integer >= 0
1828  
1829 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
1830  
1831 =back
1832  
1833 =item return
1834  
1835 Returns (undef, undef, undef) if the GetIrLights function failed or ($irlights_value_r, $irlights_range_r, $irlights_initial_r) on success, hash references to IrLights current value, range and initial values information if successful, fields most likely subject to change (typical values in parenthesis):
1836  
1837 =over 4
1838  
1839 =item $irlights_value_r
1840  
1841 Hash reference to current camera IrLights values.
1842  
1843 =over 4
1844  
1845 =item $irlights_value_r->{IrLights}
1846  
1847 Current camera IrLights values.
1848  
1849 =over 4
1850  
1851 =item $irlights_value_r->{IrLights}->{state} ("Auto", Off", "On")
1852  
1853 Current camera IrLights state value ("Auto", Off", "On")
1854  
1855 =item $irlights_value_r->{IrLights}->{channel} (0)
1856  
1857 =over 4
1858  
1859 =item IPCamera::Reolink::ChannelDefault
1860  
1861 If you are connected to a camera then there is (usually) only 1 channel.
1862  
1863 =item integer >= 0
1864  
1865 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
1866  
1867 =back
1868  
1869 =item $irlights_range_r
1870  
1871 Hash reference to camera IrLights value ranges.
1872  
1873 =over 4
1874  
1875 =item TBD
1876  
1877 =back
1878  
1879 =item $irlights_initial_r
1880  
1881 Hash reference to camera IrLights initial values.
1882  
1883 =over 4
1884  
1885 =item TBD
1886  
1887 =back
1888  
1889 =back
1890  
1891 =back
1892  
1893 =back
1894  
1895 =back
1896  
1897 =head2 SetIrLights($camera_channel, $irlights_state)
1898  
1899 Return camera IrLights state value.
1900  
1901 =over 4
1902  
1903 =item $camera_channel
1904  
1905 Perform camera operation on specified camera channel.
1906  
1907 =over 4
1908  
1909 =item IPCamera::Reolink::ChannelDefault
1910  
1911 If you are connected to a camera then there is (usually) only 1 channel.
1912  
1913 =item integer >= 0
1914  
1915 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
1916  
1917 =back
1918  
1919 =item $irlights_state
1920  
1921 =over 4
1922  
1923 =item IrLights_State_Auto => "Auto"; # IR lights will automatically turn on in dim light and turn off when there is sufficient lighting.
1924  
1925 =item IrLights_State_Off => "Off"; # IR lights will stay off
1926  
1927 =item IrLights_State_On => "On"; # IR lights will stay on
1928  
1929 =back
1930  
1931 =item return
1932  
1933 Returns 0 if the SetIrLights function failed or 1 on success.
1934  
1935 =back
1936  
1937 =head2 GetPtzPreset($camera_channel)
1938  
1939 Return camera Ptz Presets.
1940  
1941 =over 4
1942  
1943 =item $camera_channel
1944  
1945 Perform camera operation on specified camera channel.
1946  
1947 =over 4
1948  
1949 =item IPCamera::Reolink::ChannelDefault
1950  
1951 If you are connected to a camera then there is (usually) only 1 channel.
1952  
1953 =item integer >= 0
1954  
1955 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
1956  
1957 =back
1958  
1959 =item return
1960  
1961 Returns (undef, undef, undef) if the GetPtzPreset() function failed or ($ptzpreset_value_r, $ptzpreset_range_r, $ptzpreset_initial_r) on success, hash references to PTZ Presets current value, range and initial values information if successful, fields most likely subject to change (typical values in parenthesis):
1962  
1963 =over 4
1964  
1965 =item $ptzpreset_value_r
1966  
1967 Hash reference to camera PTZ Preset current values.
1968  
1969 =over 4
1970  
1971 =item $ptzpreset_value_r->{PtzPreset}
1972  
1973 List/array of current presets.
1974  
1975 =over 4
1976  
1977 =item $ptzpreset_value_r->{PtzPreset}->{channel}
1978  
1979 The camera channel as passed into GetPtzPreset() via $camera_channel.
1980  
1981 =item $ptzpreset_value_r->{PtzPreset}->{enable}
1982  
1983 Boolean, true/1 if the preset is enabled, false/0 if disabled.
1984  
1985 =item $ptzpreset_value_r->{PtzPreset}->{id}
1986  
1987 Integer preset id, 0 <= id <= 63.
1988  
1989 Passed to PtzCtrl() via $preset_id.
1990  
1991 =item $ptzpreset_value_r->{PtzPreset}->{imgName}
1992  
1993 Preset image name.
1994  
1995 =item $ptzpreset_value_r->{PtzPreset}->{name}
1996  
1997 Preset name.
1998  
1999 =back
2000  
2001 =back
2002  
2003 =item $ptzpreset_range_r
2004  
2005 Hash reference to camera PTZ Preset ranges.
2006  
2007 =item $ptzpreset_initial_r
2008  
2009 Hash reference to camera PTZ Preset initial values.
2010  
2011 =back
2012  
2013 =back
2014  
2015 =head2 SetPtzPreset($camera_channel, $enable, $id, $name)
2016  
2017 Set specified camera Ptz Preset.
2018  
2019 =over 4
2020  
2021 =item $camera_channel
2022  
2023 Perform camera operation on specified camera channel.
2024  
2025 =over 4
2026  
2027 =item IPCamera::Reolink::ChannelDefault
2028  
2029 If you are connected to a camera then there is (usually) only 1 channel.
2030  
2031 =item integer >= 0
2032  
2033 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
2034  
2035 =back
2036  
2037 =back
2038  
2039 =over 4
2040  
2041 =item $enable
2042  
2043 1 to enable the preset, 0 to disable the preset.
2044  
2045 =back
2046  
2047 =over 4
2048  
2049 =item $id
2050  
2051 Preset id, integer value in the range [PTZ_PresetMin + 1, PTZ_PresetMax +1].
2052  
2053 =back
2054  
2055 =over 4
2056  
2057 =item $name
2058  
2059 Preset name, maximum length PTZ_PresetMaxNameLength characters.
2060  
2061 =item return
2062  
2063 Returns 1 if the specified preset is set else 0.
2064  
2065 =back
2066  
2067 =head2 Snap($camera_channel)
2068  
2069 Return camera snapshot.
2070  
2071 =over 4
2072  
2073 =item $camera_channel
2074  
2075 Perform camera operation on specified camera channel.
2076  
2077 =over 4
2078  
2079 =item IPCamera::Reolink::ChannelDefault
2080  
2081 If you are connected to a camera then there is (usually) only 1 channel.
2082  
2083 =item integer >= 0
2084  
2085 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
2086  
2087 =back
2088  
2089 =item return
2090  
2091 Returns raw/binary snapshot data in JPG format or undef if the Snap() function failed.
2092  
2093 =back
2094  
2095 =head2 Reboot()
2096  
2097 Reboot the camera, on successful return must reestablish the IPCamera::Reolink session.
2098  
2099 =over 4
2100  
2101 =item return
2102  
2103 Returns 1 if the camera is rebooted else 0.
2104  
2105 Upon successful return the connection to the camera is lost and new session must be established.
2106  
2107 =back
2108  
2109 =head2 AudioAlarmPlay($camera_channel, $manual_switch, $num_times, $alarm_mode)
2110  
2111 Play audio alarm.
2112  
2113 =over
2114  
2115 =item $camera_channel
2116  
2117 Perform camera operation on specified camera channel.
2118  
2119 =over 4
2120  
2121 =item IPCamera::Reolink::ChannelDefault
2122  
2123 If you are connected to a camera then there is (usually) only 1 channel.
2124  
2125 =item integer >= 0
2126  
2127 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
2128  
2129 =back
2130  
2131 =item $manual_switch
2132  
2133 if $alarm_mode is AAP_AlarmModeManual then set tp 1 to play alarm or 0 to stop alarm.
2134  
2135 =item $num_times
2136  
2137 Number of times to play audio alarm, > 0.
2138  
2139 =item $alarm_mode
2140  
2141 IPCamera::Reolink::AudioAlarmPlay() alarm_mode values.
2142  
2143 =over 4
2144  
2145 =item AAP_AlarmModeTimes
2146  
2147 Play specified # of times.
2148  
2149 =item AAP_AlarmModeManual
2150  
2151 Play continuously until next AudioAlarmPlay command.
2152  
2153 =back
2154  
2155 =item return
2156  
2157 Returns 1 if audio alarm played else 0.
2158  
2159 =back
2160  
2161 =head2 SetWhiteLed($camera_channel, $state, $mode, $bright, $lighting_schedule_r, $ai_detect_type_r)
2162  
2163 Set the configuration of the white led (spotlight).
2164 Any of the parameters with the value undef will not be modified.
2165  
2166 =over
2167  
2168 =item $camera_channel
2169  
2170 Perform camera operation on specified camera channel.
2171  
2172 =over 4
2173  
2174 =item IPCamera::Reolink::ChannelDefault
2175  
2176 If you are connected to a camera then there is (usually) only 1 channel.
2177  
2178 =item integer >= 0
2179  
2180 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
2181  
2182 =back
2183  
2184 =item $state
2185  
2186 White led/spotlight state.
2187  
2188 =over 4
2189  
2190 =item IPCamera::Reolink::WhiteLed_StateOff
2191  
2192 White led off.
2193  
2194 =item IPCamera::Reolink::WhiteLed_StateOn
2195  
2196 White led on.
2197  
2198 =back
2199  
2200 =item $mode
2201  
2202 White led/spotlight state.
2203  
2204 =over 4
2205  
2206 =item IPCamera::Reolink::WhiteLed_ModeOff
2207  
2208 Spotlight will never be turned on.
2209  
2210 =item IPCamera::Reolink::WhiteLed_ModeNightSmart
2211  
2212 Spotlight will be turned on at night when motion is detected.
2213  
2214 =item IPCamera::Reolink::WhiteLed_ModeTimer
2215  
2216 Spotlight will be turned on per $lighting_schedule_r schedule.
2217  
2218 =back
2219  
2220 =item $bright
2221  
2222 Set spotlight brightness as an integer value between IPCamera::Reolink::WhiteLed_BrightMin and IPCamera::Reolink::WhiteLed_BrightMax.
2223  
2224 =item $lighting_schedule_r
2225  
2226 new IPCamera::Reolink::LightingSchedule($StartHour, $StartMin, $EndHour, $EndMin)
2227  
2228 =over 4
2229  
2230 =item $StartHour
2231  
2232 0 <= $StartHour < 24
2233  
2234 =item $StartMin
2235  
2236 0 <= $StartMin < 60
2237  
2238 =item $EndHour
2239  
2240 0 <= $EndHour < 24
2241  
2242 =item $EndMin
2243  
2244 0 <= $EndMin < 60
2245  
2246 =back
2247  
2248 =item $ai_detect_type_r
2249  
2250 new IPCamera::Reolink::wlAiDetectType($dog_cat, $people, $vehicle)
2251  
2252 =over 4
2253  
2254 =item $dog_cat
2255  
2256 1 to enable dog/cat (animal) detection, 0 to disable
2257  
2258 =item $people
2259  
2260 1 to enable people detection, 0 to disable
2261  
2262 =item $vehicle
2263  
2264 1 to enable vehicle detection, 0 to disable
2265  
2266 =back
2267  
2268 =item return
2269  
2270 Returns 1 if SetWhiteLed() successful else 0 on failure.
2271  
2272 =back
2273  
2274 =head2 GetWhiteLed($camera_channel)
2275  
2276 Get the configuration of the white led (spotlight)
2277  
2278 =over
2279  
2280 =item $camera_channel
2281  
2282 Perform camera operation on specified camera channel.
2283  
2284 =over 4
2285  
2286 =item IPCamera::Reolink::ChannelDefault
2287  
2288 If you are connected to a camera then there is (usually) only 1 channel.
2289  
2290 =item integer >= 0
2291  
2292 If you are connected to an NVR then there is usually one channel per attached camera starting at integer value 0.
2293  
2294 =item return
2295  
2296 Returns undef if the GetWhiteLed function failed.
2297  
2298 Returns ($whiteled_value_r, $whiteled_range_r, $whiteled_initial_r).
2299  
2300 =back
2301  
2302 =back
2303  
2304 =head1 TODO
2305  
2306 =over 4
2307  
2308 =item *
2309  
2310 Implement REST via HTTPS.
2311  
2312 =item *
2313  
2314 Camera seems to "forget" existing REST/HTTP(S) session after period of inactivity.
2315  
2316 =back
2317  
2318 =head1 AUTHOR
2319  
2320 Stephen Oberski, C<< <cpan at cargocult.ca> >>
2321  
2322 =head1 BUGS
2323  
2324 Please report any bugs or feature requests to C<bug-ipcamera-reolink at rt.cpan.org>, or through
2325 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=IPCamera-Reolink>. I will be notified, and then you'll
2326 automatically be notified of progress on your bug as I make changes.
2327  
2328 =head1 SUPPORT
2329  
2330 You can find documentation for this module with the perldoc command.
2331  
2332 perldoc IPCamera::Reolink
2333  
2334  
2335 You can also look for information at:
2336  
2337 =over 4
2338  
2339 =item * RT: CPAN's request tracker (report bugs here)
2340  
2341 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=IPCamera-Reolink>
2342  
2343 =item * CPAN Ratings
2344  
2345 L<https://cpanratings.perl.org/d/IPCamera-Reolink>
2346  
2347 =item * Search CPAN
2348  
2349 L<https://metacpan.org/release/IPCamera-Reolink>
2350  
2351 =back
2352  
2353 =head1 LICENSE AND COPYRIGHT
2354  
2355 This software is Copyright (c) 2024 by Stephen Oberski.
2356  
2357 This is free software, licensed under:
2358  
2359 The Artistic License 2.0 (GPL Compatible)
2360  
2361 =cut
2362 1; # End of IPCamera::Reolink
↑ Summary