@wiotp/sdk 0.4.2 → 0.6.2

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.
Files changed (48) hide show
  1. package/LICENSE +203 -203
  2. package/README.md +68 -68
  3. package/dist/BaseClient.js +259 -0
  4. package/dist/BaseConfig.js +194 -0
  5. package/dist/api/ApiClient.js +508 -0
  6. package/dist/api/ApiErrors.js +118 -0
  7. package/dist/api/DscClient.js +332 -0
  8. package/dist/api/LecClient.js +48 -0
  9. package/dist/api/MgmtClient.js +77 -0
  10. package/dist/api/RegistryClient.js +234 -0
  11. package/dist/api/RulesClient.js +105 -0
  12. package/dist/api/StateClient.js +738 -0
  13. package/dist/application/ApplicationClient.js +436 -0
  14. package/dist/application/ApplicationConfig.js +233 -0
  15. package/dist/application/index.js +23 -0
  16. package/dist/bundled/wiotp-bundle.js +35592 -0
  17. package/dist/bundled/wiotp-bundle.min.js +47 -0
  18. package/dist/device/DeviceClient.js +125 -0
  19. package/dist/device/DeviceConfig.js +216 -0
  20. package/dist/device/index.js +23 -0
  21. package/dist/gateway/GatewayClient.js +159 -0
  22. package/dist/gateway/GatewayConfig.js +52 -0
  23. package/dist/gateway/index.js +23 -0
  24. package/dist/index.js +55 -0
  25. package/dist/util.js +50 -0
  26. package/package.json +92 -84
  27. package/src/BaseClient.js +215 -215
  28. package/src/BaseConfig.js +157 -157
  29. package/src/api/ApiClient.js +454 -454
  30. package/src/api/ApiErrors.js +33 -33
  31. package/src/api/DscClient.js +164 -145
  32. package/src/api/LecClient.js +32 -32
  33. package/src/api/MgmtClient.js +57 -57
  34. package/src/api/RegistryClient.js +194 -194
  35. package/src/api/RulesClient.js +84 -84
  36. package/src/api/StateClient.js +650 -650
  37. package/src/application/ApplicationClient.js +348 -348
  38. package/src/application/ApplicationConfig.js +191 -191
  39. package/src/application/index.js +12 -12
  40. package/src/device/DeviceClient.js +78 -78
  41. package/src/device/DeviceConfig.js +175 -175
  42. package/src/device/index.js +14 -14
  43. package/src/gateway/GatewayClient.js +114 -114
  44. package/src/gateway/GatewayConfig.js +21 -21
  45. package/src/gateway/index.js +13 -13
  46. package/{index.js → src/index.js} +19 -19
  47. package/src/util.js +38 -38
  48. package/src/util/IoTFoundation.pem +0 -82
@@ -1,349 +1,349 @@
1
- /**
2
- *****************************************************************************
3
- Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
4
- All rights reserved. This program and the accompanying materials
5
- are made available under the terms of the Eclipse Public License v1.0
6
- which accompanies this distribution, and is available at
7
- http://www.eclipse.org/legal/epl-v10.html
8
- *****************************************************************************
9
- *
10
- */
11
- import { isDefined } from '../util';
12
- import { default as BaseClient } from '../BaseClient';
13
- import { default as ApiClient } from '../api/ApiClient';
14
- import { default as RegistryClient } from '../api/RegistryClient';
15
- import { default as MgmtClient } from '../api/MgmtClient';
16
- import { default as LecClient } from '../api/LecClient';
17
- import { default as DscClient } from '../api/DscClient';
18
- import { default as RulesClient } from '../api/RulesClient';
19
- import { default as StateClient } from '../api/StateClient';
20
-
21
- import { default as ApplicationConfig } from './ApplicationConfig';
22
-
23
- const DEVICE_EVT_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/evt\/(.+)\/fmt\/(.+)$/;
24
- const DEVICE_CMD_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/cmd\/(.+)\/fmt\/(.+)$/;
25
- const DEVICE_STATE_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/intf\/(.+)\/evt\/state$/;
26
- const DEVICE_STATE_ERROR_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/err\/data$/;
27
- const RULE_TRIGGER_RE = /^iot-2\/intf\/(.+)\/rule\/(.+)\/evt\/trigger$/;
28
- const RULE_ERROR_RE = /^iot-2\/intf\/(.+)\/rule\/(.+)\/err\/data$/;
29
- const DEVICE_MON_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/mon$/;
30
- const APP_MON_RE = /^iot-2\/app\/(.+)\/mon$/;
31
-
32
- export default class ApplicationClient extends BaseClient {
33
- constructor(config) {
34
- if (!config instanceof ApplicationConfig) {
35
- throw new Error("Config must be an instance of ApplicationConfig");
36
- }
37
- super(config);
38
- this.useLtpa = config.auth && config.auth.useLtpa;
39
-
40
- if ((config.auth && config.auth.useLtpa) || config.getOrgId() != "quickstart") {
41
- this._apiClient = new ApiClient(this.config);
42
-
43
- this.dsc = new DscClient(this._apiClient);
44
- this.lec = new LecClient(this._apiClient);
45
- this.mgmt = new MgmtClient(this._apiClient);
46
- this.registry = new RegistryClient(this._apiClient);
47
- this.rules = new RulesClient(this._apiClient);
48
- this.state = new StateClient(this._apiClient);
49
- }
50
-
51
- this.log.debug("[ApplicationClient:constructor] ApplicationClient initialized for organization : " + config.getOrgId());
52
- }
53
-
54
-
55
- connect() {
56
- super.connect();
57
-
58
- this.mqtt.on('message', (topic, payload) => {
59
- this.log.trace("[ApplicationClient:onMessage] mqtt: ", topic, payload.toString());
60
-
61
- // For each type of registered callback, check the incoming topic against a Regexp.
62
- // If matches, forward the payload and various fields from the topic (extracted using groups in the regexp)
63
-
64
- var match = DEVICE_EVT_RE.exec(topic);
65
- if (match) {
66
- this.emit('deviceEvent', match[1], match[2], match[3], match[4], payload, topic);
67
- return;
68
- }
69
-
70
-
71
- var match = DEVICE_CMD_RE.exec(topic);
72
- if (match) {
73
- this.emit('deviceCommand', match[1], match[2], match[3], match[4], payload, topic);
74
- return;
75
- }
76
-
77
- var match = DEVICE_STATE_RE.exec(topic);
78
- if(match){
79
- this.emit('deviceState', match[1], match[2], match[3], payload, topic);
80
- return;
81
- }
82
-
83
- var match = DEVICE_STATE_ERROR_RE.exec(topic);
84
- if(match){
85
- this.emit('deviceStateError', match[1], match[2], payload, topic);
86
- return;
87
- }
88
-
89
- var match = RULE_TRIGGER_RE.exec(topic);
90
- if(match){
91
- this.emit('ruleTrigger', match[1], match[2], payload, topic);
92
- return;
93
- }
94
-
95
- var match = RULE_ERROR_RE.exec(topic);
96
- if(match){
97
- this.emit('ruleError', match[1], match[2], payload, topic);
98
- return;
99
- }
100
-
101
- var match = DEVICE_MON_RE.exec(topic);
102
- if (match) {
103
- this.emit('deviceStatus', match[1], match[2], payload, topic);
104
- return;
105
- }
106
-
107
- var match = APP_MON_RE.exec(topic);
108
- if (match) {
109
- this.emit('appStatus', match[1], payload, topic);
110
- return;
111
- }
112
-
113
- // catch all which logs the receipt of an unexpected message
114
- this.log.warn("[ApplicationClient:onMessage] Message received on unexpected topic" + ", " + topic + ", " + payload);
115
- });
116
- }
117
-
118
-
119
- // ==========================================================================
120
- // Device Events
121
- // ==========================================================================
122
-
123
- publishEvent(typeId, deviceId, eventId, format, data, qos, callback) {
124
- qos = qos || 0;
125
- if (!isDefined(typeId) || !isDefined(deviceId) || !isDefined(eventId) || !isDefined(format)) {
126
- this.log.error("[ApplicationClient:publishDeviceEvent] Required params for publishDeviceEvent not present");
127
- this.emit('error', "[ApplicationClient:publishDeviceEvent] Required params for publishDeviceEvent not present");
128
- return;
129
- }
130
- var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/evt/" + eventId + "/fmt/" + format;
131
- this._publish(topic, data, qos, callback);
132
- return this;
133
- }
134
-
135
- subscribeToEvents(typeId, deviceId, eventId, format, qos, callback) {
136
- typeId = typeId || '+';
137
- deviceId = deviceId || '+';
138
- eventId = eventId || '+';
139
- format = format || '+';
140
- qos = qos || 0;
141
-
142
- var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/evt/" + eventId + "/fmt/" + format;
143
- this._subscribe(topic, qos, callback);
144
- return this;
145
- }
146
-
147
- unsubscribeFromEvents(typeId, deviceId, eventId, format) {
148
- typeId = typeId || '+';
149
- deviceId = deviceId || '+';
150
- eventId = eventId || '+';
151
- format = format || '+';
152
-
153
- var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/evt/" + eventId + "/fmt/" + format;
154
- this._unsubscribe(topic, callback);
155
- return this;
156
- }
157
-
158
-
159
- // ==========================================================================
160
- // Device Commands
161
- // ==========================================================================
162
-
163
- publishCommand(typeId, deviceId, commandId, format, data, qos, callback) {
164
- qos = qos || 0;
165
- if (!isDefined(typeId) || !isDefined(deviceId) || !isDefined(commandId) || !isDefined(format)) {
166
- this.log.error("[ApplicationClient:publishDeviceCommand] Required params for publishDeviceCommand not present");
167
- this.emit('error', "[ApplicationClient:publishDeviceCommand] Required params for publishDeviceCommand not present");
168
- return;
169
- }
170
- var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/cmd/" + commandId + "/fmt/" + format;
171
- this._publish(topic, data, qos, callback);
172
- return this;
173
- }
174
-
175
- subscribeToCommands(typeId, deviceId, commandId, format, qos, callback){
176
- typeId = typeId || '+';
177
- deviceId = deviceId || '+';
178
- commandId = commandId || '+';
179
- format = format || '+';
180
- qos = qos || 0;
181
-
182
- var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/cmd/" + commandId + "/fmt/" + format;
183
- this.log.debug("[ApplicationClient:subscribeToDeviceCommands] Calling subscribe with QoS " + qos);
184
- this._subscribe(topic, qos, callback);
185
- return this;
186
- }
187
-
188
- unsubscribeFromCommands(typeId, deviceId, commandId, format, callback) {
189
- typeId = typeId || '+';
190
- deviceId = deviceId || '+';
191
- commandId = commandId || '+';
192
- format = format || '+';
193
-
194
- var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/cmd/" + commandId + "/fmt/" + format;
195
- this._unsubscribe(topic, callback);
196
- return this;
197
- }
198
-
199
-
200
- // ==========================================================================
201
- // Device State Events
202
- // ==========================================================================
203
-
204
- subscribeToDeviceState(type, id, interfaceId, qos){
205
- type = type || '+';
206
- id = id || '+';
207
- interfaceId = interfaceId || '+';
208
- qos = qos || 0;
209
-
210
- var topic = "iot-2/type/" + type + "/id/" + id + "/intf/"+ interfaceId + "/evt/state";
211
- this.log.debug("[ApplicationClient:subscribeToDeviceState] Calling subscribe with QoS "+qos);
212
- this._subscribe(topic, qos);
213
- return this;
214
- }
215
-
216
- unsubscribeToDeviceState(type, id, interfaceId){
217
- type = type || '+';
218
- id = id || '+';
219
- interfaceId = interfaceId || '+';
220
-
221
- var topic = "iot-2/type/" + type + "/id/" + id + "/intf/"+ interfaceId + "/evt/state";
222
- this._unsubscribe(topic);
223
- return this;
224
- }
225
-
226
-
227
- // ==========================================================================
228
- // Device State Errors
229
- // ==========================================================================
230
-
231
- subscribeToDeviceErrors(type, id, qos){
232
- type = type || '+';
233
- id = id || '+';
234
- qos = qos || 0;
235
-
236
- var topic = "iot-2/type/" + type + "/id/" + id + "/err/data";
237
- this.log.debug("[ApplicationClient:subscribeToDeviceErrors] Calling subscribe with QoS "+qos);
238
- this._subscribe(topic, qos);
239
- return this;
240
- }
241
-
242
- unsubscribeToDeviceErrors(type, id){
243
- type = type || '+';
244
- id = id || '+';
245
-
246
- var topic = "iot-2/type/" + type + "/id/" + id + "/err/data";
247
- this._unsubscribe(topic);
248
- return this;
249
- }
250
-
251
-
252
- // ==========================================================================
253
- // Rule Triggers
254
- // ==========================================================================
255
-
256
- subscribeToRuleTriggers(interfaceId, ruleId, qos){
257
- interfaceId = interfaceId || '+';
258
- ruleId = ruleId || '+';
259
- qos = qos || 0;
260
-
261
- var topic = "iot-2/intf/" + interfaceId + "/rule/" + ruleId + "/evt/trigger";
262
- this.log.debug("[ApplicationClient:subscribeToRuleTriggers] Calling subscribe with QoS "+qos);
263
- this._subscribe(topic, qos);
264
- return this;
265
- }
266
-
267
- unsubscribeToRuleTriggers(interfaceId, ruleId){
268
- interfaceId = interfaceId || '+';
269
- ruleId = ruleId || '+';
270
-
271
- var topic = "iot-2/intf/" + interfaceId + "/rule/" + ruleId + "/evt/trigger";
272
- this._unsubscribe(topic);
273
- return this;
274
- }
275
-
276
-
277
- // ==========================================================================
278
- // Rule Trigger Errors
279
- // ==========================================================================
280
-
281
- subscribeToRuleErrors(interfaceId, ruleId, qos){
282
- interfaceId = interfaceId || '+';
283
- ruleId = ruleId || '+';
284
- qos = qos || 0;
285
-
286
- var topic = "iot-2/intf/" + interfaceId + "/rule/" + ruleId + "/err/data";
287
- this.log.debug("[ApplicationClient:subscribeToRuleErrors] Calling subscribe with QoS "+qos);
288
- this._subscribe(topic, qos);
289
- return this;
290
- }
291
-
292
- unsubscribeToRuleErrors(interfaceId, ruleId){
293
- interfaceId = interfaceId || '+';
294
- ruleId = ruleId || '+';
295
-
296
- var topic = "iot-2/intf/" + interfaceId + "/rule/" + ruleId + "/err/data";
297
- this._unsubscribe(topic);
298
- return this;
299
- }
300
-
301
-
302
- // ==========================================================================
303
- // Device Status
304
- // ==========================================================================
305
-
306
- subscribeToDeviceStatus(type, id, qos) {
307
- type = type || '+';
308
- id = id || '+';
309
- qos = qos || 0;
310
-
311
- var topic = "iot-2/type/" + type + "/id/" + id + "/mon";
312
- this.log.debug("[ApplicationClient:subscribeToDeviceStatus] Calling subscribe with QoS " + qos);
313
- this._subscribe(topic, qos);
314
- return this;
315
- }
316
-
317
- unsubscribeToDeviceStatus(type, id) {
318
- type = type || '+';
319
- id = id || '+';
320
-
321
- var topic = "iot-2/type/" + type + "/id/" + id + "/mon";
322
- this._unsubscribe(topic);
323
- return this;
324
- }
325
-
326
- // ==========================================================================
327
- // Application Status
328
- // ==========================================================================
329
-
330
- subscribeToAppStatus(id, qos) {
331
- id = id || '+';
332
- qos = qos || 0;
333
-
334
- var topic = "iot-2/app/" + id + "/mon";
335
- this.log.debug("[ApplicationClient:subscribeToAppStatus] Calling subscribe with QoS " + qos);
336
- this._subscribe(topic, qos);
337
- return this;
338
- }
339
-
340
- unsubscribeToAppStatus(id) {
341
- id = id || '+';
342
-
343
- var topic = "iot-2/app/" + id + "/mon";
344
- this._unsubscribe(topic);
345
-
346
- return this;
347
- }
348
-
1
+ /**
2
+ *****************************************************************************
3
+ Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
4
+ All rights reserved. This program and the accompanying materials
5
+ are made available under the terms of the Eclipse Public License v1.0
6
+ which accompanies this distribution, and is available at
7
+ http://www.eclipse.org/legal/epl-v10.html
8
+ *****************************************************************************
9
+ *
10
+ */
11
+ import { isDefined } from '../util';
12
+ import { default as BaseClient } from '../BaseClient';
13
+ import { default as ApiClient } from '../api/ApiClient';
14
+ import { default as RegistryClient } from '../api/RegistryClient';
15
+ import { default as MgmtClient } from '../api/MgmtClient';
16
+ import { default as LecClient } from '../api/LecClient';
17
+ import { default as DscClient } from '../api/DscClient';
18
+ import { default as RulesClient } from '../api/RulesClient';
19
+ import { default as StateClient } from '../api/StateClient';
20
+
21
+ import { default as ApplicationConfig } from './ApplicationConfig';
22
+
23
+ const DEVICE_EVT_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/evt\/(.+)\/fmt\/(.+)$/;
24
+ const DEVICE_CMD_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/cmd\/(.+)\/fmt\/(.+)$/;
25
+ const DEVICE_STATE_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/intf\/(.+)\/evt\/state$/;
26
+ const DEVICE_STATE_ERROR_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/err\/data$/;
27
+ const RULE_TRIGGER_RE = /^iot-2\/intf\/(.+)\/rule\/(.+)\/evt\/trigger$/;
28
+ const RULE_ERROR_RE = /^iot-2\/intf\/(.+)\/rule\/(.+)\/err\/data$/;
29
+ const DEVICE_MON_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/mon$/;
30
+ const APP_MON_RE = /^iot-2\/app\/(.+)\/mon$/;
31
+
32
+ export default class ApplicationClient extends BaseClient {
33
+ constructor(config) {
34
+ if (!config instanceof ApplicationConfig) {
35
+ throw new Error("Config must be an instance of ApplicationConfig");
36
+ }
37
+ super(config);
38
+ this.useLtpa = config.auth && config.auth.useLtpa;
39
+
40
+ if ((config.auth && config.auth.useLtpa) || config.getOrgId() != "quickstart") {
41
+ this._apiClient = new ApiClient(this.config);
42
+
43
+ this.dsc = new DscClient(this._apiClient);
44
+ this.lec = new LecClient(this._apiClient);
45
+ this.mgmt = new MgmtClient(this._apiClient);
46
+ this.registry = new RegistryClient(this._apiClient);
47
+ this.rules = new RulesClient(this._apiClient);
48
+ this.state = new StateClient(this._apiClient);
49
+ }
50
+
51
+ this.log.debug("[ApplicationClient:constructor] ApplicationClient initialized for organization : " + config.getOrgId());
52
+ }
53
+
54
+
55
+ connect() {
56
+ super.connect();
57
+
58
+ this.mqtt.on('message', (topic, payload) => {
59
+ this.log.trace("[ApplicationClient:onMessage] mqtt: ", topic, payload.toString());
60
+
61
+ // For each type of registered callback, check the incoming topic against a Regexp.
62
+ // If matches, forward the payload and various fields from the topic (extracted using groups in the regexp)
63
+
64
+ var match = DEVICE_EVT_RE.exec(topic);
65
+ if (match) {
66
+ this.emit('deviceEvent', match[1], match[2], match[3], match[4], payload, topic);
67
+ return;
68
+ }
69
+
70
+
71
+ var match = DEVICE_CMD_RE.exec(topic);
72
+ if (match) {
73
+ this.emit('deviceCommand', match[1], match[2], match[3], match[4], payload, topic);
74
+ return;
75
+ }
76
+
77
+ var match = DEVICE_STATE_RE.exec(topic);
78
+ if(match){
79
+ this.emit('deviceState', match[1], match[2], match[3], payload, topic);
80
+ return;
81
+ }
82
+
83
+ var match = DEVICE_STATE_ERROR_RE.exec(topic);
84
+ if(match){
85
+ this.emit('deviceStateError', match[1], match[2], payload, topic);
86
+ return;
87
+ }
88
+
89
+ var match = RULE_TRIGGER_RE.exec(topic);
90
+ if(match){
91
+ this.emit('ruleTrigger', match[1], match[2], payload, topic);
92
+ return;
93
+ }
94
+
95
+ var match = RULE_ERROR_RE.exec(topic);
96
+ if(match){
97
+ this.emit('ruleError', match[1], match[2], payload, topic);
98
+ return;
99
+ }
100
+
101
+ var match = DEVICE_MON_RE.exec(topic);
102
+ if (match) {
103
+ this.emit('deviceStatus', match[1], match[2], payload, topic);
104
+ return;
105
+ }
106
+
107
+ var match = APP_MON_RE.exec(topic);
108
+ if (match) {
109
+ this.emit('appStatus', match[1], payload, topic);
110
+ return;
111
+ }
112
+
113
+ // catch all which logs the receipt of an unexpected message
114
+ this.log.warn("[ApplicationClient:onMessage] Message received on unexpected topic" + ", " + topic + ", " + payload);
115
+ });
116
+ }
117
+
118
+
119
+ // ==========================================================================
120
+ // Device Events
121
+ // ==========================================================================
122
+
123
+ publishEvent(typeId, deviceId, eventId, format, data, qos, callback) {
124
+ qos = qos || 0;
125
+ if (!isDefined(typeId) || !isDefined(deviceId) || !isDefined(eventId) || !isDefined(format)) {
126
+ this.log.error("[ApplicationClient:publishDeviceEvent] Required params for publishDeviceEvent not present");
127
+ this.emit('error', "[ApplicationClient:publishDeviceEvent] Required params for publishDeviceEvent not present");
128
+ return;
129
+ }
130
+ var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/evt/" + eventId + "/fmt/" + format;
131
+ this._publish(topic, data, qos, callback);
132
+ return this;
133
+ }
134
+
135
+ subscribeToEvents(typeId, deviceId, eventId, format, qos, callback) {
136
+ typeId = typeId || '+';
137
+ deviceId = deviceId || '+';
138
+ eventId = eventId || '+';
139
+ format = format || '+';
140
+ qos = qos || 0;
141
+
142
+ var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/evt/" + eventId + "/fmt/" + format;
143
+ this._subscribe(topic, qos, callback);
144
+ return this;
145
+ }
146
+
147
+ unsubscribeFromEvents(typeId, deviceId, eventId, format) {
148
+ typeId = typeId || '+';
149
+ deviceId = deviceId || '+';
150
+ eventId = eventId || '+';
151
+ format = format || '+';
152
+
153
+ var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/evt/" + eventId + "/fmt/" + format;
154
+ this._unsubscribe(topic, callback);
155
+ return this;
156
+ }
157
+
158
+
159
+ // ==========================================================================
160
+ // Device Commands
161
+ // ==========================================================================
162
+
163
+ publishCommand(typeId, deviceId, commandId, format, data, qos, callback) {
164
+ qos = qos || 0;
165
+ if (!isDefined(typeId) || !isDefined(deviceId) || !isDefined(commandId) || !isDefined(format)) {
166
+ this.log.error("[ApplicationClient:publishDeviceCommand] Required params for publishDeviceCommand not present");
167
+ this.emit('error', "[ApplicationClient:publishDeviceCommand] Required params for publishDeviceCommand not present");
168
+ return;
169
+ }
170
+ var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/cmd/" + commandId + "/fmt/" + format;
171
+ this._publish(topic, data, qos, callback);
172
+ return this;
173
+ }
174
+
175
+ subscribeToCommands(typeId, deviceId, commandId, format, qos, callback){
176
+ typeId = typeId || '+';
177
+ deviceId = deviceId || '+';
178
+ commandId = commandId || '+';
179
+ format = format || '+';
180
+ qos = qos || 0;
181
+
182
+ var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/cmd/" + commandId + "/fmt/" + format;
183
+ this.log.debug("[ApplicationClient:subscribeToDeviceCommands] Calling subscribe with QoS " + qos);
184
+ this._subscribe(topic, qos, callback);
185
+ return this;
186
+ }
187
+
188
+ unsubscribeFromCommands(typeId, deviceId, commandId, format, callback) {
189
+ typeId = typeId || '+';
190
+ deviceId = deviceId || '+';
191
+ commandId = commandId || '+';
192
+ format = format || '+';
193
+
194
+ var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/cmd/" + commandId + "/fmt/" + format;
195
+ this._unsubscribe(topic, callback);
196
+ return this;
197
+ }
198
+
199
+
200
+ // ==========================================================================
201
+ // Device State Events
202
+ // ==========================================================================
203
+
204
+ subscribeToDeviceState(type, id, interfaceId, qos){
205
+ type = type || '+';
206
+ id = id || '+';
207
+ interfaceId = interfaceId || '+';
208
+ qos = qos || 0;
209
+
210
+ var topic = "iot-2/type/" + type + "/id/" + id + "/intf/"+ interfaceId + "/evt/state";
211
+ this.log.debug("[ApplicationClient:subscribeToDeviceState] Calling subscribe with QoS "+qos);
212
+ this._subscribe(topic, qos);
213
+ return this;
214
+ }
215
+
216
+ unsubscribeToDeviceState(type, id, interfaceId){
217
+ type = type || '+';
218
+ id = id || '+';
219
+ interfaceId = interfaceId || '+';
220
+
221
+ var topic = "iot-2/type/" + type + "/id/" + id + "/intf/"+ interfaceId + "/evt/state";
222
+ this._unsubscribe(topic);
223
+ return this;
224
+ }
225
+
226
+
227
+ // ==========================================================================
228
+ // Device State Errors
229
+ // ==========================================================================
230
+
231
+ subscribeToDeviceErrors(type, id, qos){
232
+ type = type || '+';
233
+ id = id || '+';
234
+ qos = qos || 0;
235
+
236
+ var topic = "iot-2/type/" + type + "/id/" + id + "/err/data";
237
+ this.log.debug("[ApplicationClient:subscribeToDeviceErrors] Calling subscribe with QoS "+qos);
238
+ this._subscribe(topic, qos);
239
+ return this;
240
+ }
241
+
242
+ unsubscribeToDeviceErrors(type, id){
243
+ type = type || '+';
244
+ id = id || '+';
245
+
246
+ var topic = "iot-2/type/" + type + "/id/" + id + "/err/data";
247
+ this._unsubscribe(topic);
248
+ return this;
249
+ }
250
+
251
+
252
+ // ==========================================================================
253
+ // Rule Triggers
254
+ // ==========================================================================
255
+
256
+ subscribeToRuleTriggers(interfaceId, ruleId, qos){
257
+ interfaceId = interfaceId || '+';
258
+ ruleId = ruleId || '+';
259
+ qos = qos || 0;
260
+
261
+ var topic = "iot-2/intf/" + interfaceId + "/rule/" + ruleId + "/evt/trigger";
262
+ this.log.debug("[ApplicationClient:subscribeToRuleTriggers] Calling subscribe with QoS "+qos);
263
+ this._subscribe(topic, qos);
264
+ return this;
265
+ }
266
+
267
+ unsubscribeToRuleTriggers(interfaceId, ruleId){
268
+ interfaceId = interfaceId || '+';
269
+ ruleId = ruleId || '+';
270
+
271
+ var topic = "iot-2/intf/" + interfaceId + "/rule/" + ruleId + "/evt/trigger";
272
+ this._unsubscribe(topic);
273
+ return this;
274
+ }
275
+
276
+
277
+ // ==========================================================================
278
+ // Rule Trigger Errors
279
+ // ==========================================================================
280
+
281
+ subscribeToRuleErrors(interfaceId, ruleId, qos){
282
+ interfaceId = interfaceId || '+';
283
+ ruleId = ruleId || '+';
284
+ qos = qos || 0;
285
+
286
+ var topic = "iot-2/intf/" + interfaceId + "/rule/" + ruleId + "/err/data";
287
+ this.log.debug("[ApplicationClient:subscribeToRuleErrors] Calling subscribe with QoS "+qos);
288
+ this._subscribe(topic, qos);
289
+ return this;
290
+ }
291
+
292
+ unsubscribeToRuleErrors(interfaceId, ruleId){
293
+ interfaceId = interfaceId || '+';
294
+ ruleId = ruleId || '+';
295
+
296
+ var topic = "iot-2/intf/" + interfaceId + "/rule/" + ruleId + "/err/data";
297
+ this._unsubscribe(topic);
298
+ return this;
299
+ }
300
+
301
+
302
+ // ==========================================================================
303
+ // Device Status
304
+ // ==========================================================================
305
+
306
+ subscribeToDeviceStatus(type, id, qos) {
307
+ type = type || '+';
308
+ id = id || '+';
309
+ qos = qos || 0;
310
+
311
+ var topic = "iot-2/type/" + type + "/id/" + id + "/mon";
312
+ this.log.debug("[ApplicationClient:subscribeToDeviceStatus] Calling subscribe with QoS " + qos);
313
+ this._subscribe(topic, qos);
314
+ return this;
315
+ }
316
+
317
+ unsubscribeToDeviceStatus(type, id) {
318
+ type = type || '+';
319
+ id = id || '+';
320
+
321
+ var topic = "iot-2/type/" + type + "/id/" + id + "/mon";
322
+ this._unsubscribe(topic);
323
+ return this;
324
+ }
325
+
326
+ // ==========================================================================
327
+ // Application Status
328
+ // ==========================================================================
329
+
330
+ subscribeToAppStatus(id, qos) {
331
+ id = id || '+';
332
+ qos = qos || 0;
333
+
334
+ var topic = "iot-2/app/" + id + "/mon";
335
+ this.log.debug("[ApplicationClient:subscribeToAppStatus] Calling subscribe with QoS " + qos);
336
+ this._subscribe(topic, qos);
337
+ return this;
338
+ }
339
+
340
+ unsubscribeToAppStatus(id) {
341
+ id = id || '+';
342
+
343
+ var topic = "iot-2/app/" + id + "/mon";
344
+ this._unsubscribe(topic);
345
+
346
+ return this;
347
+ }
348
+
349
349
  };