diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-10-21 19:12:04 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-10-21 19:12:04 +0200 |
commit | 217cdb9b3c2057615cdf7167f1c2d6f8a9be18fe (patch) | |
tree | 4518dfb0f13fbc7390e21ea47aca9c30ef6591ad | |
parent | c9463cb260f1851bb3f5a4b60acb913ec96807df (diff) |
Use --publish/--retain to select message type
-rwxr-xr-x | bin/mqtt-multipub | 18 |
1 files changed, 11 insertions, 7 deletions
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{ ^ (?<topic> [^=]+) = (?<msgtype> . ) = (?<content> .*) $ }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 ); } } } |