From fd14fb7a60e03d941f082411b1260d6c47565532 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 1 Nov 2017 11:15:46 +0100 Subject: Specify mqtt server via -h/--host option --- bin/mqtt-multipub | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/bin/mqtt-multipub b/bin/mqtt-multipub index 8fa622f..906a1db 100755 --- a/bin/mqtt-multipub +++ b/bin/mqtt-multipub @@ -7,9 +7,20 @@ use 5.020; our $VERSION = '0.00'; use File::Slurp qw(read_file); +use Getopt::Long; use Net::MQTT::Simple; -my $mqtt = Net::MQTT::Simple->new('172.23.225.193'); +my $mqtt_host; + +GetOptions( + 'h|host=s' => \$mqtt_host, +); + +if ( not defined $mqtt_host or not length($mqtt_host) ) { + die("Usage: $0 -h [topic=value ...]\n"); +} + +my $mqtt = Net::MQTT::Simple->new($mqtt_host); my $retain = 0; sub parse_content_string { @@ -31,9 +42,7 @@ for my $arg (@ARGV) { elsif ( $arg eq '--retain' ) { $retain = 1; } - elsif ( - $arg =~ m{ ^ (? [^=]+) = (? .*) $ }x ) - { + elsif ( $arg =~ m{ ^ (? [^=]+) = (? .*) $ }x ) { my $content = parse_content_string( $+{content} ); if ($retain) { $mqtt->retain( $+{topic}, $content ); -- cgit v1.2.3