This project is in a very early phase. Its goal is to provide an easy to use API for discovering, monitoring and controlling Machinetalk instances.
npm install --save machinetalk
var machinetalk = require('machinetalk');
// Initiate a machine browser that discovers Machinetalk
// machines on the network with their capabilities (services).
var browser = new machinetalk.MachineTalkBrowser();
// Wait for services to be discovered.
browser.on('serviceUp', function(service) {
// We are only interested in the 'status' service.
if (service.name !== 'status') { return; }
// Initiate a status client that can retrieve status updates.
var statusclient = new machinetalk.StatusClient(service.dsn);
// Wait for status updates for motion and print them.
statusclient.on('motionstatuschanged', function(status) {
console.log('Machine position: ',
status.position.x,
status.position.y,
status.position.z
);
});
// Connect to the status service.
// We are only interested in 'motion' updates.
statusclient.connect();
statusclient.subscribe('motion');
});
// Start discovering machines.
browser.start();