@@ -431,7 +431,7 @@ sub process_check {
431
431
# check if data comes back unauthenticated
432
432
if (($self -> {login_success } == 0) and ($self -> {login_attempt })) {
433
433
if ($main::Time > ($self -> {login_attempt } + 30)) { # retry log in every 30 seconds
434
- main::print_log( " [raZberry :" . $self -> {host } . " ] Attempting to re-authenticate" );
434
+ main::print_log( " [raZerry :" . $self -> {host } . " ] Attempting to re-authenticate" );
435
435
$self -> login;
436
436
}
437
437
}
@@ -440,7 +440,7 @@ sub process_check {
440
440
441
441
$com_status = " online" ;
442
442
$processed_data = 1;
443
- main::print_log( " [raZberry :" . $self -> {host } . " ] Background poll " . $self -> {poll_process_mode } . " process completed" ) if ( $self -> {debug } );
443
+ main::print_log( " [raZerry :" . $self -> {host } . " ] Background poll " . $self -> {poll_process_mode } . " process completed" ) if ( $self -> {debug } );
444
444
445
445
my $file_data = &main::file_read( $self -> {poll_data_file } );
446
446
exit unless ($file_data ); # if there is no data, then don't process
@@ -460,10 +460,6 @@ sub process_check {
460
460
main::print_log( " [raZberry:" . $self -> {host } . " ] ERROR! bad data returned by poll" );
461
461
main::print_log( " [raZberry:" . $self -> {host } . " ] ERROR! file data is [$file_data ]. json data is [$json_data ]" );
462
462
$com_status = " offline" ;
463
- if ($file_data =~ / .*Not logged in 401.*/i ){
464
- $self -> {cookie_jar }-> clear();
465
- $self -> login;
466
- }
467
463
} else {
468
464
push @process_data , $json_data ;
469
465
}
@@ -472,7 +468,7 @@ sub process_check {
472
468
$com_status = " online" ;
473
469
$processed_data = 2;
474
470
475
- main::print_log( " [raZberry :" . $self -> {host } . " ] Command " . $self -> {cmd_process_mode } . " process completed" ) if ( $self -> {debug } );
471
+ main::print_log( " [raZerry :" . $self -> {host } . " ] Command " . $self -> {cmd_process_mode } . " process completed" ) if ( $self -> {debug } );
476
472
477
473
my $file_data = &main::file_read( $self -> {cmd_data_file } );
478
474
exit unless ($file_data ); # if there is no data, then don't process
@@ -500,15 +496,11 @@ sub process_check {
500
496
501
497
# print "debug: json_data=$json_data\n" if ( $self->{debug} > 2);
502
498
unless ( ($file_data ) and ($json_data ) ) {
503
- main::print_log( " [raZberry:" . $self -> {host } . " ] ERROR! bad data returned by command " );
499
+ main::print_log( " [raZberry:" . $self -> {host } . " ] ERROR! bad data returned by poll " );
504
500
main::print_log( " [raZberry:" . $self -> {host } . " ] ERROR! file data is [$file_data ]. json data is [$json_data ]" );
505
501
$com_status = " offline" ;
506
502
# update the retry on the failed item.
507
503
$ {$self -> {cmd_queue }}[0][3]++;
508
- if ($file_data =~ / .*Not logged in 401.*/i ){
509
- $self -> {cookie_jar }-> clear();
510
- $self -> login;
511
- }
512
504
} else {
513
505
push @process_data , $json_data ;
514
506
shift @{ $self -> {cmd_queue } }; # successfully processed to remove item from the queue
@@ -519,21 +511,20 @@ sub process_check {
519
511
520
512
# check for any queued data that needs to be processed $self->{command_timeout}
521
513
if ((scalar @{ $self -> {cmd_queue } }) and ($self -> {cmd_process }-> done() )) {
522
- my ($mode , $url , $time , $retry ) = @ { ${ $self -> {cmd_queue } }[0] };
523
- # print "**** mode=$mode, url=$url \n";
514
+ my ($mode , $get_cmd , $time , $retry ) = @ { ${ $self -> {cmd_queue } }[0] };
515
+ # print "**** mode=$mode, get_cmd=$get_cmd \n";
524
516
# print "*** time=$time, time_diff=" . ($main::Time - $time) ." timeout=" .$self->{command_timeout} . " retry=$retry\n";
525
517
# if there is a retry, then execute at request time + (retry * 5 seconds)
526
518
# discard the command if 60 seconds after the request time
527
519
# if the item is queued then wait until at least a second after the request time
528
520
# discard the item if it's been retried $self->{command_timeout_limit} times
529
521
if ($retry > $self -> {command_timeout_limit }) {
530
- main::print_log( " [raZberry:" . $self -> {host } . " ] ERROR: Abandoning command $url due to $retry retry attempts" );
522
+ main::print_log( " [raZberry:" . $self -> {host } . " ] ERROR: Abandoning command $get_cmd due to $retry retry attempts" );
531
523
shift @{ $self -> {cmd_queue }};
532
524
} elsif (($main::Time - $time ) > $self -> {command_timeout }) {
533
- main::print_log( " [raZberry:" . $self -> {host } . " ] ERROR: $url request older than " . $self -> {command_timeout } . " seconds. Abandoning request" );
525
+ main::print_log( " [raZberry:" . $self -> {host } . " ] ERROR: $get_cmd request older than " . $self -> {command_timeout } . " seconds. Abandoning request" );
534
526
shift @{ $self -> {cmd_queue }};
535
527
} elsif (($main::Time > ($time + 1 + ($retry * 5)) and ($self -> {cmd_process }-> done() ) )) {# the original time isn't a great base for deep queued commands
536
- my $get_cmd = $self -> get_cmd_string($url );
537
528
if ($retry == 0) {
538
529
main::print_log( " [raZberry:" . $self -> {host } . " ] Command Queue found, processing next item" );
539
530
} else {
@@ -772,19 +763,11 @@ sub update_dev {
772
763
}
773
764
774
765
# ------------------------------------------------------------------------------------
775
- sub get_cmd_string{
776
- my ( $self , $url ) = @_ ;
777
- my $cookie = " " ;
778
- $cookie = $self -> {cookie_string } if ( $self -> {cookie_string } );
779
- my $get_params = " -ua " ;
780
- $get_params .= " -timeout " . $self -> {timeout } . " " ;
781
- $get_params .= " -cookies " . " '" . $cookie . " ' " if ($cookie ne " " );
782
- return " get_url $get_params $url " ;
783
- }
784
-
785
766
sub _get_JSON_data {
786
767
my ( $self , $mode , $cmd ) = @_ ;
787
768
769
+ my $cookie = " " ;
770
+ $cookie = $self -> {cookie_string } if ( $self -> {cookie_string } );
788
771
my $host = $self -> {host };
789
772
my $port = $self -> {port };
790
773
my $params = " " ;
@@ -799,8 +782,10 @@ sub _get_JSON_data {
799
782
or ( $mode eq " usercode_data" ) );
800
783
$method = " ZWaveAPI" if ( $mode eq " controller" );
801
784
&main::print_log(" [raZberry:" . $self -> {host } . " ]: contacting http://$host :$port /$method /$rest {$mode }$params " ) if ( $self -> {debug } );
802
- my $url = ' "http://' . " $host :$port /$method /$rest {$mode }$params " . ' "' ;
803
- my $get_cmd = $self -> get_cmd_string($url );
785
+ my $get_params = " -ua " ;
786
+ $get_params .= " -timeout " . $self -> {timeout } . " " ;
787
+ $get_params .= " -cookies " . " '" . $cookie . " ' " if ($cookie ne " " );
788
+ my $get_cmd = " get_url $get_params " . ' "http://' . " $host :$port /$method /$rest {$mode }$params " . ' "' ;
804
789
805
790
if (( $cmd eq " " ) or ($cmd =~ m / ^\? since=/ )) {
806
791
$self -> {poll_process }-> stop() unless ($self -> {poll_process }-> done() );
@@ -815,12 +800,12 @@ sub _get_JSON_data {
815
800
$self -> {cmd_process }-> start();
816
801
$self -> {cmd_process_pid }-> { $self -> {cmd_process }-> pid() } = $mode ; # capture the type of information requested in order to parse;
817
802
$self -> {cmd_process_mode } = $mode ;
818
- push @{ $self -> {cmd_queue } }, [$mode ,$url ,$main::Time ,0];
803
+ push @{ $self -> {cmd_queue } }, [$mode ,$get_cmd ,$main::Time ,0];
819
804
main::print_log( " [raZberry:" . $self -> {host } . " ] Backgrounding Command (" . $self -> {cmd_process }-> pid() . " ) command $mode , $get_cmd " ) if ( $self -> {debug } );
820
805
} else {
821
806
main::print_log( " [raZberry:" . $self -> {host } . " ] Queing Command command $mode , $get_cmd , time " . $main::Time ) if ( $self -> {debug } );
822
807
if (scalar @{ $self -> {cmd_queue } } <= $self -> {max_cmd_queue } ) {
823
- push @{ $self -> {cmd_queue } }, [$mode ,$url ,$main::Time ,0];
808
+ push @{ $self -> {cmd_queue } }, [$mode ,$get_cmd ,$main::Time ,0];
824
809
} else {
825
810
main::print_log( " [raZberry:" . $self -> {host } . " ] Max Queue Length ($self ->{max_cmd_queue}) reached! Discarding queued command" );
826
811
# @{ $self->{cmd_queue} } = ();
0 commit comments