Storage SDK¶
KNoT Cloud storage service JavaScript library.
Quick Start¶
Install¶
npm install --save @cesarbr/knot-cloud-sdk-js-storage
Run¶
KNoTCloudStorage connects to <protocol>://<hostname>:<port> using
user or gateway credentials (device owner). Replace this address with
your storage instance and the credentials with valid ones.
const KNoTCloudStorage = require('@cesarbr/knot-cloud-sdk-js-storage');
const client = new KNoTCloudStorage({
  protocol: 'https',
  hostname: 'data.knot.cloud',
  id: 'b1a1bd58-c3ef-4cb5-82cd-3a2e0b38dd21',
  token: '3185a6c9d64915f6b468ee8043df4af5f08e1933',
});
Methods¶
constructor(options)¶
Creates a new client storage instance so that you can operate on storage.
- Parameters
 
optionsObject JSON object.protocolString (Optional) Either'http'or'https'. Default:'https'.hostnameString KNoT Cloud storage instance host name.portNumber (Optional) KNoT Cloud storage instance port. Default: 443.pathnameString (Optional) Path name on the server.idString Device owner ID.tokenNumber Device owner token.
- Example
 
const KNoTCloudStorage = require('@cesarbr/knot-cloud-sdk-js-storage');
const client = new KNoTCloudStorage({
  protocol: 'https',
  hostname: 'data.knot.cloud',
  id: 'b1a1bd58-c3ef-4cb5-82cd-3a2e0b38dd21',
  token: '3185a6c9d64915f6b468ee8043df4af5f08e1933',
});
listData(query)¶
Get all the device data messages.
- Parameters
 
queryObject Optional properties used to filter data.orderByString The field used to order.orderNumber Ascending (1) or descending (2) order, default=0.skipNumber The number of data to skip (returns skip + 1), default=0.takeNumber The maximum number of data that you want from skip + 1 (the number is limited to 100), default=10.startDateString The start date that you want your set of data (format=YYYY-MM-DD HH:MM:SS).endDateString The finish date that you want your set of data (format=YYYY-MM-DD HH:MM:SS).
- Return
 
messagesArray JSON object containing device data messages.
- Example
 
const KNoTCloudStorage = require('@cesarbr/knot-cloud-sdk-js-storage');
const client = new KNoTCloudStorage({
  protocol: 'https',
  hostname: 'data.knot.cloud',
  id: 'b1a1bd58-c3ef-4cb5-82cd-3a2e0b38dd21',
  token: '3185a6c9d64915f6b468ee8043df4af5f08e1933',
});
client.listData();
// [{
//   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',
// }]
listDataByDevice(id, query)¶
Get the messages sent by a specific device.
- Parameters
 
idString Device ID.queryObject Optional properties used to filter data.orderByString The field used to order.orderNumber Ascending (1) or descending (2) order, default=0.skipNumber The number of data to skip (returns skip + 1), default=0.takeNumber The maximum number of data that you want from skip + 1 (the number is limited to 100), default=10.startDateString The start date that you want your set of data (format=YYYY-MM-DD HH:MM:SS).endDateString The finish date that you want your set of data (format=YYYY-MM-DD HH:MM:SS).
- Return
 
messagesArray JSON object containing device data messages.
- Example
 
const KNoTCloudStorage = require('@cesarbr/knot-cloud-sdk-js-storage');
const client = new KNoTCloudStorage({
  protocol: 'https',
  hostname: 'data.knot.cloud',
  id: 'b1a1bd58-c3ef-4cb5-82cd-3a2e0b38dd21',
  token: '3185a6c9d64915f6b468ee8043df4af5f08e1933',
});
const data = client.listDataById('cc5429a29afcd158');
console.log(data);
// [{
//   from: '188824f0-28c4-475b-ab36-2505402bebcb',
//   payload: {
//       sensorId: 2,
//       value: 234,
//   },
//   timestamp: '2019-03-18T12:48:05.569Z',
// }]
listDataBySensor(deviceId, sensorId, query)¶
Get the messages sent by a specific device’s sensor.
- Parameters
 
deviceIdString Device ID.sensorIdNumber Sensor ID.queryObject Optional properties used to filter data.orderByString The field used to order.orderNumber Ascending (1) or descending (2) order, default=0.skipNumber The number of data to skip (returns skip + 1), default=0.takeNumber The maximum number of data that you want from skip + 1 (the number is limited to 100), default=10.startDateString The start date that you want your set of data (format=YYYY-MM-DD HH:MM:SS).endDateString The finish date that you want your set of data (format=YYYY-MM-DD HH:MM:SS).
- Return
 
messagesArray JSON object containing device’s sensor data messages.
- Example
 
const KNoTCloudStorage = require('@cesarbr/knot-cloud-sdk-js-storage');
const client = new KNoTCloudStorage({
  protocol: 'https',
  hostname: 'data.knot.cloud',
  id: 'b1a1bd58-c3ef-4cb5-82cd-3a2e0b38dd21',
  token: '3185a6c9d64915f6b468ee8043df4af5f08e1933',
});
client.listDataBySensor('cc5429a29afcd158', 1);
// [{
//   from: '188824f0-28c4-475b-ab36-2505402bebcb',
//   payload: {
//       sensorId: 1,
//       value: true,
//   },
//   timestamp: '2019-07-04T02:37:45.365Z',
// }]