2.2.16 • Published 2 years ago

wise-paas-datahub-utility v2.2.16

Weekly downloads
25
License
ISC
Repository
-
Last release
2 years ago

wise-paas-datahub-utility

wise-paas-datahub-utility is a utility node-module for WISE-PaaS/DataHub.

Installation

npm install wise-paas-datahub-utility

Example

const utility = require('wise-paas-datahub-utility');

const datastore = utility.datastore;
const deviceManager = utility.deviceManager;
const amqp = utility.amqp;

API

datastore

  • datastore.init(mongodbOptions, mqttOptions)
  • datastore.quit()
  • datastore.getRealData(tag array, [callback])
  • datastore.upsertRealData(nodeId, parameters, [callback])
  • datastore.updateRealData(nodeId, parameters, [callback])
  • datastore.getHistData()
  • datastore.insertHistData()

datastore.init(mongodbOptions, mqttOptions)

Connects to MongoDB and MQTT broker specified by the given options. You have to specify the following options, for example:

let mongodbConf = {
  host: '127.0.0.1',
  port: 27017,
  username: 'admin',
  password: '1234',
  database: 'mongodb'
};
let mqttConf = {
  host: '127.0.0.1',
  port: 1883,
  username: '',
  password: ''
};

datastore.init(mongodbConf, mqttConf);

datastore#quit()

When no need to use datacore, close the connection.


datastore#getRealData(tag array, callback)

Get real-time tag data by the given tags list, a tag has nodeId and tagName properties. The callback is called when all tag data has been gotten.

For example:

let t1 = {
  nodeId: 'node1',
  tagName: 'Foo1'
};

let t2 = {
  nodeId: 'node2',
  tagName: 'Foo2'
};

datastore.getRealData([t1, t2],  (err, response) => {
  if (err) {
    console.error(err);
  } else {
    console.log(response);
  }
});

datastore#upsertRealData(nodeId, parameters, callback)

Update real-time tag value. If tag is not found, tag will be inserted. The callback is called when tag value has been updated.

For example:

let nodeId = 'node1';
let t1 = {
  tagName: 'Foo1',
  value: 100,
  ts: new Date()
};

datastore.upsertRealData(nodeId, t1,  (err, response)=>  {
  if (err) {
    console.error(err);
  } else {
    console.log('success: ' + response.ok);
  }
});

datastore#updateRealData(nodeId, parameters, callback)

Update real-time tag value. The callback is called when tag value has been updated.

For example:

let nodeId = 'node1';
let t1 = {
  tagName: 'Foo1',
  value: 100,
  ts: new Date()
};

datastore.updateRealData(nodeId, t1,  (err, response) => {
  if (err) {
    console.error(err);
  } else {
    console.log('success: ' + response.ok);
  }
});

datastore#getHistData(parameters, callback)

Get history tag data according to the input parameters. The callback is called when data has been gotten.

For example:

let t1 = {
  nodeId: 'cda43195-7a0a-4903-a533-d333d8c5f9d9',
  deviceId: 'P02_NODE',
  tagName: 'ATML_PACPRF:CTR',
  startTs: new Date('2015-01-01'),
  endTs: new Date(),
  orderby: -1,
  limit: 10
};

datastore.getHistData(t1, function (err, response) {
  if (err) {
    console.error(err);
  } else {
    console.log(response);
  }
});

datastore#insertHistData(parameters, callback)

Insert history tag data. The callback is called when data has been inserted.

For example:

let t1 = {
  nodeId: 'cda43195-7a0a-4903-a533-d333d8c5f9d9',
  deviceId: 'P02_NODE',
  tagName: 'ATML_PACPRF:CTR',
  value: 100,
  ts: new Date()
};

datastore.insertHistData(t1, function (err, response) {
  if (err) {
    console.error(err);
  } else {
    console.log('success: ' + response.ok);
  }
});

2.2.16

2 years ago

2.2.15

2 years ago

2.2.13

2 years ago

2.2.14

2 years ago

2.2.12

3 years ago

2.2.11

3 years ago

2.2.10

3 years ago

2.1.1-1.1

3 years ago

2.2.9

3 years ago

2.2.8

3 years ago

2.2.7

3 years ago

2.2.6

3 years ago

2.2.5

3 years ago

2.2.4

3 years ago

2.2.3

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.2.0-rc5

3 years ago

2.2.0-rc4

3 years ago

2.2.0-rc1

3 years ago

2.2.0-rc3

3 years ago

2.2.0-rc2

3 years ago

2.1.11

3 years ago

2.1.9

3 years ago

2.1.10

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.14

4 years ago

2.0.13

4 years ago

2.0.12

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago