-
Notifications
You must be signed in to change notification settings - Fork 114
Scout
This is a class you inherit from when writing custom device drivers. Scouts are used to search for devices with external node modules, or protocols.
It's used by require('zetta-scout')
. You must inherit from the Scout
class when building custom Zetta modules.
var util = require('util');
var Scout = require('zetta-scout');
function DeviceScout(){
Scout.call(this);
}
util.inherits(DeviceScout, Scout);
-
next
Function
This method should be implemented by you. This allows you to initialize any resources like bluetooth access, serial ports, or
vendor modules needed to look for devices. The argument next
is provided, and must be called after scouting has started. This notifies Zetta that the scouting process is done, and can move on to another scout if needed.
DeviceScout.prototype.init = function(next) {
var connection = Serial.connect(function(){
});
connection.on('start', function(){
next();
});
};
-
constructor
Subclass of Device -
arguments
List of Objects
This method is called by you when you've found your device. The constructor
argument should be a subclass of Device
, and the second argument is a
list of objects to be used by the constructor.
DeviceScout.prototype.init = function(next) {
this.discover(DeviceDriver, foo, bar, 'baz');
};
-
deviceObject
Object -
constructor
Subclass of Device
Zetta will persist device data to an internal registry. Using an object retrieved from this registry you can initialize a device that Zetta already
knows about. The first argument deviceObject
is just data on the object from Zetta. The constructor
argument is what will be created by Zetta.
DeviceScout.prototype.init = function(next) {
var deviceObject = {
name:'testObject',
id: '123',
foo: 'bar'
};
this.provision(deviceObject, DeviceDriver);
};
This gives access to the zetta runtime. Here you can issue queries and lookup devices that Zetta already knows about.
DeviceScout.prototype.init = function(next) {
var self = this;
// query registry for any device that has type led and an id that we know of.
var query = this.server.where({ type: 'lcd', id: 'some-id' });
this.server.find(query, function(err, results) {
if (results.length > 0) {
// found in registry, tell zetta it came online
self.provision(results[0], DeviceDriver, foo, bar, 'baz');
} else {
// does not exist in registry, discover a new one.
self.discover(DeviceDriver, foo, bar, 'baz');
}
});
};
Need help? Visit the Zetta Discuss List !
Need help? Visit the Zetta Discuss List ! |
---|
About Zetta
Videos and webcasts
- NEW! Building with Zetta
Tutorials
- NEW! Zetta tutorial series
- Quick start
- Configure a simple device
- Build a mock LED device
- Use the browser client
- Deploy a Zetta server to Heroku
Understanding Zetta
Writing Zetta drivers
- Finding Zetta device drivers
- Create a device driver from starter code
- More coming soon...
Using streams
Reference