@project-chip/matter-node.js-examples 0.6.1-alpha.0-20231015-0e2c4e1 → 0.6.1-alpha.0-20231019-738744a
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/dist/cjs/examples/BridgedDevicesNode.js +4 -3
- package/dist/cjs/examples/BridgedDevicesNode.js.map +2 -2
- package/dist/cjs/examples/ComposedDeviceNode.js +3 -2
- package/dist/cjs/examples/ComposedDeviceNode.js.map +2 -2
- package/dist/cjs/examples/ControllerNode.js +25 -21
- package/dist/cjs/examples/ControllerNode.js.map +3 -3
- package/dist/cjs/examples/DeviceNode.js +3 -2
- package/dist/cjs/examples/DeviceNode.js.map +2 -2
- package/dist/cjs/examples/MultiDeviceNode.js +3 -2
- package/dist/cjs/examples/MultiDeviceNode.js.map +2 -2
- package/dist/cjs/tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/examples/BridgedDevicesNode.ts +4 -3
- package/src/examples/ComposedDeviceNode.ts +3 -2
- package/src/examples/ControllerNode.ts +34 -22
- package/src/examples/DeviceNode.ts +3 -2
- package/src/examples/MultiDeviceNode.ts +3 -2
@@ -16,7 +16,7 @@
|
|
16
16
|
* Import needed modules from @project-chip/matter-node.js
|
17
17
|
*/
|
18
18
|
// Include this first to auto-register Crypto, Network and Time Node.js implementations
|
19
|
-
import { CommissioningController, MatterServer } from "@project-chip/matter-node.js";
|
19
|
+
import { CommissioningController, MatterServer, NodeCommissioningOptions } from "@project-chip/matter-node.js";
|
20
20
|
|
21
21
|
import { BleNode } from "@project-chip/matter-node-ble.js/ble";
|
22
22
|
import { Ble } from "@project-chip/matter-node.js/ble";
|
@@ -26,7 +26,7 @@ import {
|
|
26
26
|
GeneralCommissioning,
|
27
27
|
OnOffCluster,
|
28
28
|
} from "@project-chip/matter-node.js/cluster";
|
29
|
-
import {
|
29
|
+
import { NodeId } from "@project-chip/matter-node.js/datatype";
|
30
30
|
import { Format, Level, Logger } from "@project-chip/matter-node.js/log";
|
31
31
|
import { CommissioningOptions } from "@project-chip/matter-node.js/protocol";
|
32
32
|
import { ManualPairingCodeCodec } from "@project-chip/matter-node.js/schema";
|
@@ -177,13 +177,7 @@ class ControllerNode {
|
|
177
177
|
|
178
178
|
const matterServer = new MatterServer(storageManager);
|
179
179
|
const commissioningController = new CommissioningController({
|
180
|
-
|
181
|
-
longDiscriminator,
|
182
|
-
shortDiscriminator,
|
183
|
-
passcode: setupPin,
|
184
|
-
delayedPairing: true,
|
185
|
-
commissioningOptions,
|
186
|
-
subscribeAllAttributes: true,
|
180
|
+
autoConnect: false,
|
187
181
|
});
|
188
182
|
matterServer.addCommissioningController(commissioningController);
|
189
183
|
|
@@ -196,29 +190,47 @@ class ControllerNode {
|
|
196
190
|
|
197
191
|
await matterServer.start();
|
198
192
|
|
193
|
+
if (!commissioningController.isCommissioned()) {
|
194
|
+
const options = {
|
195
|
+
commissioning: commissioningOptions,
|
196
|
+
discovery: {
|
197
|
+
knownAddress: ip !== undefined && port !== undefined ? { ip, port, type: "udp" } : undefined,
|
198
|
+
identifierData:
|
199
|
+
longDiscriminator !== undefined
|
200
|
+
? { longDiscriminator }
|
201
|
+
: shortDiscriminator !== undefined
|
202
|
+
? { shortDiscriminator }
|
203
|
+
: {},
|
204
|
+
},
|
205
|
+
passcode: setupPin,
|
206
|
+
} as NodeCommissioningOptions;
|
207
|
+
logger.info(`Commissioning ... ${JSON.stringify(options)}`);
|
208
|
+
const nodeId = await commissioningController.commissionNode(options);
|
209
|
+
|
210
|
+
console.log(`Commissioning successfully done with nodeId ${nodeId}`);
|
211
|
+
}
|
212
|
+
|
199
213
|
/**
|
200
214
|
* TBD
|
201
215
|
*/
|
202
216
|
try {
|
203
|
-
|
217
|
+
const nodes = commissioningController.getCommissionedNodes();
|
218
|
+
console.log("Found commissioned nodes:", Logger.toJSON(nodes));
|
204
219
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
controllerStorage.set("port", port);
|
220
|
+
const nodeId = NodeId(getIntParameter("nodeid") ?? nodes[0]);
|
221
|
+
if (!nodes.includes(nodeId)) {
|
222
|
+
throw new Error(`Node ${nodeId} not found in commissioned nodes`);
|
209
223
|
}
|
210
|
-
|
211
|
-
|
212
|
-
}
|
213
|
-
controllerStorage.set("pin", setupPin);
|
224
|
+
|
225
|
+
const node = await commissioningController.connectNode(nodeId);
|
214
226
|
|
215
227
|
// Important: This is a temporary API to proof the methods working and this will change soon and is NOT stable!
|
216
228
|
// It is provided to proof the concept
|
217
229
|
|
218
|
-
|
230
|
+
node.logStructure();
|
219
231
|
|
220
232
|
// Example to initialize a ClusterClient and access concrete fields as API methods
|
221
|
-
const descriptor =
|
233
|
+
const descriptor = node.getRootClusterClient(DescriptorCluster);
|
222
234
|
if (descriptor !== undefined) {
|
223
235
|
console.log(await descriptor.attributes.deviceTypeList.get()); // you can call that way
|
224
236
|
console.log(await descriptor.getServerListAttribute()); // or more convenient that way
|
@@ -227,7 +239,7 @@ class ControllerNode {
|
|
227
239
|
}
|
228
240
|
|
229
241
|
// Example to subscribe to a field and get the value
|
230
|
-
const info =
|
242
|
+
const info = node.getRootClusterClient(BasicInformationCluster);
|
231
243
|
if (info !== undefined) {
|
232
244
|
console.log(await info.getProductNameAttribute()); // This call is executed remotely
|
233
245
|
//console.log(await info.subscribeProductNameAttribute(value => console.log("productName", value), 5, 30));
|
@@ -248,7 +260,7 @@ class ControllerNode {
|
|
248
260
|
//const attributesBasicInformation = await interactionClient.getMultipleAttributes([{ endpointId: 0, clusterId: BasicInformationCluster.id} ]);
|
249
261
|
//console.log("Attributes-BasicInformation:", JSON.stringify(attributesBasicInformation, null, 2));
|
250
262
|
|
251
|
-
const devices =
|
263
|
+
const devices = node.getDevices();
|
252
264
|
if (devices[0] && devices[0].id === 1) {
|
253
265
|
// Example to subscribe to all Attributes of endpoint 1 of the commissioned node: */*/*
|
254
266
|
//await interactionClient.subscribeMultipleAttributes([{ endpointId: 1, /* subscribe anything from endpoint 1 */ }], 0, 180, data => {
|
@@ -20,6 +20,7 @@ import { BleNode } from "@project-chip/matter-node-ble.js/ble";
|
|
20
20
|
import { Ble } from "@project-chip/matter-node.js/ble";
|
21
21
|
import { OnOffLightDevice, OnOffPluginUnitDevice, logEndpoint } from "@project-chip/matter-node.js/device";
|
22
22
|
import { Format, Level, Logger } from "@project-chip/matter-node.js/log";
|
23
|
+
import { QrCode } from "@project-chip/matter-node.js/schema";
|
23
24
|
import { StorageBackendDisk, StorageManager } from "@project-chip/matter-node.js/storage";
|
24
25
|
import { Time } from "@project-chip/matter-node.js/time";
|
25
26
|
import {
|
@@ -249,9 +250,9 @@ class Device {
|
|
249
250
|
onIpNetwork: false,
|
250
251
|
});
|
251
252
|
|
252
|
-
const {
|
253
|
+
const { qrPairingCode, manualPairingCode } = pairingData;
|
253
254
|
|
254
|
-
console.log(
|
255
|
+
console.log(QrCode.get(qrPairingCode));
|
255
256
|
logger.info(
|
256
257
|
`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`,
|
257
258
|
);
|
@@ -20,6 +20,7 @@ import { CommissioningServer, MatterServer } from "@project-chip/matter-node.js"
|
|
20
20
|
|
21
21
|
import { DeviceTypes, OnOffLightDevice, OnOffPluginUnitDevice } from "@project-chip/matter-node.js/device";
|
22
22
|
import { Format, Level, Logger } from "@project-chip/matter-node.js/log";
|
23
|
+
import { QrCode } from "@project-chip/matter-node.js/schema";
|
23
24
|
import { StorageBackendDisk, StorageManager } from "@project-chip/matter-node.js/storage";
|
24
25
|
import { Time } from "@project-chip/matter-node.js/time";
|
25
26
|
import {
|
@@ -219,9 +220,9 @@ class Device {
|
|
219
220
|
console.log(`Device ${index + 1}:`);
|
220
221
|
if (!commissioningServer.isCommissioned()) {
|
221
222
|
const pairingData = commissioningServer.getPairingCode();
|
222
|
-
const {
|
223
|
+
const { qrPairingCode, manualPairingCode } = pairingData;
|
223
224
|
|
224
|
-
console.log(
|
225
|
+
console.log(QrCode.get(qrPairingCode));
|
225
226
|
console.log(
|
226
227
|
`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`,
|
227
228
|
);
|