Power::Outlet::SonoffDiy - Control and query a Sonoff DIY device
my $outlet = Power::Outlet::SonoffDiy->new(host => "SonoffDiy"); print $outlet->query, "\n"; print $outlet->on, "\n"; print $outlet->off, "\n";
Power::Outlet::SonoffDiy is a package for controlling and querying Sonoff ESP8266 hardware running Sonoff firmware in DIY mode. This package supports and has been tested on both the version 1.4 (firmware 3.3.0) and version 2.0 (firmware 3.6.0) of the API.
From: https://github.com/itead/Sonoff_Devices_DIY_Tools
Commands can be executed via HTTP POST requests, for example:
curl -i -XPOST -d '{"deviceid":"","data":{}}' http://10.10.7.1:8081/zeroconf/info
1.4 Return where data is a string
{ "seq" : 21, "error" : 0, "data" : "{\"switch\":\"off\",\"startup\":\"stay\",\"pulse\":\"off\",\"pulseWidth\":500,\"ssid\":\"my_ssid\",\"otaUnlock\":false}" }
2.0 Return where data is an object
{ "seq" : 12, "error" : 0, "data":{ "switch" : "on", "startup" : "stay", "pulse" : "off", "pulseWidth" : 500, "ssid" : "my_ssid", "otaUnlock" : false, "fwVersion" : "3.6.0", "deviceid" : "1001262ec1", "bssid" : "fc:ec:da:81:c:98", "signalStrength" : -61 } } curl -i -XPOST -d '{"deviceid":"","data":{"switch":"off"}}' http://10.10.7.1:8081/zeroconf/switch { "seq" : 22, "error" : 0 } curl -i -XPOST -d '{"deviceid":"","data":{"switch":"on"}}' http://10.10.7.1:8081/zeroconf/switch { "seq" : 23, "error" : 0 }
use Power::Outlet::SonoffDiy; my $outlet = Power::Outlet::SonoffDiy->new(host=>"SonoffDiy"); print $outlet->on, "\n";
my $outlet = Power::Outlet->new(type=>"SonoffDiy", host=>"SonoffDiy"); my $outlet = Power::Outlet::SonoffDiy->new(host=>"SonoffDiy");
Sets and returns the hostname or IP address.
Default: SonoffDiy
Sets and returns the port number.
Default: 8081
Sets and returns the http_path.
Default: /
Returns the name as configured.
Note: The Sonoff DIY firmware does not support setting a hostname or friendly name.
Sends an HTTP message to the device to query the current state
Sends a message to the device to Turn Power ON
Sends a message to the device to Turn Power OFF
Sends a message to the device to toggle the power
Sends messages to the device to Cycle Power (ON-OFF-ON or OFF-ON-OFF).
Please log on RT and send an email to the author.
DavisNetworks.com supports all Perl applications including this package.
Michael R. Davis CPAN ID: MRDVT DavisNetworks.com
Copyright (c) 2020 Michael R. Davis
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
https://github.com/itead/Sonoff_Devices_DIY_Tools
To install Power::Outlet, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Power::Outlet
CPAN shell
perl -MCPAN -e shell install Power::Outlet
For more information on module installation, please visit the detailed CPAN module installation guide.