-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunlock-via-mqtt.pl
executable file
·44 lines (33 loc) · 1.06 KB
/
unlock-via-mqtt.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
#!/usr/bin/perl
use strict;
use autodie;
use Net::MQTT::Simple;
my $mqtt = Net::MQTT::Simple->new("mosquitto.space.revspace.nl");
my %opt_in = do "/home/pi/doorduino/opt-in.conf.pl";
my %opt_out = do "/home/pi/doorduino/opt-out.conf.pl";
die "Can't write to device $opt_in{dev}" if not -w $opt_in{dev};
die "Can't write to device $opt_out{dev}" if not -w $opt_out{dev};
die "Opt-in door is not a fake door" if not $opt_in{skip_access};
die "Opt-out door is not a fake door" if not $opt_out{skip_access};
$mqtt->subscribe(
# Opzettelijk geen wildcards of parsing. Extra hard-coding voor
# paranoide beveiliging om te voorkomen dat een andere deur
# kan worden geopend.
"revspace-local/doorduino/opt-in/unlock" => sub {
my ($topic, $message) = @_;
warn "$topic => $message";
open my $dev, ">", $opt_in{dev};
print $dev "A\n";
close $dev;
},
"revspace-local/doorduino/opt-out/unlock" => sub {
my ($topic, $message) = @_;
warn "$topic => $message";
open my $dev, ">", $opt_out{dev};
print $dev "A\n";
close $dev;
},
);
while (1) {
$mqtt->tick(1);
}