Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Latest commit

 

History

History
48 lines (35 loc) · 1.77 KB

README.md

File metadata and controls

48 lines (35 loc) · 1.77 KB

webrelay

NPM

Build Status devDependency Status

Coverage Status Dependency Status

http wrapper for operating a ControlByWeb relay device

api
  • #setup.run(host, mac, callback) add an arp entry for host and test with ping
  • #setup.arp(host, mac, callback) add an arp entry for host
  • #setup.ping(host, callback) ping the given host
  • #switch(host, breaker, state, callback) change the state of breaker to state and return the state of the relay (xml)
  • #state(host, callback) return the state of the relay (xml)
usage

the module is programmed to spy at environment variables and runtime arguments for configuration data. runtime arguments take precedence over environment variables and default values.

var webrelay = require('webrelay'),
    host = webrelay.config.RELAY_HOST,
    mac = webrelay.config.RELAY_MAC;

// initial set up
webrelay.setup.run(host, mac, function(err, res) {
  if (err) throw err;
  // relay is now accessible via config.RELAY_HOST
});

// toggle a breaker
webrelay.switch(host, 1, 1, function(err, res) {
  if (err) throw err;
  // breaker number 1's state is now 1
});

// get the state back (in xml)
webrelay.state(host, function(err, res) {
  if (err) throw err;
  console.log(res);
});