specify topic on command-line
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 7 Aug 2017 13:06:51 +0000 (15:06 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 7 Aug 2017 13:06:51 +0000 (15:06 +0200)
mqtt-trend.pl

index e256a45..7047672 100755 (executable)
@@ -19,12 +19,15 @@ system "i3-msg layout splitv";
 
 my $border = 2;
 
 
 my $border = 2;
 
-open(my $in, '-|', 'mosquitto_sub -h rpi2 -t stat/# -t fade/# -v');
+my $topic = 'fade/#';
+$topic = $ARGV[0] if $ARGV[0];
+
+open(my $in, '-|', "mosquitto_sub -h rpi2 -t '$topic' -v");
 while(<$in>) {
        s/\s+$//sg;
 
        my ($t,$v) = split(/\s/,$_,2);
 while(<$in>) {
        s/\s+$//sg;
 
        my ($t,$v) = split(/\s/,$_,2);
-       warn "$t\t$v\n";
+       print STDERR "$t=$v ";
 
        if ( ! exists $trend->{$t} && $v =~ m/^\d+/ ) {
                my $hist = $trend->{hist_spec}->{$t} || $trend->{hist_spec}->{__default};
 
        if ( ! exists $trend->{$t} && $v =~ m/^\d+/ ) {
                my $hist = $trend->{hist_spec}->{$t} || $trend->{hist_spec}->{__default};