The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Power::Outlet::Dingtian - Control and query Dingtian Relay Boards via the HTTP API

SYNOPSIS

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

DESCRIPTION

Power::Outlet::Dingtian is a package for controlling and querying a relay on Dingtian hardware via the HTTP API.

Example commands can be executed via web (HTTP) GET requests, for example:

Relay Status URL Example

  http://192.168.1.100/relay_cgi_load.cgi

Relay 1 on example (relays are named one-based but the api uses a zero-based index)

  http://192.168.1.100/relay_cgi.cgi?type=0&relay=0&on=1&time=0&pwd=0&

Relay 2 off example

  http://192.168.1.100/relay_cgi.cgi?type=0&relay=1&on=0&time=0&pwd=0&

Relay 2 cycle off-on-off example (note: time in 100ms increments)

  http://192.168.1.100/relay_cgi.cgi?type=1&relay=1&on=1&time=100&pwd=0&

I have tested this package against the Dingtian DT-R002 V3.6A with V3.1.276A firmware configured for both HTTP and HTTPS.

USAGE

  use Power::Outlet::Dingtian;
  my $relay = Power::Outlet::Dingtian->new(host=>"my_host", relay=>"1");
  print $relay->on, "\n";

CONSTRUCTOR

new

  my $outlet = Power::Outlet->new(type=>"Dingtian", host=>"my_host", relay=>"1");
  my $outlet = Power::Outlet::Dingtian->new(host=>"my_host", relay=>"1");

PROPERTIES

relay

Dingtian API supports up to 32 relays numbered 1 to 32.

Default: 1

Note: The relays are numbered 1-32 but the api uses a zero based index.

pwd

Sets and returns the ID token used for authentication with the Dingtian hardware

Default: "0"

Can be set in the Relay Password property in the Other section on the Relay Connect screen.

host

Sets and returns the hostname or IP address.

Default: 192.168.1.100

port

Sets and returns the port number.

Default: 80

Can be set in the HTTP Server Port property on the Setting screen.

http_scheme

Sets and returns the http scheme (i.e. protocol) (e.g. http or https).

Default: http

Can be set in the HTTP or HTTPS property on the Setting screen

METHODS

name

Sets and returns the friendly name for this relay.

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 open an issue on GitHub.

AUTHOR

  Michael R. Davis
  CPAN ID: MRDVT

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://www.dingtian-tech.com/sdk/relay_sdk.zip => programming_manual_en.pdf page 12 "Protocol: HTTP GET CGI"