Skip to content

Instantly share code, notes, and snippets.

@ferki
Created August 22, 2019 17:04
Show Gist options
  • Select an option

  • Save ferki/a1e86f769033a86c06ed63a257cd7ec2 to your computer and use it in GitHub Desktop.

Select an option

Save ferki/a1e86f769033a86c06ed63a257cd7ec2 to your computer and use it in GitHub Desktop.
Rex+MQTT
use strict;
use warnings;
use Rex -feature => [ '1.4', 'exec_autodie' ];
use Net::MQTT::Simple;
use Time::HiRes qw(time);
no_ssh task 'agent', sub {
my $mqtt = Net::MQTT::Simple->new('localhost');
$mqtt->run(
"topic/test" => sub {
my ( $topic, $message ) = @_;
run_task 'config',
params => { topic => $topic, message => $message };
},
);
};
task 'config', sub {
my $params = shift;
my $time = time;
LOCAL {
file '/tmp/mqtt', content => qq($time [$params->{topic}] $params->{message});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment