Skip to content

Commit 7266acc

Browse files
author
Stefania
authored
Merge pull request #3 from arduino/change_mqtt_topic
Change mqtt topic
2 parents 55a8dd2 + d27f874 commit 7266acc

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ ArduinoCloud.closeCloudMonitor(connectionId, deviceId).then(topic => {
5959
// Send a property value to a device
6060
// - value can be a string, a boolean or a number
6161
// - timestamp is a unix timestamp, not required
62-
ArduinoCloud.sendProperty(connectionId, deviceId, name, value, timestamp).then(() => {
62+
ArduinoCloud.sendProperty(connectionId, thingId, name, value, timestamp).then(() => {
6363
// Property value sent
6464
});
6565

6666
// Register a callback on a property value change
6767
//
68-
ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyName, updateCb).then(() => {
68+
ArduinoCloud.onPropertyValue(connectionId, thingId, propertyName, updateCb).then(() => {
6969
// 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
7070
});
7171

package-lock.json

+21-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ const closeCloudMonitor = (id, deviceId) => {
222222
return unsubscribe(id, cloudMonitorOutputTopic);
223223
};
224224

225-
const sendProperty = (connectionId, deviceId, name, value, timestamp) => {
226-
const propertyInputTopic = `/a/d/${deviceId}/e/i`;
225+
const sendProperty = (connectionId, thingId, name, value, timestamp) => {
226+
const propertyInputTopic = `/a/t/${thingId}/e/i`;
227227

228228
if (timestamp && !Number.isInteger(timestamp)) {
229229
throw new Error('Timestamp must be Integer');
@@ -294,8 +294,8 @@ const getCborValue = (senMl) => {
294294
return arrayBufferToBase64(cborEncoded);
295295
};
296296

297-
const sendPropertyAsDevice = (connectionId, deviceId, name, value, timestamp) => {
298-
const propertyInputTopic = `/a/d/${deviceId}/e/o`;
297+
const sendPropertyAsDevice = (connectionId, deviceId, thingId, name, value, timestamp) => {
298+
const propertyInputTopic = `/a/t/${thingId}/e/o`;
299299

300300
if (timestamp && !Number.isInteger(timestamp)) {
301301
throw new Error('Timestamp must be Integer');
@@ -309,14 +309,14 @@ const sendPropertyAsDevice = (connectionId, deviceId, name, value, timestamp) =>
309309
return sendMessage(connectionId, propertyInputTopic, CBOR.encode([senMlValue]));
310310
};
311311

312-
const onPropertyValue = (connectionId, deviceId, name, cb) => {
312+
const onPropertyValue = (connectionId, thingId, name, cb) => {
313313
if (!name) {
314314
throw new Error('Invalid property name');
315315
}
316316
if (typeof cb !== 'function') {
317317
throw new Error('Invalid callback');
318318
}
319-
const propOutputTopic = `/a/d/${deviceId}/e/o`;
319+
const propOutputTopic = `/a/t/${thingId}/e/o`;
320320

321321
if (!propertyCallback[propOutputTopic]) {
322322
propertyCallback[propOutputTopic] = {};

test/arduino-cloud.test.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const ArduinoCloud = require('../dist/index.js');
2121

2222
let connectionId;
2323
const deviceId = '1f4ced70-53ad-4b29-b221-1b0abbdfc757';
24+
const thingId = '2cea8542-d472-4464-859c-4ef4dfc7d1d3'
2425
const propertyIntName = 'integer';
2526
const propertyIntValue = 22;
2627

@@ -100,42 +101,42 @@ it('Simulate device write and client read his message from cloud monitor', (done
100101
});
101102

102103
it('Simulate client read integer property sent by device', (done) => {
103-
ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyIntName, (value) => {
104+
ArduinoCloud.onPropertyValue(connectionId, thingId, propertyIntName, (value) => {
104105
if (value === propertyIntValue) {
105106
done();
106107
}
107108
}).then(() => {
108-
ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, propertyIntName, propertyIntValue);
109+
ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, thingId, propertyIntName, propertyIntValue);
109110
});
110111
});
111112

112113
it('Simulate client read float property sent by device', (done) => {
113-
ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyFloatName, (value) => {
114+
ArduinoCloud.onPropertyValue(connectionId, thingId, propertyFloatName, (value) => {
114115
if (value === propertyFloatVal) {
115116
done();
116117
}
117118
}).then(() => {
118-
ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, propertyFloatName, propertyFloatVal);
119+
ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, thingId, propertyFloatName, propertyFloatVal);
119120
});
120121
});
121122

122123
it('Simulate client read string property sent by device', (done) => {
123-
ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyStrName, (value) => {
124+
ArduinoCloud.onPropertyValue(connectionId, thingId, propertyStrName, (value) => {
124125
if (value === propertyStrVal) {
125126
done();
126127
}
127128
}).then(() => {
128-
ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, propertyStrName, propertyStrVal);
129+
ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, thingId, propertyStrName, propertyStrVal);
129130
});
130131
});
131132

132133
it('Simulate client read boolean property sent by device', (done) => {
133-
ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyBoolName, (value) => {
134+
ArduinoCloud.onPropertyValue(connectionId, thingId, propertyBoolName, (value) => {
134135
if (value === propertyBoolVal) {
135136
ArduinoCloud.disconnect(connectionId);
136137
done();
137138
}
138139
}).then(() => {
139-
ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, propertyBoolName, propertyBoolVal);
140+
ArduinoCloud.sendPropertyAsDevice(connectionId, deviceId, thingId, propertyBoolName, propertyBoolVal);
140141
});
141142
});

0 commit comments

Comments
 (0)