http wrapper for operating a ControlByWeb relay device
#setup.run(host, mac, callback)
add anarp
entry forhost
and test withping
#setup.arp(host, mac, callback)
add anarp
entry forhost
#setup.ping(host, callback)
ping the givenhost
#switch(host, breaker, state, callback)
change the state ofbreaker
tostate
and return the state of the relay (xml)#updateVariable(host, index, newVal, callback)
update an external variable atindex
tonewVal
and return the state of the relay (xml)#state(host, callback)
return the state of the relay (xml)
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
});
// update an external variable
webrelay.updateVariable(host, 0, 10, function(err, res) {
if (err) throw err;
// extVar0 value is now 10
});
// get the state back (in xml)
webrelay.state(host, function(err, res) {
if (err) throw err;
console.log(res);
});