-
Notifications
You must be signed in to change notification settings - Fork 0
/
Read.js
45 lines (38 loc) · 1.28 KB
/
Read.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module.exports = function (RED) {
var dc = require('./Calls.js');
function DCloudRead(cfg) {
"use strict";
RED.nodes.createNode(this, cfg);
var node = this;
node.config = cfg;
// node-specific code goes here
var util = require('util');
var async = require('async');
var request = require('request');
this.source = RED.nodes.getNode(node.config.source);
//Handle input
this.on('input', function (msg) {
this.log('input:' + util.inspect(msg));
readLatest();
});
this.on('close', function () {
this.log('Read close');
});
function readLatest() {
dc.read(node.source, node.config.from, node.config.variable, function (err, obj) {
if (err) {
node.error(err);
}
else {
var msg = {};
msg.payload = { ok: true }
msg.topic = node.variable;
msg.payload.data = obj;
//console.log('sending msg:' + util.inspect(msg));
node.send(msg);
}
});
}
}
RED.nodes.registerType("DCloud-Read", DCloudRead);
}