diff --git a/README.md b/README.md index b15e4ac..885ec5c 100644 --- a/README.md +++ b/README.md @@ -59,13 +59,13 @@ ArduinoCloud.closeCloudMonitor(connectionId, deviceId).then(topic => { // Send a property value to a device // - value can be a string, a boolean or a number // - timestamp is a unix timestamp, not required -ArduinoCloud.sendProperty(connectionId, deviceId, name, value, timestamp).then(() => { +ArduinoCloud.sendProperty(connectionId, thingId, name, value, timestamp).then(() => { // Property value sent }); // Register a callback on a property value change // -ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyName, updateCb).then(() => { +ArduinoCloud.onPropertyValue(connectionId, thingId, propertyName, updateCb).then(() => { // updateCb(message) will be called every time a new value is available. Value can be string, number, or a boolean depending on the property type }); diff --git a/package-lock.json b/package-lock.json index a814f7c..36ee6e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2734,12 +2734,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2754,17 +2756,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2881,7 +2886,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2893,6 +2899,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2907,6 +2914,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2914,12 +2922,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -2938,6 +2948,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3018,7 +3029,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3030,6 +3042,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3151,6 +3164,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/src/index.js b/src/index.js index 76967e3..78b79a5 100644 --- a/src/index.js +++ b/src/index.js @@ -222,8 +222,8 @@ const closeCloudMonitor = (id, deviceId) => { return unsubscribe(id, cloudMonitorOutputTopic); }; -const sendProperty = (connectionId, deviceId, name, value, timestamp) => { - const propertyInputTopic = `/a/d/${deviceId}/e/i`; +const sendProperty = (connectionId, thingId, name, value, timestamp) => { + const propertyInputTopic = `/a/t/${thingId}/e/i`; if (timestamp && !Number.isInteger(timestamp)) { throw new Error('Timestamp must be Integer'); @@ -294,8 +294,8 @@ const getCborValue = (senMl) => { return arrayBufferToBase64(cborEncoded); }; -const sendPropertyAsDevice = (connectionId, deviceId, name, value, timestamp) => { - const propertyInputTopic = `/a/d/${deviceId}/e/o`; +const sendPropertyAsDevice = (connectionId, deviceId, thingId, name, value, timestamp) => { + const propertyInputTopic = `/a/t/${thingId}/e/o`; if (timestamp && !Number.isInteger(timestamp)) { throw new Error('Timestamp must be Integer'); @@ -309,14 +309,14 @@ const sendPropertyAsDevice = (connectionId, deviceId, name, value, timestamp) => return sendMessage(connectionId, propertyInputTopic, CBOR.encode([senMlValue])); }; -const onPropertyValue = (connectionId, deviceId, name, cb) => { +const onPropertyValue = (connectionId, thingId, name, cb) => { if (!name) { throw new Error('Invalid property name'); } if (typeof cb !== 'function') { throw new Error('Invalid callback'); } - const propOutputTopic = `/a/d/${deviceId}/e/o`; + const propOutputTopic = `/a/t/${thingId}/e/o`; if (!propertyCallback[propOutputTopic]) { propertyCallback[propOutputTopic] = {}; diff --git a/test/arduino-cloud.test.js b/test/arduino-cloud.test.js index 8d5ad02..5b34493 100644 --- a/test/arduino-cloud.test.js +++ b/test/arduino-cloud.test.js @@ -21,6 +21,7 @@ const ArduinoCloud = require('../dist/index.js'); let connectionId; const deviceId = '1f4ced70-53ad-4b29-b221-1b0abbdfc757'; +const thingId = '2cea8542-d472-4464-859c-4ef4dfc7d1d3' const propertyIntName = 'integer'; const propertyIntValue = 22; @@ -100,42 +101,42 @@ it('Simulate device write and client read his message from cloud monitor', (done }); it('Simulate client read integer property sent by device', (done) => { - ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyIntName, (value) => { + ArduinoCloud.onPropertyValue(connectionId, thingId, propertyIntName, (value) => { if (value === propertyIntValue) { done(); } }).then(() => { - ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, propertyIntName, propertyIntValue); + ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, thingId, propertyIntName, propertyIntValue); }); }); it('Simulate client read float property sent by device', (done) => { - ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyFloatName, (value) => { + ArduinoCloud.onPropertyValue(connectionId, thingId, propertyFloatName, (value) => { if (value === propertyFloatVal) { done(); } }).then(() => { - ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, propertyFloatName, propertyFloatVal); + ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, thingId, propertyFloatName, propertyFloatVal); }); }); it('Simulate client read string property sent by device', (done) => { - ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyStrName, (value) => { + ArduinoCloud.onPropertyValue(connectionId, thingId, propertyStrName, (value) => { if (value === propertyStrVal) { done(); } }).then(() => { - ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, propertyStrName, propertyStrVal); + ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, thingId, propertyStrName, propertyStrVal); }); }); it('Simulate client read boolean property sent by device', (done) => { - ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyBoolName, (value) => { + ArduinoCloud.onPropertyValue(connectionId, thingId, propertyBoolName, (value) => { if (value === propertyBoolVal) { ArduinoCloud.disconnect(connectionId); done(); } }).then(() => { - ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, propertyBoolName, propertyBoolVal); + ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, thingId, propertyBoolName, propertyBoolVal); }); });