@cesarbr/knot-cloud-sdk-js
KNoT Cloud SDK for NodeJS and browser
Last updated 5 months ago by jneto .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @cesarbr/knot-cloud-sdk-js 
SYNC missed versions from official npm registry.

knot-cloud-sdk-js

npm version

The knot-cloud-sdk-js is a client side library for Node.js and browser that aims to help developers to create solutions with the KNoT Cloud.

This library exports the following SDKs:

  • WebSocket SDK - npm version: to connect with WebSocket protocol adapter and operate on devices.

  • Authenticator SDK - npm version: to perform user management tasks such as authentication and password recovery.

  • Storage SDK - npm version: to operate on data sent by devices.

Quickstart

Install

npm install --save @cesarbr/knot-cloud-sdk-js

Example: Register Device

const { Client } = require('@cesarbr/knot-cloud-sdk-js');

const client = new Client({
  protocol: 'wss',
  hostname: 'ws.knot.cloud',
  port: 443,
  pathname: '/',
  id: '78159106-41ca-4022-95e8-2511695ce64c',
  token: 'd5265dbc4576a88f8654a8fc2c4d46a6d7b85574',
});

client.on('ready', () => {
  client.register({
    id: '6e5a681b2ae7be40',
    type: 'knot:thing',
    name: 'Door Lock',
  });
});
client.on('registered', (thing) => {
  console.log('Registered', thing);
  client.close();
});
client.connect();

Example: List Device Data

const { Storage } = require('@cesarbr/knot-cloud-sdk-js');

const client = new Storage({
  protocol: 'https',
  hostname: 'data.knot.cloud',
  id: 'b1a1bd58-c3ef-4cb5-82cd-3a2e0b38dd21',
  token: '3185a6c9d64915f6b468ee8043df4af5f08e1933',
});

async function main() {
  console.log(await client.listData())
}
main();

// [{
//   from: '188824f0-28c4-475b-ab36-2505402bebcb',
//   payload: {
//       sensorId: 2,
//       value: 234,
//   },
//   timestamp: '2019-03-18T12:48:05.569Z',
// },
// {
//   from: '188824f0-28c4-475b-ab36-2505402bebcb',
//   payload: {
//       sensorId: 1,
//       value: true,
//   },
//   timestamp: '2019-03-18T14:42:03.192Z',
// }]

Example:

const { Authenticator } = require('@cesarbr/knot-cloud-sdk-js');

const client = new Authenticator({
  protocol: 'https',
  hostname: 'auth.knot.cloud',
});

async function main() {
  try {
    console.log(await client.createUser('user@provider.com', '123qwe!@#QWE'));
  } catch (err) {
    if (err.response) {
      console.error(err.response.data.message);
      return;
    }
    console.error(err);
  }
}
main();

// { id: '863ad780-efd9-4158-b24a-026de3f1dffb'
//   token: '40ad864d503488eda9b629825876d46cb1356bdf' }

Current Tags

  • 3.2.0                                ...           latest (13 days ago)

8 Versions

  • 3.2.0                                ...           13 days ago
  • 3.1.0                                ...           3 months ago
  • 3.0.0                                ...           4 months ago
  • 2.1.0                                ...           5 months ago
  • 2.0.0                                ...           6 months ago
  • 1.2.0                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.0                                ...           a year ago

Copyright 2014 - 2016 © taobao.org |