Created
August 22, 2019 17:04
-
-
Save ferki/a1e86f769033a86c06ed63a257cd7ec2 to your computer and use it in GitHub Desktop.
Rex+MQTT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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