node-upb
A NodeJS, Bower, browser, AMD, and CommonJS (that includes RequireJS) library that generates and decodes UPB (Universal Powerline Bus) commands. If you are looking for the CLI program that uses this, then please see upb-cli.
This has only been tested with Simply Automated switches! While probably won't harm your device (it is sending control commands, not core commands), I'm not sure what will happen when this is used with other branded switches (like PCS).
Installation
Node
Install it to your project folder:
npm install upb
Then include it in your file:
var upb = ;
Browser
Either download the package via Bower (package named upb
) or download the latest release and include it in your page:
Use it with the upb
object. The examples below should work fine. There is a minified version in the /dist/
folder or available for download from the releases page.
Usage
generate(command)
The function takes a JSON object input as command
and returns a promise withg a new JSON object with more data (including the generated command) as the first argument of the callback function.
If you plan on making your own serial implementation using this, remember to put the PIM in message mode first and to proceed each UPB command with the ASCII #20 character and to end it with the ASCII #13 character. Also, the PIM will automatically send the correct number of commands based on sendx
. So, sendTime
is only useful for displaying commands and not sending them.
Example:
upb;
decode(command, callback)
The function takes a string input as command
and returns a JSON object with data (including the original command) as the first argument of the callback function. The second argument of the callback function is for errors. This does not verify the checksum. However, it will throw errors for other problems in the command.
Example:
upb;
validCommands
An array of valid commands
Example:
console;// [20,"20","activate",21,"21","deactivate",22,"22","goto",23,"23","fadeStart",24,"24","fadeStop",25,"25","blink",26,"26","indicate",27,"27","toggle",30,"30","reportState",31,"31","storeState",80,"80","ackResponse",85,"85","setupTimeReport",86,"86","deviceStateReport",87,"87","deviceStatusReport",90,"90","registerValuesReport",91,"91","RAMvaluesReport",92,"92","rawDataReport",93,"93","heartbeatReport",143,"143","deviceSignatureReport"]
commands
An object of all commands
Example:
console;/* { activate: 20, deactivate: 21, goto: 22, fadeStart: 23, fadeStop: 24, blink: 25, indicate: 26, toggle: 27, reportState: 30, storeState: 31, ackResponse: 80, setupTimeReport: 85, deviceStateReport: 86, deviceStatusReport: 87, registerValuesReport: 90, RAMvaluesReport: 91, rawDataReport: 92, heartbeatReport: 93, deviceSignatureReport: 143 } */
defaultCommand
An object with the optional defaults.
Example:
console;// {"source":255,"sendx":1,"sendTime":1,"ackPulse":false,"idPulse":false,"ackMsg":false,"powerlineRepeater":0}
More Information
I got most of the information the last three items listed on this Simply Automated page: Tech Specs. I also experimented with my serial terminal to see responses of other switches.
- UPB System Description - This PDF describes all parts of the UPB protocol.
- UPB Command Wizard - Software - This program lets you build commands with a wizard/GUI and see the result. It does not actually send the command, but it is very valuable for understanding the commands without reading too much of the above PDF.
- UPB Powerline Interface Module (PIM) - Description - This PDF contains information about the PIM. It shows serial specifications (4800 baud 8-n-1) and PIM responses. It look me a while to figure out that the PIM always responds with
PE
whenever a command is not prefixed by the #20 character.