Device::Plugwise - Perl module to communicate with Plugwise hardware
version 0.5
my $plugwise = Device::Plugwise->new(device => '/dev/cu.usbserial01'); $plugwise->command('on', 'ABCDEF'); # Enable Circle#ABCDEF while (1) { my $message = $plugwise->read(); print $message, "\n"; } $plugwise = Device::Plugwise->new(device => 'hostname:port'); $plugwise->command('on', 'ABCDEF'); # Enable Circle#ABCDEF
Module for interfacing to Plugwise hardware.
Current implemented functions are
IMPORTANT: This module required Plugwise firmware v2.37 or higher.
new(%parameters)
This constructor returns a new Device::Plugwise object. Supported parameters are listed below
The name of the device to connect to, The value can be a tty device name of hostname:port for a TCP connection. This parameter is required.
hostname:port
The name of an existing filehandle to be used instead of the 'device' parameter.
The baud rate for the tty device. The default is 9600.
9600
The port for a TCP device. There is no default port.
device()
Returns the device used to connect to the equipment. If a filehandle was provided this method will return undef.
baud()
Returns the baud rate. Only makes sense when connected over a serial connection.
port()
Returns the TCP port for the device. Only makes sense when using this type of connection of course.
filehandle()
This method returns the file handle for the device.
list_circles_count()
This method returns the number of Circles that will be interrogated with the list_circles command. If you have more than 16 Circles in your network, increase the setting to a higher value.
read([$timeout])
This method blocks until a new message has been received by the device. When a message is received the message string is returned. An optional timeout (in seconds) may be provided.
read_one(\$buffer, [$do_not_write])
This method attempts to remove a single message from the buffer passed in via the scalar reference. When a message is removed a data structure is returned that represents the data received. If insufficient data is available then undef is returned.
By default, a received message triggers sending of the next queued message if the $do_no_write parameter is set then writes are not triggered.
$do_no_write
write($command, $callback)
This method queues a command for sending to the connected device. The first write will be written immediately, subsequent writes are queued until a response to the previous message is received.
queue_size()
This method reports the number of commands that are in the queue to be sent to the stick.
status()
This method returns the status of the internal _plugwise hash. This can be used to extract network information and for debugging. Hash entries include
command($command, $target)
This method sends a command to the stick.
Supported $commands with a target id are:
$command
$target can either be a single short hardware MAC address or a comma-separated list of devices if multiple devices need to receive the same command.
$target
The code of this module is heavily based the code by Mark Hindess (Device::Onkyo), thanks Mark! The initial Perl Plugwise interface code for firmware v1 was written by Jfn.
Lieven Hollevoet <hollie@cpan.org>
This software is copyright (c) 2012 by Lieven Hollevoet.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Device::Plugwise, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Plugwise
CPAN shell
perl -MCPAN -e shell install Device::Plugwise
For more information on module installation, please visit the detailed CPAN module installation guide.