diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2021-05-10 19:01:37 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2021-05-10 19:01:37 +0200 |
commit | 639fca0f5cf2f853fb1d8464811878df4fb4d9e4 (patch) | |
tree | 56dc2f639de3e801772ef401c2c79349983f6522 /scd4x | |
parent | 2a84f50e8488f9de45b5f0484c31bd3c48e93016 (diff) | |
download | hue-639fca0f5cf2f853fb1d8464811878df4fb4d9e4.tar.gz |
rename #2
Diffstat (limited to 'scd4x')
-rwxr-xr-x | scd4x | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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; +} |