giotto-api
v1.0.8
Published
NodeJS wrapper for the GIoTTO and BuildingDepot APIs.
Downloads
4
Readme
node-giotto-api
NodeJS wrapper for the GIoTTO and BuildingDepot APIs.
Installation
- clone this repo,
- run
npm install
Usage
This is how you initialize it:
var GIoTTOApi = require('./path/to/the/repo/folder');
var api = new GIoTTOApi({
clientId: 'wHaTeVeR', # required
clientSecret: 'wHaTeVeR', # required
email: '[email protected]', # required, email for the user
mqUsername: 'wHaTeVeR', # required, username for the RabbitMQ
mqPassword: 'wHaTeVeR', # required, password for the RabbitMQ
protocol: 'https', # defaults to https
hostname: 'bd-exp.andrew.cmu.edu', # defaults to bd-exp.andrew.cmu.edu
csPort: 81, # defaults to 81, port for the CentralService
dsPort: 82 # defaults to 82, port for the DataService
});
api.authenticate(function (err) {
// start using the api here
});
Sending sensor data:
api.createSensor(name, building, identifier, function (err, response, body) {});
api.addSensorMetadata(uuid, {});
api.postTimeseriesValue(sensorUuid, time, value);
Searching for sensors:
api.searchSensorsInBuilding(building, function (err, response, body) {});
Subscribing to sensor data over RabbitMQ:
api.startListeningForSensorData(function (err, sensor, value) {});
api.subscribeToSensor(sensor, function (err) {});
api.unsubscribeFromSensor(sensor);
Reading timeseries of one sensor:
api.readTimeseries(uuid, startTime, endTime, (err, data) => {
// [ { time: 1484062558.954, value: 12.5 }, ... ]
});
Reading timeseries of multiple sensors:
api.readTimeseriesOfSensors([ uuid1, uuid2 ], startTime, endTime, (err, data) => {
// [ { time: 1484062558.954, value: 12.5 }, ... ]
});
Using virtual sensors to classify data:
var sensor = api.virtualSensor();
var uuids = [
[
'6931acba-cea0-437f-aadf-982334ce583f',
'288473c1-e809-4da0-85da-b77f53f62df0'
], // A group of sensors - their values will be merged and trained together
[
'5d952e43-d008-4713-9558-7031f7520e65'
] // Second group of sensors
];
sensor.addSample(uuids, 1484067040.554, 1484067050.121, 'light');
sensor.addSample(uuids, 1484067094.361, 1484067105.505, 'dark');
sensor.addSample(uuids, 1484067169.671, 1484067179.671, 'light');
sensor.addSample(uuids, 1484067130.728, 1484067140.500, 'dark');
sensor.train((err) => {
if (err) { console.log(err); return; }
sensor.predict(uuids, 1484067263.748, 1484067273.748, (err, label) => {
if (err) { console.log(err); return; }
console.log(label);
});
});
Creating, publishing and listening on custom message queues:
api.publishToQueue(queueName, '{}', function (err) {});
api.subscribeToQueue(this.queueName, function (err, msg) {});