Skip to content

Instantly share code, notes, and snippets.

@sdhibit
Created September 24, 2015 17:18
Show Gist options
  • Save sdhibit/f417fe24d5b1c93ce4e5 to your computer and use it in GitHub Desktop.
Save sdhibit/f417fe24d5b1c93ce4e5 to your computer and use it in GitHub Desktop.
Node.js demo of ISY994 REST subscription using websockets
var WebSocket = require('ws');
var username = 'admin'; //replace with admin username
var password = 'password'; //replace with admin password
var host = '192.168.1.100'; //replace with your ISY IP
var auth = username + ':' + password;
var url = 'ws://' + auth + '@' + host + '/rest/subscribe';
var ws = new WebSocket(url, 'ISYSUB', {
origin: 'com.universal-devices.websockets.isy',
protocolVersion: 13
});
ws.on('open', function open() {
console.log('connected');
});
ws.on('close', function close() {
console.log('disconnected');
});
ws.on('message', function message(data, flags) {
console.log("*******************************");
console.log(data);
console.log("*******************************");
console.log("");
});
ws.on('error', function(error) {
console.log(error);
});
@sdhibit
Copy link
Author

sdhibit commented Sep 24, 2015

Run the following command in same directory as this file.

npm install ws 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment