summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-08-12 20:31:04 +0200
committerDaniel Friesel <derf@finalrewind.org>2017-08-12 20:31:04 +0200
commitde795cf866e08a065f5794166946f57c6192ea2b (patch)
tree0df4197392394269e3bfa761f584c7e934189e55
parentddb272be30c164635a0205338540c748e444ce5e (diff)
Add config support to the publisher as well
-rwxr-xr-xbin/mqttsyncdir-publisher27
1 files changed, 22 insertions, 5 deletions
diff --git a/bin/mqttsyncdir-publisher b/bin/mqttsyncdir-publisher
index 53c36dd..92b5d3a 100755
--- a/bin/mqttsyncdir-publisher
+++ b/bin/mqttsyncdir-publisher
@@ -9,12 +9,29 @@ our $VERSION = '0.00';
use File::Slurp qw(read_dir read_file);
use Linux::Inotify2;
use Net::MQTT::Simple;
+use YAML::XS;
-# proof of concept -- a proper config parser will be implemented later
-my %config = (
- directory => '/tmp/mqttsyncdir-publisher',
- server => '172.23.225.193',
-);
+sub load_config {
+ my ($config_file) = @_;
+ my $content = read_file($config_file);
+ my $yaml = Load($content);
+ return $yaml;
+}
+
+my ($config_file) = @ARGV;
+
+if ( not defined $config_file ) {
+ die("Usage: $0 <config.yaml>\n");
+}
+
+my %config = %{ load_config($config_file) };
+
+if ( not defined $config{directory} ) {
+ die("Error: configuration must specify an output directory\n");
+}
+if ( not defined $config{server} ) {
+ die("Error: configuration must specify a server\n");
+}
my $mqtt = Net::MQTT::Simple->new( $config{server} );