eclipse-agail / agile-sdk

JavaScript Agile IoT SDK
Eclipse Public License 2.0
2 stars 4 forks source link

Agile SDK

The official JavaScript Agile IoT SDK.

js-semistandard-style Build Status

Role

The intention of this module is to provide developers a nice API to integrate their JavaScript applications with Agile IoT Gateway.

Installation

Install the Agile SDK by running:

$ npm install --save agile-sdk

Documentation

The module exports a single factory function that takes an object including your Agile API hostname as the api property. Additionally, it can receive the idm url and a token.

It's available in node.js and the browser.

var agile = require('agile-sdk')({
  api: 'http://agile.local:8080',
  idm: 'http://agile.local:3000',
  token: "LQCL7C14y84Ayqedjmbm1LuIes1TsSyn5Cv"
})

For convenience it's shipped with a browser bundle too with agileSDK expose as a global constant eg.

<script src="https://github.com/eclipse-agail/agile-sdk/raw/master/node_modules/agile-sdk/dist/bundle.js"></script>
<script>
var agile = agileSDK({
  api: 'http://agile.local:8080',
  idm: 'http://agile.local:3000',
  token: "LQCL7C14y84Ayqedjmbm1LuIes1TsSyn5Cv"
});

agile.protocolManager.discovery.start()
.then(function() {
  console.log('started!')
})
.catch(function(err) {
  console.log(err)
});
</script>

Here a example of reading data from a device:

import agileSDK from 'agile-sdk';

const agile = agileSDK({
  api: 'http://agile.local:8080',
  idm: 'http://agile.local:3000',
  token: "LQCL7C14y84Ayqedjmbm1LuIes1TsSyn5Cv"
});
const deviceId = 'bleB0B448BE5084';
const componentID = 'Temperature';

agile.device.subscribe(deviceId, componentID).then(stream => {
  stream.onerror = () => {
    console.log('Connection Error');
  };

  stream.onopen = () => {
    console.log('Connected');
  };

  stream.onclose = () => {
    console.log('Closed');
  };

  stream.onmessage = (e) => {
    if (typeof e.data === 'string') {
        console.log("Received: '" + e.data + "'");
    }
  };
}).catch(err => {
  console.log(err);
});

Read full documentation.

Change Log

The change log is automatically managed by versionist. View full change log.

Support

If you're having any problem, please raise an issue on GitHub and the team will be happy to help.

Tests

npm run test