node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org ยป

automationhub-client

# AutomationHub

By: Matthew Whited (c) 2014


Summary

This is a Node.JS library to interface WhitedUS.AutomationHub for .Net


Usage

see automationhub-sample.js for more examples

Create instance of AutomationHub client

var automation = require('automationhub-client');

var config = {
	clientAddress: "http://localhost:8080/signalR",
	panel: {
		name: name,
		devices: [
			new demoDevice("Device 1","D1","Demo Device 1"),
			new demoDevice("Device 2","D2","Demo Device 2")
		]
	},
	user: {
		name: name
	}
}

automation(config); // the process will automaticly after after constrution

Device instance miniumum

function demoDevice(name, device, description) {
	var _self = {
		name: name,
		device: device,
		description: description,
		type: "DemoDevice",
		allowed: "0,1",
		_value: "Init!"
	};
	
	this.__defineGetter__('name', function() { return _self.name; });
	this.__defineGetter__('device', function() { return _self.device; });
	this.__defineGetter__('description', function() { return _self.description; });
	this.__defineGetter__('type', function() { return _self.type; });
	this.__defineGetter__('allowed', function() { return _self.allowed; });

	this.__defineGetter__('value', function() {
		console.log("Get:", _self.device, _self._value);
		return _self._value;
		});
	this.__defineSetter__('value', function(value) { 
		console.log("Set:", _self.device, value);
		_self._value = value;
		});
}

Eventing Devices

Start with the above example

var events = require('events'),
	util = require('util');
util.inherits(demoDeviceEventer, events.EventEmitter);

var _t;
//the emited event must be 'deviceEvent'
self.emit('deviceEvent', 'eventType', { counter: _t++} /*event data*/);

Change History

  • v0.0.1: Initial Release
  • v0.0.2: Added support for device sent events

Donations for this project are graciously accepted by paypal matt@whited.us or by bitcoin 1CRroBpvWHzW5iVnmCwqkJWp8CC3APvAK8