wise-paas-datahub-utility is a utility node-module for WISE-PaaS/DataHub.
npm install wise-paas-datahub-utilitynpm install wise-paas-datahub-utility
js
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()
-------------------------------------------------------
$3
Connects to MongoDB and MQTT broker specified by the given options.
You have to specify the following options, for example:
`js
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);
`
-------------------------------------------------------
$3
When no need to use datacore, close the connection.
-------------------------------------------------------
$3
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:
`js
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);
}
});
`
-------------------------------------------------------
$3
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:
`js
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);
}
});
`
-------------------------------------------------------
$3
Update real-time tag value.
The callback is called when tag value has been updated.
For example:
`js
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);
}
});
`
-------------------------------------------------------
$3
Get history tag data according to the input parameters.
The callback is called when data has been gotten.
For example:
`js
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);
}
});
`
-------------------------------------------------------
$3
Insert history tag data.
The callback is called when data has been inserted.
For example:
`js
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);
}
});
``