summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-11-01 11:15:46 +0100
committerDaniel Friesel <derf@finalrewind.org>2017-11-01 11:15:46 +0100
commitfd14fb7a60e03d941f082411b1260d6c47565532 (patch)
treea0a9443b774b9fe847df1700faa17f2f1a315b24
parent054426518ababc109a6d5c3df86e9da7e258885b (diff)
Specify mqtt server via -h/--host option
-rwxr-xr-xbin/mqtt-multipub17
1 files 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 <hostname> [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{ ^ (?<topic> [^=]+) = (?<content> .*) $ }x )
- {
+ elsif ( $arg =~ m{ ^ (?<topic> [^=]+) = (?<content> .*) $ }x ) {
my $content = parse_content_string( $+{content} );
if ($retain) {
$mqtt->retain( $+{topic}, $content );