@gotillit/tillit-node-red 1.1.14 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,7 +45,8 @@ var got_1 = __importDefault(require("got"));
45
45
  var buildApiFunction = function (RED) { return (function apiCall(n) {
46
46
  RED.nodes.createNode(this, n);
47
47
  this.myDevice = n.device;
48
- this.connection = RED.nodes.getNode(this.myDevice);
48
+ this.device = RED.nodes.getNode(this.myDevice);
49
+ this.connection = this.device.broker;
49
50
  var _a = this.connection, environment = _a.environment, tenant = _a.tenant, username = _a.username, password = _a.password;
50
51
  var self = this;
51
52
  self.on("input", function (msg) {
@@ -1 +1 @@
1
- {"version":3,"file":"node-api.js","sourceRoot":"","sources":["../../src/nodes/node-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAAyC;AACzC,4CAAsB;AAEf,IAAM,gBAAgB,GAAG,UAAC,GAAQ,IAAK,OAAA,CAAC,SAAS,OAAO,CAAC,CAAiB;IAC7E,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IACzB,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAA,KAA4C,IAAI,CAAC,UAAU,EAA1D,WAAW,iBAAA,EAAE,MAAM,YAAA,EAAE,QAAQ,cAAA,EAAE,QAAQ,cAAmB,CAAC;IAClE,IAAM,IAAI,GAAG,IAAI,CAAC;IAElB,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,UAAgB,GAAQ;;;;;;;wBAE/B,QAAQ,GAAG,MAAA,GAAG,CAAC,QAAQ,mCAAI,CAAC,CAAC,QAAQ,CAAC;wBACtC,GAAG,GAAG,IAAA,gBAAQ,EA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KAAK,EAAE,GAAG,CAAC,KAAK;oCAChB,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI;iCAC5D,EAAE,IAAI,CAAC,CAAC,CAAC;yBACb;wBAAC,OAAO,CAAC,EAAE;4BACR,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE;oCACb,KAAK,EAAE,GAAG,CAAC,KAAK;oCAChB,OAAO,EAAE,QAAQ,CAAC,IAAI;iCACzB,CAAC,CAAC,CAAC;yBACP;;;;wBAGD,IAAI,CAAC,MAAM,CAAC;4BACR,IAAI,EAAE,KAAK;4BACX,KAAK,EAAE,MAAM;4BACb,IAAI,EAAE,OAAK,CAAC,OAAO;yBACtB,CAAC,CAAC;wBACH,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE;gCACb,KAAK,EAAE,GAAG,CAAC,KAAK;gCAChB,OAAO,EAAE,OAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,OAAK,CAAC,OAAO,EAAC;6BAC5F,CAAC,CAAC,CAAC;;;;;;KAGX,CAAC,CAAC;AACP,CAAC,CAAC,EAjE4C,CAiE5C,CAAA;AAjEW,QAAA,gBAAgB,oBAiE3B"}
@@ -1,2 +1,16 @@
1
1
  import { TilliTConnection } from '../shared/types';
2
+ export interface NodeMqttClient {
3
+ client: any;
4
+ connected: boolean;
5
+ connect: () => Promise<boolean>;
6
+ reconnect: () => Promise<boolean>;
7
+ disconnect: () => Promise<boolean>;
8
+ unsubscribe: (topic: string) => Promise<any>;
9
+ subscribe: (topic: string, qos: '0' | '1' | '2', on_message?: any) => Promise<boolean>;
10
+ on: (event: string, listener: any) => void;
11
+ }
12
+ export interface NodeBrokerInterface {
13
+ connect: (clientId: string, reconnect: any, callback: any) => void;
14
+ mqttClient: NodeMqttClient;
15
+ }
2
16
  export declare const buildNodeBrokerFunction: (RED: any) => (n: TilliTConnection) => void;
@@ -4,81 +4,92 @@ exports.buildNodeBrokerFunction = void 0;
4
4
  var utils_1 = require("../shared/utils");
5
5
  var edge_from_s3_1 = require("../shared/edge-from-s3");
6
6
  var aws_iot_device_sdk_v2_1 = require("aws-iot-device-sdk-v2");
7
- var buildNodeBrokerFunction = function (RED) { return (function awsNodeBroker(n) {
8
- var _this = this;
9
- var _a;
10
- var workingDir = RED.settings.userDir + '/';
11
- RED.nodes.createNode(this, n);
12
- this.clientId = process.env.CLIENT_ID || n.thingId;
13
- this.environment = (_a = n.environment) !== null && _a !== void 0 ? _a : process.env.ENVIRONMENT;
14
- this.endpoint = process.env.IOT_ENDPOINT || (0, utils_1.mqttEndpoint)(n.environment);
15
- var username = n.username, tenant = n.tenant, password = n.password;
16
- username = username !== null && username !== void 0 ? username : process.env.USERNAME;
17
- this.password = password !== null && password !== void 0 ? password : process.env.PASSWORD;
18
- this.tenant = tenant !== null && tenant !== void 0 ? tenant : process.env.TENANT;
19
- this.username = "".concat(username, "@").concat(tenant, ".tillit.cloud");
20
- if (process.env.EDGE_BUCKET && n.thingId) {
21
- (0, edge_from_s3_1.downloadAndUnzipEdge)(workingDir, n.thingId);
7
+ var NodeBroker = /** @class */ (function () {
8
+ function NodeBroker(n, RED, log) {
9
+ var _a;
10
+ this.log = log;
11
+ this.workingDir = RED.settings.userDir + '/';
12
+ try {
13
+ this.clientId = process.env.CLIENT_ID || n.thingId;
14
+ this.environment = (_a = n.environment) !== null && _a !== void 0 ? _a : process.env.ENVIRONMENT;
15
+ this.endpoint = process.env.IOT_ENDPOINT || (0, utils_1.mqttEndpoint)(n.environment);
16
+ var username = n.username, tenant = n.tenant, password = n.password;
17
+ username = username !== null && username !== void 0 ? username : process.env.USERNAME;
18
+ this.password = password !== null && password !== void 0 ? password : process.env.PASSWORD;
19
+ this.tenant = tenant !== null && tenant !== void 0 ? tenant : process.env.TENANT;
20
+ this.username = "".concat(username, "@").concat(tenant, ".tillit.cloud");
21
+ this.thingCert = process.env.THING_CERT || (this.workingDir + this.clientId + '/tillitEdgeConfig/thingCert.crt');
22
+ this.privKey = process.env.PRIV_KEY || (this.workingDir + this.clientId + '/tillitEdgeConfig/privKey.key');
23
+ this.rootCa = process.env.ROOT_CA || (this.workingDir + this.clientId + '/tillitEdgeConfig/rootCA.pem');
24
+ if (process.env.EDGE_BUCKET && n.thingId) {
25
+ (0, edge_from_s3_1.downloadAndUnzipEdge)(this.workingDir, n.thingId);
26
+ }
27
+ }
28
+ catch (e) {
29
+ console.error(e);
30
+ }
22
31
  }
23
- var self = this;
24
- this.connect = function (clientId, reconnect, callback) {
25
- clientId = n.thingId.trim();
26
- if (!self.device || reconnect) {
27
- self.log("Attempt to connect to with " + clientId + " from: " + _this.endpoint);
28
- var thingCert = process.env.THING_CERT || n.thingCert || (workingDir + n.thingId + '/tillitEdgeConfig/thingCert.crt');
29
- var privKey = process.env.PRIV_KEY || n.privKey || (workingDir + n.thingId + '/tillitEdgeConfig/privKey.key');
30
- var rootCa = process.env.ROOT_CA || n.rootCa || (workingDir + n.thingId + '/tillitEdgeConfig/rootCA.pem');
31
- self.log("Using the certificates that are presented as follows:");
32
- self.log(" - keyPath : " + privKey);
33
- self.log(" - certPath : " + thingCert);
34
- self.log(" - caPath : " + rootCa);
35
- var configBuilder = aws_iot_device_sdk_v2_1.iot.AwsIotMqttConnectionConfigBuilder.new_mtls_builder_from_path(thingCert, privKey);
36
- configBuilder.with_certificate_authority_from_path(undefined, rootCa);
32
+ NodeBroker.prototype.connect = function (clientId, reconnect, callback) {
33
+ var _a, _b;
34
+ this.log("connected: ".concat((_b = (_a = this.mqttClient) === null || _a === void 0 ? void 0 : _a.client) === null || _b === void 0 ? void 0 : _b.connected));
35
+ if (!this.mqttClient || reconnect) {
36
+ this.log("Attempt to connect to with " + clientId + " from: " + this.endpoint);
37
+ this.log("Using the certificates that are presented as follows:");
38
+ this.log(" - keyPath : " + this.privKey);
39
+ this.log(" - certPath : " + this.thingCert);
40
+ this.log(" - caPath : " + this.rootCa);
41
+ var configBuilder = aws_iot_device_sdk_v2_1.iot.AwsIotMqttConnectionConfigBuilder.new_mtls_builder_from_path(this.thingCert, this.privKey);
42
+ configBuilder.with_certificate_authority_from_path(undefined, this.rootCa);
37
43
  configBuilder.with_clean_session(false);
38
- configBuilder.with_client_id(clientId || "test-" + Math.floor(Math.random() * 100000000));
39
- configBuilder.with_endpoint(self.endpoint);
44
+ configBuilder.with_client_id((clientId || "test-") + Math.floor(Math.random() * 100000000));
45
+ configBuilder.with_endpoint(this.endpoint);
40
46
  configBuilder.with_keep_alive_seconds(20);
41
47
  var config = configBuilder.build();
42
- console.log(JSON.stringify(config));
43
48
  var client = new aws_iot_device_sdk_v2_1.mqtt.MqttClient();
44
- self.device = client.new_connection(config);
45
- self.device.connect().catch(function (error) {
49
+ this.mqttClient = client.new_connection(config);
50
+ this.mqttClient.connect().catch(function (error) {
46
51
  console.log("Connect error: " + error);
47
- }).then(function (connected, err) {
52
+ }).then(function (connected) {
53
+ }).catch(function (err) {
48
54
  console.log(err);
49
55
  });
50
- if (self.device) {
51
- self.device.on('connect', function () {
56
+ var self_1 = this;
57
+ if (this.mqttClient) {
58
+ this.mqttClient.on('connect', function () {
59
+ this.connnected = true;
52
60
  callback('connected');
53
61
  });
54
- self.device.on('reconnect', function () {
55
- callback('reconnected');
56
- });
57
- self.device.on('interrupt', function (error) {
62
+ this.mqttClient.on('interrupt', function (error) {
63
+ this.connnected = false;
58
64
  callback('interrupt', error);
59
65
  });
60
- self.device.on('resume', function (error) {
66
+ this.mqttClient.on('resume', function (error) {
67
+ this.connnected = true;
61
68
  callback('resume', error);
62
69
  });
63
- self.device.on('error', function (error) {
70
+ this.mqttClient.on('error', function (error) {
64
71
  callback('error', error);
65
72
  });
66
- self.device.on('offline', function () {
67
- callback('offline');
68
- });
69
73
  }
70
74
  callback('created');
71
75
  }
72
- else if (self.device) {
73
- callback('ready');
76
+ else if (this.mqttClient) {
77
+ callback('connected');
74
78
  }
75
79
  };
76
- self.on('close', function () {
80
+ ;
81
+ return NodeBroker;
82
+ }());
83
+ var buildNodeBrokerFunction = function (RED) { return (function awsNodeBroker(n) {
84
+ RED.nodes.createNode(this, n);
85
+ var self = this;
86
+ this.broker = new NodeBroker(n, RED, function (msg) { return self.log(msg); });
87
+ this.on('close', function () {
77
88
  self.log("closed " + self.clientId + " ok");
78
- if (self.device) {
79
- self.device.disconnect();
89
+ if (self.broker.mqttClient) {
90
+ self.broker.mqttClient.disconnect();
80
91
  }
81
- self.device = null;
92
+ self.broker.mqttClient = null;
82
93
  });
83
94
  }); };
84
95
  exports.buildNodeBrokerFunction = buildNodeBrokerFunction;
@@ -1 +1 @@
1
- {"version":3,"file":"node-broker.js","sourceRoot":"","sources":["../../src/nodes/node-broker.ts"],"names":[],"mappings":";;;AACA,yCAA6C;AAC7C,uDAA4D;AAC5D,+DAAgD;AAEzC,IAAM,uBAAuB,GAAG,UAAC,GAAQ,IAAK,OAAA,CACjD,SAAS,aAAa,CAAC,CAAmB;IAA1C,iBAiFC;;IAhFG,IAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,GAAG,GAAG,CAAC;IAC9C,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,CAAC,OAAO,CAAC;IACnD,IAAI,CAAC,WAAW,GAAG,MAAA,CAAC,CAAC,WAAW,mCAAI,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAC5D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,IAAA,oBAAY,EAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACnE,IAAA,QAAQ,GAAsB,CAA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AAC,CAAC;IACrE,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE;QACb,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC;QAC5C,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YACxB,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;SAEvC;QACD,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;IAClC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,EAb+C,CAa/C,CAAA;AAbO,QAAA,uBAAuB,2BAa9B"}
@@ -0,0 +1,2 @@
1
+ import { TilliTEvent } from '../shared/types';
2
+ export declare const buildEventFunction: (RED: any) => (n: TilliTEvent) => void;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.buildEventFunction = void 0;
43
+ var utils_1 = require("../shared/utils");
44
+ var got_1 = __importDefault(require("got"));
45
+ var buildEventFunction = function (RED) { return (function apiCall(n) {
46
+ RED.nodes.createNode(this, n);
47
+ this.myDevice = n.device;
48
+ this.device = RED.nodes.getNode(this.myDevice);
49
+ this.connection = this.device.broker;
50
+ var _a = this.connection, environment = _a.environment, tenant = _a.tenant, username = _a.username, password = _a.password;
51
+ var self = this;
52
+ var payload = {
53
+ assetId: n.assetId * 1,
54
+ eventTypeId: n.eventTypeId * 1,
55
+ subtitle: n.subtitle,
56
+ timestamp: new Date().toISOString()
57
+ };
58
+ self.on("input", function (msg) {
59
+ return __awaiter(this, void 0, void 0, function () {
60
+ var url, finalPayload, ops, response, error_1, error_2;
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0:
64
+ _a.trys.push([0, 5, , 6]);
65
+ url = (0, utils_1.hostname)(environment, tenant) + '/api/core/event-instances/raise';
66
+ self.status({
67
+ fill: "blue",
68
+ shape: "ring",
69
+ text: "sending..."
70
+ });
71
+ _a.label = 1;
72
+ case 1:
73
+ _a.trys.push([1, 3, , 4]);
74
+ finalPayload = payload;
75
+ if (msg.payload && typeof msg.payload === 'object') {
76
+ finalPayload = Object.assign(payload, msg.payload);
77
+ }
78
+ if (!finalPayload.assetId) {
79
+ finalPayload.assetId = msg.topic;
80
+ }
81
+ ops = {
82
+ method: 'POST',
83
+ username: username,
84
+ password: password,
85
+ json: finalPayload
86
+ };
87
+ console.log('Raising event ' + url + ' ' + JSON.stringify(finalPayload));
88
+ return [4 /*yield*/, (0, got_1.default)(url, ops)];
89
+ case 2:
90
+ response = _a.sent();
91
+ // const data = await response.json();
92
+ self.status({
93
+ fill: "green",
94
+ shape: "ring",
95
+ text: response.statusCode
96
+ });
97
+ try {
98
+ self.send([{
99
+ topic: msg.topic,
100
+ payload: response.body ? JSON.parse(response.body) : null
101
+ }, null]);
102
+ }
103
+ catch (e) {
104
+ self.send([null, {
105
+ topic: msg.topic,
106
+ payload: response.body
107
+ }]);
108
+ }
109
+ return [3 /*break*/, 4];
110
+ case 3:
111
+ error_1 = _a.sent();
112
+ self.status({
113
+ fill: "red",
114
+ shape: "ring",
115
+ text: error_1.message
116
+ });
117
+ self.send([{
118
+ topic: msg.topic,
119
+ payload: error_1.response.body ? JSON.parse(error_1.response.body) : { message: error_1.message }
120
+ }]);
121
+ return [3 /*break*/, 4];
122
+ case 4: return [3 /*break*/, 6];
123
+ case 5:
124
+ error_2 = _a.sent();
125
+ self.status({
126
+ fill: "red",
127
+ shape: "ring",
128
+ text: error_2.message
129
+ });
130
+ return [3 /*break*/, 6];
131
+ case 6: return [2 /*return*/];
132
+ }
133
+ });
134
+ });
135
+ });
136
+ }); };
137
+ exports.buildEventFunction = buildEventFunction;
138
+ //# sourceMappingURL=node-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-event.js","sourceRoot":"","sources":["../../src/nodes/node-event.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAAyC;AACzC,4CAAsB;AAEf,IAAM,kBAAkB,GAAG,UAAC,GAAQ,IAAK,OAAA,CAAC,SAAS,OAAO,CAAC,CAAc;IAC5E,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IACzB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC/B,IAAA,KAA4C,IAAI,CAAC,UAAU,EAA1D,WAAW,iBAAA,EAAE,MAAM,YAAA,EAAE,QAAQ,cAAA,EAAE,QAAQ,cAAmB,CAAC;IAClE,IAAM,IAAI,GAAG,IAAI,CAAC;IAClB,IAAI,OAAO,GAAG;QACV,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC;QACtB,WAAW,EAAE,CAAC,CAAC,WAAW,GAAG,CAAC;QAC9B,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAEtC,CAAA;IACD,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,UAAgB,GAAQ;;;;;;;wBAE3B,GAAG,GAAG,IAAA,gBAAQ,EAAC,WAAW,EAAE,MAAM,CAAC,GAAG,iCAAiC,CAAC;wBAC9E,IAAI,CAAC,MAAM,CAAC;4BACR,IAAI,EAAE,MAAM;4BACZ,KAAK,EAAE,MAAM;4BACb,IAA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AAE,QAAQ,CAAC,IAAI;iCACzB,CAAC,CAAC,CAAC;yBACP;;;;wBAGD,IAAI,CAAC,MAAM,CAAC;4BACR,IAAI,EAAE,KAAK;4BACX,KAAK,EAAE,MAAM;4BACb,IAAI,EAAE,OAAK,CAAC,OAAO;yBACtB,CAAC,CAAC;wBACH,IAAI,CAAC,IAAI,CAAC,CAAC;gCACP,KAAK,EAAE,GAAG,CAAC,KAAK;gCAChB,OAAO,EAAE,OAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,OAAK,CAAC,OAAO,EAAC;6BAC5F,CAAC,CAAC,CAAC;;;;;wBAIR,IAAI,CAAC,MAAM,CAAC;4BACR,IAAI,EAAE,KAAK;4BACX,KAAK,EAAE,MAAM;4BACb,IAAI,EAAE,OAAK,CAAC,OAAO;yBACtB,CAAC,CAAC;;;;;;KAEV,CAAC,CAAC;AACP,CAAC,CAAC,EA/E8C,CA+E9C,CAAA;AA/EW,QAAA,kBAAkB,sBA+E7B"}
@@ -5,19 +5,25 @@ var aws_iot_device_sdk_v2_1 = require("aws-iot-device-sdk-v2");
5
5
  var decoder = new TextDecoder('utf8');
6
6
  var buildNodeInFunction = function (RED) { return (function awsMqttNodeIn(n) {
7
7
  RED.nodes.createNode(this, n);
8
- this.myDevice = n.device;
9
- this.awsIot = RED.nodes.getNode(this.myDevice);
8
+ this.configurationNode = RED.nodes.getNode(n.device);
10
9
  var self = this;
11
- if (self.awsIot) {
10
+ self.broker = this.configurationNode.broker;
11
+ if (self.broker) {
12
12
  self.status({
13
13
  fill: "yellow",
14
14
  shape: "ring",
15
15
  text: "subscribing..."
16
16
  });
17
- self.awsIot.connect(null, null, function (event, error) {
17
+ self.broker.connect(null, null, function (event, error) {
18
18
  if (event == "connected") {
19
- var topic = self.awsIot.tenant + n.topic;
20
- self.awsIot.device.unsubscribe(topic);
19
+ var topic = self.broker.tenant + n.topic;
20
+ try {
21
+ self.broker.mqttClient.unsubscribe(topic);
22
+ }
23
+ catch (e) {
24
+ console.error('Error unsubscribing');
25
+ console.error(e);
26
+ }
21
27
  var onMessage = function (topic, payload, dup, qos, retain) {
22
28
  var json = JSON.parse(decoder.decode(payload));
23
29
  self.log("RECV< " + topic + JSON.stringify(json));
@@ -27,7 +33,7 @@ var buildNodeInFunction = function (RED) { return (function awsMqttNodeIn(n) {
27
33
  });
28
34
  };
29
35
  try {
30
- self.awsIot.device.subscribe(topic, aws_iot_device_sdk_v2_1.mqtt.QoS.AtLeastOnce, onMessage);
36
+ self.broker.mqttClient.subscribe(topic, aws_iot_device_sdk_v2_1.mqtt.QoS.AtLeastOnce, onMessage);
31
37
  self.status({
32
38
  fill: "green",
33
39
  shape: "ring",
@@ -40,7 +46,7 @@ var buildNodeInFunction = function (RED) { return (function awsMqttNodeIn(n) {
40
46
  shape: "ring",
41
47
  text: error.message
42
48
  });
43
- self.awsIot.device.on('message');
49
+ self.broker.mqttClient.on('message');
44
50
  }
45
51
  }
46
52
  else if (event == "error") {
@@ -1 +1 @@
1
- {"version":3,"file":"node-in.js","sourceRoot":"","sources":["../../src/nodes/node-in.ts"],"names":[],"mappings":";;;AACA,+DAA2C;AAE3C,IAAM,OAAO,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACjC,IAAM,mBAAmB,GAAG,UAAC,GAAQ,IAAK,OAAA,CAC7C,SAAS,aAAa,CAAC,CAAW;IAC9B,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IACzB,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAM,IAAI,GAAG,IAAI,CAAC;IAClB,IAAI,IAAI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O,QAAA,mBAAmB,uBA4E1B"}
@@ -4,15 +4,16 @@ exports.buildNodeOutFunction = void 0;
4
4
  var buildNodeOutFunction = function (RED) { return (function awsMqttNodeOut(n) {
5
5
  RED.nodes.createNode(this, n);
6
6
  this.myDevice = n.device;
7
- this.awsIot = RED.nodes.getNode(this.myDevice);
7
+ this.configuration = RED.nodes.getNode(this.myDevice);
8
+ this.broker = this.configuration.broker;
8
9
  var self = this;
9
10
  var options = {
10
11
  qos: parseInt(n.qos) || 0
11
12
  };
12
13
  self.on("input", function (msg) {
13
- if (self.awsIot) {
14
- self.awsIot.connect(msg.clientId, msg.reconnect, function (event, error) {
15
- if ((event == "ready" || event == "created")) {
14
+ if (self.broker) {
15
+ self.broker.connect(msg.clientId, msg.reconnect, function (event, error) {
16
+ if ((event == "connected")) {
16
17
  self.log("SEND> " + (msg.topic || n.topic) + " " + JSON.stringify(msg.payload));
17
18
  if (!Buffer.isBuffer(msg.payload)) {
18
19
  if (typeof msg.payload === "object") {
@@ -29,7 +30,7 @@ var buildNodeOutFunction = function (RED) { return (function awsMqttNodeOut(n) {
29
30
  text: "sending..."
30
31
  });
31
32
  try {
32
- self.awsIot.device.publish(msg.topic || n.topic, msg.payload, options.qos, false).then(function (result, error) {
33
+ self.broker.mqttClient.publish(msg.topic || n.topic, msg.payload, options.qos, false).then(function (result, error) {
33
34
  if (error) {
34
35
  self.status({
35
36
  fill: "red",
@@ -54,6 +55,14 @@ var buildNodeOutFunction = function (RED) { return (function awsMqttNodeOut(n) {
54
55
  });
55
56
  }
56
57
  }
58
+ if (event == 'error') {
59
+ self.error("connection error");
60
+ self.status({
61
+ fill: "red",
62
+ shape: "ring",
63
+ text: "not configured"
64
+ });
65
+ }
57
66
  });
58
67
  }
59
68
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"node-out.js","sourceRoot":"","sources":["../../src/nodes/node-out.ts"],"names":[],"mappings":";;;AAEO,IAAM,oBAAoB,GAAG,UAAC,GAAQ,IAAK,OAAA,CAC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E,KAAK;wBACX,KAAK,EAAE,MAAM;wBACb,IAAI,EAAE,gBAAgB;qBACzB,CAAC,CAAC;iBACN;YACL,CAAC,CAAC,CAAC;SACN;aAAM;YACH,IAAI,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;YAC7C,IAAI,CAAC,MAAM,CAAC;gBACR,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,MAAM;gBACb,IAAI,EAAE,gBAAgB;aACzB,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,EAtE4C,CAsE5C,CAAA;AAtEO,QAAA,oBAAoB,wBAsE3B"}
@@ -0,0 +1,2 @@
1
+ import { TilliTPv } from '../shared/types';
2
+ export declare const buildNodeProgressFunction: (RED: any) => (n: TilliTPv) => void;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildNodeProgressFunction = void 0;
4
+ var buildNodeProgressFunction = function (RED) { return (function awsMqttNodeProgress(n) {
5
+ RED.nodes.createNode(this, n);
6
+ this.connection = RED.nodes.getNode(n.device);
7
+ this.broker = this.connection.broker;
8
+ this.assetId = n.assetId;
9
+ var self = this;
10
+ var options = {
11
+ qos: 0
12
+ };
13
+ self.on("input", function (msg) {
14
+ try {
15
+ if (self.broker) {
16
+ self.broker.connect(msg.clientId, msg.reconnect, function (event, error) {
17
+ if ((event == "connected")) {
18
+ var topic = "$aws/rules/".concat(self.broker.environment, "_edge_data/").concat(self.broker.tenant, "/").concat(self.broker.clientId, "/order-progress");
19
+ var finalPayload = {
20
+ format: 'json', body: [Object.assign({
21
+ assetId: (1 * self.assetId > 0) ? (1 * self.assetId > 0) : msg.topic * 1,
22
+ timestamp: new Date().toISOString()
23
+ }, msg.payload)]
24
+ };
25
+ self.log("SEND> " + topic + ' ' + JSON.stringify(finalPayload));
26
+ var buffer = new Buffer(JSON.stringify(finalPayload), "utf-8");
27
+ self.status({
28
+ fill: "blue",
29
+ shape: "ring",
30
+ text: "sending..."
31
+ });
32
+ try {
33
+ self.broker.mqttClient.publish(topic, buffer, options.qos, false).then(function (result, error) {
34
+ if (error) {
35
+ self.status({
36
+ fill: "red",
37
+ shape: "ring",
38
+ text: error.message
39
+ });
40
+ }
41
+ else {
42
+ self.status({
43
+ fill: "green",
44
+ shape: "ring",
45
+ text: "done"
46
+ });
47
+ }
48
+ });
49
+ }
50
+ catch (e) {
51
+ self.status({
52
+ fill: "red",
53
+ shape: "ring",
54
+ text: e.message
55
+ });
56
+ }
57
+ }
58
+ if (event == 'error') {
59
+ self.error("connection error");
60
+ self.status({
61
+ fill: "red",
62
+ shape: "ring",
63
+ text: "connection error"
64
+ });
65
+ }
66
+ });
67
+ }
68
+ else {
69
+ self.error("connection is not configured");
70
+ self.status({
71
+ fill: "red",
72
+ shape: "ring",
73
+ text: "not configured"
74
+ });
75
+ }
76
+ }
77
+ catch (e) {
78
+ self.error("something went wrong", e);
79
+ self.status({
80
+ fill: "red",
81
+ shape: "ring",
82
+ text: e.message
83
+ });
84
+ }
85
+ });
86
+ }); };
87
+ exports.buildNodeProgressFunction = buildNodeProgressFunction;
88
+ //# sourceMappingURL=node-progress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-progress.js","sourceRoot":"","sources":["../../src/nodes/node-progress.ts"],"names":[],"mappings":";;;AAEO,IAAM,yBAAyB,GAAG,UAAC,GAAQ,IAAK,OAAA,CACnD,SAAS,mBAAmB,CAAC,CAAW;IACpC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IACrC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC;IACzB,IAAM,IAAI,GAAG,IAAI,CA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C;gBACR,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,MAAM;gBACb,IAAI,EAAE,CAAC,CAAC,OAAO;aAClB,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,EApFiD,CAoFjD,CAAA;AApFO,QAAA,yBAAyB,6BAoFhC"}
@@ -0,0 +1,2 @@
1
+ import { TilliTPv } from '../shared/types';
2
+ export declare const buildNodePvFunction: (RED: any) => (n: TilliTPv) => void;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildNodePvFunction = void 0;
4
+ var buildNodePvFunction = function (RED) { return (function awsMqttNodePv(n) {
5
+ RED.nodes.createNode(this, n);
6
+ this.myDevice = n.device;
7
+ this.configuration = RED.nodes.getNode(this.myDevice);
8
+ this.broker = this.configuration.broker;
9
+ var self = this;
10
+ var options = {
11
+ qos: 0
12
+ };
13
+ this.dataType = n.dataType;
14
+ var body = {
15
+ assetId: +n.assetId,
16
+ processVariableId: +n.processVariableId,
17
+ timestamp: new Date().toISOString()
18
+ };
19
+ self.on("input", function (msg) {
20
+ if (self.broker) {
21
+ self.broker.connect(msg.clientId, msg.reconnect, function (event, error) {
22
+ if ((event == "connected")) {
23
+ var topic = "$aws/rules/".concat(self.broker.environment, "_edge_data/").concat(self.broker.tenant, "/").concat(self.broker.clientId, "/timeseries");
24
+ if (body.assetId < 1)
25
+ body.assetId = msg.topic;
26
+ var payload = void 0;
27
+ if (typeof msg.payload === 'object') {
28
+ body = Object.assign(body, msg.payload);
29
+ }
30
+ else {
31
+ if (self.dataType === 'number') {
32
+ body['numericValue'] = msg.payload;
33
+ }
34
+ else if (self.dataType === 'string') {
35
+ body['stringValue'] = msg.payload;
36
+ }
37
+ else if (self.dataType === 'boolean') {
38
+ body['booleanValue'] = msg.payload;
39
+ }
40
+ }
41
+ var finalPayload = { format: 'json', body: [body] };
42
+ self.log("SEND> " + topic + ' ' + JSON.stringify(finalPayload));
43
+ var buffer = new Buffer(JSON.stringify(finalPayload), "utf-8");
44
+ self.status({
45
+ fill: "blue",
46
+ shape: "ring",
47
+ text: "sending..."
48
+ });
49
+ try {
50
+ self.broker.mqttClient.publish(topic, buffer, options.qos, false).then(function (result, error) {
51
+ if (error) {
52
+ self.status({
53
+ fill: "red",
54
+ shape: "ring",
55
+ text: error.message
56
+ });
57
+ }
58
+ else {
59
+ self.status({
60
+ fill: "green",
61
+ shape: "ring",
62
+ text: "done"
63
+ });
64
+ }
65
+ });
66
+ }
67
+ catch (e) {
68
+ self.status({
69
+ fill: "red",
70
+ shape: "ring",
71
+ text: e.message
72
+ });
73
+ }
74
+ }
75
+ if (event == 'error') {
76
+ self.error("connection error");
77
+ self.status({
78
+ fill: "red",
79
+ shape: "ring",
80
+ text: "connection error"
81
+ });
82
+ }
83
+ });
84
+ }
85
+ else {
86
+ self.error("connection is not configured");
87
+ self.status({
88
+ fill: "red",
89
+ shape: "ring",
90
+ text: "not configured"
91
+ });
92
+ }
93
+ });
94
+ }); };
95
+ exports.buildNodePvFunction = buildNodePvFunction;
96
+ //# sourceMappingURL=node-pv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-pv.js","sourceRoot":"","sources":["../../src/nodes/node-pv.ts"],"names":[],"mappings":";;;AAEO,IAAM,mBAAmB,GAAG,UAAC,GAAQ,IAAK,OAAA,CAC7C,SAAS,aAAa,CAAC,CAAW;IAC9B,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC;IACzB,IAAI,CAAC,aAAa,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;IACxC,IAAM,IAAI,GAAG,IAAI,CAAC;IAClB,IAAM,OAAO,GAAG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AAI,OAAO,EAAC;oBACjB,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;oBAC/B,IAAI,CAAC,MAAM,CAAC;wBACR,IAAI,EAAE,KAAK;wBACX,KAAK,EAAE,MAAM;wBACb,IAAI,EAAE,kBAAkB;qBAC3B,CAAC,CAAC;iBACN;YACL,CAAC,CAAC,CAAC;SACN;aAAM;YACH,IAAI,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;YAC5C,IAAI,CAAC,MAAM,CAAC;gBACR,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,MAAM;gBACb,IAAI,EAAE,gBAAgB;aACzB,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,EArF2C,CAqF3C,CAAA;AArFO,QAAA,mBAAmB,uBAqF1B"}
@@ -24,6 +24,18 @@ export interface TilliTOut {
24
24
  qos: string;
25
25
  device: string;
26
26
  }
27
+ export interface TilliTPv {
28
+ device: string;
29
+ assetId: number;
30
+ processVariableId: number;
31
+ dataType: string;
32
+ }
33
+ export interface TilliTEvent {
34
+ device: string;
35
+ assetId: number;
36
+ eventTypeId: number;
37
+ subtitle: string;
38
+ }
27
39
  export interface ApiCallNodeDef extends TilliTConnection {
28
40
  endpoint: string;
29
41
  method: 'POST' | 'GET' | 'PUT' | 'DELETE';
@@ -58,7 +58,7 @@
58
58
  category : 'config',
59
59
  defaults : {
60
60
  name : {
61
- value : "",
61
+ value : "tillit",
62
62
  required : true
63
63
  },
64
64
  thingId : {
@@ -128,10 +128,10 @@
128
128
  RED.nodes.registerType('tillit-out', {
129
129
  category : 'tillit',
130
130
  color : "#747ee2",
131
- paletteLabel: 'Publish',
131
+ paletteLabel: 'publish',
132
132
  defaults : {
133
133
  name: {
134
-
134
+ value: 'publish'
135
135
  },
136
136
  device : {
137
137
  type : "tillit-node-connection",
@@ -187,8 +187,11 @@
187
187
  RED.nodes.registerType('tillit-in', {
188
188
  category : 'tillit',
189
189
  color : "#747ee2",
190
- paletteLabel: 'Subscribe',
190
+ paletteLabel: 'subscribe',
191
191
  defaults : {
192
+ name:{
193
+ value: 'subscribe'
194
+ },
192
195
  device : {
193
196
  type : "tillit-node-connection",
194
197
  required : true
@@ -252,7 +255,7 @@
252
255
  <script type="text/javascript">
253
256
  RED.nodes.registerType('tillit-api', {
254
257
  category : 'tillit',
255
- paletteLabel: 'API Call',
258
+ paletteLabel: 'api call',
256
259
  color : "#747ee2",
257
260
  defaults : {
258
261
  device : {
@@ -260,7 +263,7 @@
260
263
  required : true
261
264
  },
262
265
  name : {
263
- value: 'API Call'
266
+ value: 'api'
264
267
  },
265
268
  endpoint : {
266
269
  value : "core/assets"
@@ -273,11 +276,246 @@
273
276
  outputs : 2,
274
277
  icon : "white-globe.png",
275
278
  align : "left",
276
- label : function() {
279
+ label: function () {
277
280
  var dbNode = RED.nodes.node(this.device);
278
- return this.name || ( dbNode ? dbNode.label() : this.name);
281
+ return this.name || (dbNode ? dbNode.label() : this.name);
279
282
  },
280
- labelStyle : function() {
283
+ labelStyle: function () {
284
+ return this.name ? "node_label_italic" : "";
285
+ }
286
+ });
287
+ </script>
288
+
289
+
290
+ <script type="text/x-red" data-help-name="tillit-pv">
291
+ <p>Publishes <b>msg.payload</b> to update the value of a process variable</p>
292
+ <p>msg.payload will be used as the value, respecting the data type selected</p>
293
+ <p>msg.topic will be used as assetId if you leave the configuration blank</p>
294
+ <p>For more information visit our help documentation: <a href="https://help.tillit.cloud/tillit/knowledge-base/setting-up-tillit/connecting-to-tillit/mqtt/publish-timeseries" target="blank">Open</a>
295
+
296
+ </script>
297
+
298
+
299
+ <script type="text/x-red" data-template-name="tillit-pv">
300
+ <div class="form-row">
301
+ <label for="node-input-device"><i class="fa fa-device"></i> Connection</label>
302
+ <input type="text" id="node-input-device">
303
+ </div>
304
+
305
+ <div class="form-row">
306
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
307
+ <input type="text" id="node-input-name" placeholder="Name">
308
+ </div>
309
+
310
+ <div class="form-row">
311
+ <label for="node-input-assetId"><i class="fa fa-tag"></i> Asset Id</label>
312
+ <input type="text" id="node-input-assetId" placeholder="will use msg.topic if blank">
313
+ </div>
314
+
315
+ <div class="form-row">
316
+ <label for="node-input-processVariableId"><i class="fa fa-tag"></i> Process Variable Id</label>
317
+ <input type="text" id="node-input-processVariableId" placeholder="">
318
+ </div>
319
+
320
+ <div class="form-row">
321
+ <label for="node-input-dataType"><i class="fa fa-tag"></i>Data Type</label>
322
+ <select id="node-input-dataType" style="width:125px !important">
323
+ <option value="number">NUMBER</option>
324
+ <option value="string">STRING</option>
325
+ <option value="boolean">BOOLEAN</option>
326
+ </select>
327
+ </div>
328
+
329
+
330
+ </script>
331
+
332
+ <script type="text/javascript">
333
+ RED.nodes.registerType('tillit-pv', {
334
+ category: 'tillit',
335
+ color: "#747ee2",
336
+ paletteLabel: 'process variable',
337
+ defaults: {
338
+ name: {
339
+ value: 'process variable'
340
+ },
341
+ device: {
342
+ type: "tillit-node-connection",
343
+ required: true
344
+ },
345
+ processVariableId: {},
346
+ assetId: {},
347
+ dataType: {
348
+ value: 'number'
349
+ },
350
+ },
351
+ inputs: 1,
352
+ outputs: 0,
353
+ icon: "bridge.png",
354
+ align: "right",
355
+ label: function () {
356
+ var dbNode = RED.nodes.node(this.device);
357
+ return this.name || (dbNode ? dbNode.label() : this.name);
358
+ },
359
+ labelStyle: function () {
360
+ return this.name ? "node_label_italic" : "";
361
+ }
362
+ });
363
+ </script>
364
+
365
+
366
+
367
+
368
+ <script type="text/x-red" data-help-name="tillit-event">
369
+ <p>Publishes <b>msg.payload</b> to raise an event</p>
370
+ <p>msg.topic can be used as assetId if you leave the node blank</p>
371
+ <p>msg.payload should be like the following example:</p>
372
+ <code>
373
+ {
374
+ assetId: number, //ID of the asset
375
+ timestamp: string, //Timestamp of the event
376
+ eventTypeId: number, //ID of the event to raise
377
+ orderId: number //The id of the order to raise event on (Optional)
378
+ orderNumber: string //The order number of the order to raise event on (Optional)
379
+ status: string //ACTIVE | SCHEDULED | COMPLETED (Optional)
380
+ subtitle: string //Set a description for the event (Optional)
381
+ }
382
+ </code>
383
+ This node will merge the settings from the node with the payload.
384
+ <p>For more information visit our help documentation: <a href="https://help.tillit.cloud/api/examples/raise-an-event-in-tillit" target="blank">Open</a>
385
+
386
+ </script>
387
+
388
+
389
+ <script type="text/x-red" data-template-name="tillit-event">
390
+ <div class="form-row">
391
+ <label for="node-input-device"><i class="fa fa-device"></i> Connection</label>
392
+ <input type="text" id="node-input-device">
393
+ </div>
394
+
395
+
396
+ <div class="form-row">
397
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
398
+ <input type="text" id="node-input-name" placeholder="Name">
399
+ </div>
400
+
401
+ <div class="form-row">
402
+ <label for="node-input-assetId"><i class="fa fa-tag"></i> Asset Id</label>
403
+ <input type="text" id="node-input-assetId" placeholder="Leave null and will use msg.topic or msg.payload.assetId">
404
+ </div>
405
+
406
+ <div class="form-row">
407
+ <label for="node-input-processVariableId"><i class="fa fa-tag"></i> Event Type Id</label>
408
+ <input type="text" id="node-input-eventTypeId" placeholder="Leave null and will use msg.payload.eventTypeId">
409
+ </div>
410
+
411
+
412
+ </script>
413
+
414
+ <script type="text/javascript">
415
+ RED.nodes.registerType('tillit-event', {
416
+ category: 'tillit',
417
+ color: "#747ee2",
418
+ paletteLabel: 'raise event',
419
+ defaults: {
420
+ name: {
421
+ value: 'raise event'
422
+ },
423
+ device: {
424
+ type: "tillit-node-connection",
425
+ required: true
426
+ },
427
+ eventTypeId: {},
428
+ assetId: {},
429
+ subtitle: {},
430
+ },
431
+ inputs: 1,
432
+ outputs: 1,
433
+ icon: "bridge.png",
434
+ align: "right",
435
+ label: function () {
436
+ var dbNode = RED.nodes.node(this.device);
437
+ return this.name || (dbNode ? dbNode.label() : this.name);
438
+ },
439
+ labelStyle: function () {
440
+ return this.name ? "node_label_italic" : "";
441
+ }
442
+ });
443
+ </script>
444
+
445
+
446
+
447
+
448
+ <script type="text/x-red" data-help-name="tillit-progress">
449
+ <p>Publishes <b>msg.payload</b> to update the asset progress</p>
450
+ <code>
451
+ [{
452
+ assetId: number,
453
+ orderId: number, //Is optional, if not supplied then the current running order is used.
454
+ timestamp: string,
455
+ totalCount: number,
456
+ rejectCount: number,
457
+ EQUIPMENT_STATUS_READY: boolean,
458
+ EQUIPMENT_STATUS_RUNNING: boolean,
459
+ EQUIPMENT_STATUS_STOPPED: boolean,
460
+ EQUIPMENT_STATUS_COMPLETE: boolean,
461
+ EQUIPMENT_STATUS_SUSPENDED: boolean,
462
+ EQUIPMENT_STATUS_ABORTED: boolean,
463
+ EQUIPMENT_STATUS_STARVED: boolean,
464
+ EQUIPMENT_STATUS_BLOCKED: boolean,
465
+ EQUIPMENT_STATUS_FAULTED: boolean,
466
+ downtimeReason: string,
467
+ reasonGroupId: number
468
+ }]
469
+ </code>
470
+ <p>msg.topic will be used as assetId if you leave the configuration blank</p>
471
+ <p>For more information visit our help documentation: <a href="https://help.tillit.cloud/tillit/knowledge-base/setting-up-tillit/connecting-to-tillit/mqtt/publish-timeseries" target="blank">Open</a>
472
+
473
+ </script>
474
+
475
+
476
+ <script type="text/x-red" data-template-name="tillit-progress">
477
+ <div class="form-row">
478
+ <label for="node-input-device"><i class="fa fa-device"></i> Connection</label>
479
+ <input type="text" id="node-input-device">
480
+ </div>
481
+
482
+
483
+ <div class="form-row">
484
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
485
+ <input type="text" id="node-input-name" placeholder="Name">
486
+ </div>
487
+
488
+ <div class="form-row">
489
+ <label for="node-input-assetId"><i class="fa fa-tag"></i> Asset Id</label>
490
+ <input type="text" id="node-input-assetId" placeholder="will use msg.topic if blank">
491
+ </div>
492
+
493
+ </script>
494
+
495
+ <script type="text/javascript">
496
+ RED.nodes.registerType('tillit-progress', {
497
+ category: 'tillit',
498
+ color: "#747ee2",
499
+ paletteLabel: 'progress',
500
+ defaults: {
501
+ name: {
502
+ value: 'progress'
503
+ },
504
+ device: {
505
+ type: "tillit-node-connection",
506
+ required: true
507
+ },
508
+ assetId: {},
509
+ },
510
+ inputs: 1,
511
+ outputs: 0,
512
+ icon: "bridge.png",
513
+ align: "right",
514
+ label: function () {
515
+ var dbNode = RED.nodes.node(this.device);
516
+ return this.name || (dbNode ? dbNode.label() : this.name);
517
+ },
518
+ labelStyle: function () {
281
519
  return this.name ? "node_label_italic" : "";
282
520
  }
283
521
  });
@@ -4,10 +4,16 @@ var node_api_1 = require("./nodes/node-api");
4
4
  var node_out_1 = require("./nodes/node-out");
5
5
  var node_in_1 = require("./nodes/node-in");
6
6
  var node_broker_1 = require("./nodes/node-broker");
7
+ var node_pv_1 = require("./nodes/node-pv");
8
+ var node_event_1 = require("./nodes/node-event");
9
+ var node_progress_1 = require("./nodes/node-progress");
7
10
  module.exports = function (RED) {
11
+ RED.nodes.registerType("tillit-node-connection", (0, node_broker_1.buildNodeBrokerFunction)(RED));
8
12
  RED.nodes.registerType("tillit-api", (0, node_api_1.buildApiFunction)(RED));
9
13
  RED.nodes.registerType("tillit-out", (0, node_out_1.buildNodeOutFunction)(RED));
14
+ RED.nodes.registerType("tillit-pv", (0, node_pv_1.buildNodePvFunction)(RED));
15
+ RED.nodes.registerType("tillit-progress", (0, node_progress_1.buildNodeProgressFunction)(RED));
10
16
  RED.nodes.registerType("tillit-in", (0, node_in_1.buildNodeInFunction)(RED));
11
- RED.nodes.registerType("tillit-node-connection", (0, node_broker_1.buildNodeBrokerFunction)(RED));
17
+ RED.nodes.registerType("tillit-event", (0, node_event_1.buildEventFunction)(RED));
12
18
  };
13
19
  //# sourceMappingURL=tillit-node.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tillit-node.js","sourceRoot":"","sources":["../src/tillit-node.ts"],"names":[],"mappings":";;AAAA,6CAAkD;AAClD,6CAAsD;AACtD,2CAAoD;AACpD,mDAA4D;AAE5D,MAAM,CAAC,OAAO,GAAG,UAAU,GAAQ;IAG/B,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC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,YAAY,CAAC,cAAc,EAAE,IAAA,+BAAkB,EAAC,GAAG,CAAC,CAAC,CAAC;AAGpE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gotillit/tillit-node-red",
3
- "version": "1.1.14",
3
+ "version": "1.2.1",
4
4
  "description": "A TilliT node for Node-RED",
5
5
  "main": "./dist/index.js",
6
6
  "dependencies": {