NAME

Power::Outlet::SonoffDiy - Control and query a Sonoff DIY device

SYNOPSIS

my $outlet = Power::Outlet::SonoffDiy->new(host => "SonoffDiy");
print $outlet->query, "\n";
print $outlet->on, "\n";
print $outlet->off, "\n";

DESCRIPTION

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
}

USAGE

use Power::Outlet::SonoffDiy;
my $outlet = Power::Outlet::SonoffDiy->new(host=>"SonoffDiy");
print $outlet->on, "\n";

CONSTRUCTOR

new

my $outlet = Power::Outlet->new(type=>"SonoffDiy", host=>"SonoffDiy");
my $outlet = Power::Outlet::SonoffDiy->new(host=>"SonoffDiy");

PROPERTIES

host

Sets and returns the hostname or IP address.

Default: SonoffDiy

port

Sets and returns the port number.

Default: 8081

http_path

Sets and returns the http_path.

Default: /

METHODS

name

Returns the name as configured.

Note: The Sonoff DIY firmware does not support setting a hostname or friendly name.

query

Sends an HTTP message to the device to query the current state

on

Sends a message to the device to Turn Power ON

off

Sends a message to the device to Turn Power OFF

switch

Sends a message to the device to toggle the power

cycle

Sends messages to the device to Cycle Power (ON-OFF-ON or OFF-ON-OFF).

BUGS

Please log on RT and send an email to the author.

SUPPORT

DavisNetworks.com supports all Perl applications including this package.

AUTHOR

Michael R. Davis
CPAN ID: MRDVT
DavisNetworks.com

COPYRIGHT

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.

SEE ALSO

https://github.com/itead/Sonoff_Devices_DIY_Tools