-
Notifications
You must be signed in to change notification settings - Fork 2
/
mqtt2irc.pl
executable file
·75 lines (69 loc) · 1.79 KB
/
mqtt2irc.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl -w
use strict;
use v5.28;
use Net::MQTT::Simple;
use Time::HiRes qw(time);
my $mqtt = Net::MQTT::Simple->new("127.0.0.1");
sub mekker {
my $fn = "/home/bar/saysomething/liberachat_revspace";
open my $fh, ">>", $fn or warn "open: $fn: $!";
print STDOUT "@_\n";
print $fh "@_\n";
}
sub flipdot {
$mqtt->publish("revspace/flipdot", "@_");
}
my $off;
my $lichtgordijn_start;
$mqtt->subscribe(
"revspace/doorduino" => sub {
my ($topic, $message) = @_;
mekker $message;
},
"revspace/doorduino/checked-in" => sub {
my ($topic, $message) = @_;
$message += 0;
state $prev = 0;
if ($message != $prev) {
mekker "n = $message";
$prev = $message;
}
},
"revspace/button/nomz" => sub {
my ($topic, $message) = @_;
mekker "NOMZ!";
flipdot "<\@\@ N O M Z";
$off = time() + 27;
},
"revspace/button/doorbell" => sub {
my ($topic, $message) = @_;
mekker "deurbel";
flipdot "deurbel \@\@>\n\n deurbel";
$off = time() + 25;
},
"revspace/lichtgordijn" => sub {
my ($topic, $message) = @_;
if ($message eq 'IDLE') {
if ($lichtgordijn_start) {
my $delta = time() - $lichtgordijn_start;
open my $fh, ">>/home/bar/saysomething/liberachat_revspace";
printf $fh "Lichtgordijn %.1fs\n", $delta;
}
$lichtgordijn_start = undef;
} else {
$lichtgordijn_start = time;
}
},
"revspace/photo" => sub {
my ($topic, $message, $retain) = @_;
return if $retain; # alleen nieuwe foto's mekkeren
mekker "https://revspace.nl/kiekjes/view/$message";
},
);
while (1) {
$mqtt->tick(.1);
if ($off and time() > $off) {
flipdot "";
undef $off;
}
}