#!/usr/bin/perl use Config::Tiny; use Net::MQTT::Simple::SSL; use strict; use warnings; my $config = $0; $config =~ s/\.pl$/.config/; my $configuration = Config::Tiny->read($config) or die("Could not read configuration file '$config': $!\n"); my $cpath = '/home/me/Certs'; my $mqtt = Net::MQTT::Simple::SSL->new("203.0.113.46:8883", { SSL_ca_file => "$cpath/certificate-authority.crt", SSL_cert_file => "$cpath/notifications-client.crt", SSL_key_file => "$cpath/notifications-client.key", # SSL_verify_mode => 0, }); $mqtt->login($configuration->{mqtt}->{account}, $configuration->{mqtt}->{password} ); $mqtt->subscribe('notifications', \&received); $mqtt->run(); $mqtt->disconnect(); exit(0); sub received { my ($topic, $message) = (@_); if ( $message =~ m/\x3b/ || $message =~ m/[\x00-\x08\x0a-\x1f]/ ) { warn "notify\tMalformed message\n"; } elsif ( $topic =~ m/\x3b/ || $topic =~ m/[\x00-\x08\x0a-\x1f]/ ) { warn "notify\tMalformed message\n"; } else { my ($title, $message) = ( $message =~ m/^([^\x09]+)\t(.*)$/ ); system("notify-send", "--icon=info", $title, $message); } }