From 217cdb9b3c2057615cdf7167f1c2d6f8a9be18fe Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 21 Oct 2017 19:12:04 +0200 Subject: Use --publish/--retain to select message type --- bin/mqtt-multipub | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'bin/mqtt-multipub') diff --git a/bin/mqtt-multipub b/bin/mqtt-multipub index 8cbcefd..9a94b8f 100755 --- a/bin/mqtt-multipub +++ b/bin/mqtt-multipub @@ -9,7 +9,8 @@ our $VERSION = '0.00'; use File::Slurp qw(read_file); use Net::MQTT::Simple; -my $mqtt = Net::MQTT::Simple->new('172.23.225.193'); +my $mqtt = Net::MQTT::Simple->new('172.23.225.193'); +my $retain = 0; sub parse_content_string { my ($raw_content) = @_; @@ -24,18 +25,21 @@ sub parse_content_string { } for my $arg (@ARGV) { - if ( + if ( $arg eq '--publish' ) { + $retain = 0; + } + elsif ( $arg eq '--retain' ) { + $retain = 1; + } + elsif ( $arg =~ m{ ^ (? [^=]+) = (? . ) = (? .*) $ }x ) { my $content = parse_content_string( $+{content} ); - if ( $+{msgtype} eq 'm' ) { - $mqtt->publish( $+{topic}, $content ); - } - elsif ( $+{msgtype} eq 'r' ) { + if ($retain) { $mqtt->retain( $+{topic}, $content ); } else { - warn "Unsupported message type $+{msgtype} ($arg)\n"; + $mqtt->publish( $+{topic}, $content ); } } } -- cgit v1.2.3