aboutsummaryrefslogtreecommitdiffstats
path: root/scd4x
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2021-05-10 19:01:37 +0200
committerGerd Hoffmann <kraxel@redhat.com>2021-05-10 19:01:37 +0200
commit639fca0f5cf2f853fb1d8464811878df4fb4d9e4 (patch)
tree56dc2f639de3e801772ef401c2c79349983f6522 /scd4x
parent2a84f50e8488f9de45b5f0484c31bd3c48e93016 (diff)
downloadhue-639fca0f5cf2f853fb1d8464811878df4fb4d9e4.tar.gz
rename #2
Diffstat (limited to 'scd4x')
-rwxr-xr-xscd4x38
1 files changed, 38 insertions, 0 deletions
diff --git a/scd4x b/scd4x
new file mode 100755
index 0000000..b5baad5
--- /dev/null
+++ b/scd4x
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use English;
+use POSIX;
+use JSON;
+use Net::MQTT::Simple;
+
+my $host = shift;
+my $name = shift;
+my $file = shift;
+my $verbose = 1;
+
+my $mqtt = Net::MQTT::Simple->new($host) or die "mqtt init (server $host)";
+my $json = JSON->new->allow_nonref;
+
+sub read_json_file {
+ my $filename = shift;
+ my $content;
+
+ open FILE, '<', $filename or die "read $filename: $!";
+ { local $/; undef $/; $content = <FILE> }
+ close FILE;
+
+ return $json->decode($content);
+}
+
+for (;;) {
+ my $values = read_json_file($file);
+ for my $key (sort keys %{$values}) {
+ my $topic = $key . "/" . $name;
+ my $value = $values->{$key};
+ printf("%-20s: %s\n", $topic, $value) if $verbose;
+ $mqtt->retain( $topic => $value );
+ }
+ printf("--\n") if $verbose;
+ sleep 60;
+}