@project-chip/matter-node.js-examples 0.10.0-alpha.0-20240607-fbc64d30 → 0.10.0-alpha.0-20240608-7a34e6fa

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. package/dist/esm/examples/BridgedDevicesNode.js +1 -0
  2. package/dist/esm/examples/BridgedDevicesNode.js.map +2 -2
  3. package/dist/esm/examples/ComposedDeviceNode.js +1 -0
  4. package/dist/esm/examples/ComposedDeviceNode.js.map +2 -2
  5. package/dist/esm/examples/ControllerNode.js.map +2 -2
  6. package/dist/esm/examples/ControllerNodeLegacy.js.map +2 -2
  7. package/dist/esm/examples/DeviceNode.js +1 -0
  8. package/dist/esm/examples/DeviceNode.js.map +2 -2
  9. package/dist/esm/examples/DeviceNodeFull.js +1 -0
  10. package/dist/esm/examples/DeviceNodeFull.js.map +2 -2
  11. package/dist/esm/examples/IlluminatedRollerShade.js +1 -0
  12. package/dist/esm/examples/IlluminatedRollerShade.js.map +2 -2
  13. package/dist/esm/examples/LegacyStorageConverter.js +1 -0
  14. package/dist/esm/examples/LegacyStorageConverter.js.map +2 -2
  15. package/dist/esm/examples/LightDevice.js +1 -0
  16. package/dist/esm/examples/LightDevice.js.map +2 -2
  17. package/dist/esm/examples/MultiDeviceNode.js +1 -0
  18. package/dist/esm/examples/MultiDeviceNode.js.map +2 -2
  19. package/dist/esm/examples/SensorDeviceNode.js +1 -0
  20. package/dist/esm/examples/SensorDeviceNode.js.map +2 -2
  21. package/package.json +6 -6
  22. package/src/examples/BridgedDevicesNode.ts +1 -0
  23. package/src/examples/ComposedDeviceNode.ts +1 -0
  24. package/src/examples/ControllerNode.ts +0 -1
  25. package/src/examples/ControllerNodeLegacy.ts +0 -1
  26. package/src/examples/DeviceNode.ts +1 -0
  27. package/src/examples/DeviceNodeFull.ts +1 -0
  28. package/src/examples/IlluminatedRollerShade.ts +1 -0
  29. package/src/examples/LegacyStorageConverter.ts +1 -0
  30. package/src/examples/LightDevice.ts +1 -0
  31. package/src/examples/MultiDeviceNode.ts +1 -0
  32. package/src/examples/SensorDeviceNode.ts +1 -0
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/BridgedDevicesNode.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a new device node that is composed of multiple devices.\n * It creates multiple endpoints on the server. For information on how to add a composed device to a bridge please\n * refer to the bridge example!\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { BridgedDeviceBasicInformationServer } from \"@project-chip/matter.js/behavior/definitions/bridged-device-basic-information\";\nimport { VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { AggregatorEndpoint } from \"@project-chip/matter.js/endpoints/AggregatorEndpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\n/** Initialize configuration values */\nconst { isSocket, deviceName, vendorName, passcode, discriminator, vendorId, productName, productId, port, uniqueId } =\n await getConfiguration();\n\n/**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\nconst server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: AggregatorEndpoint.deviceType,\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n});\n\n/**\n * Matter Nodes are a composition of endpoints. Create and add a single multiple endpoint to the node to make it a\n * composed device. This example uses the OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type\n * parameter. It also assigns each Endpoint a unique ID to store the endpoint number for it in the storage to restore\n * the device on restart.\n *\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n\nconst aggregator = new Endpoint(AggregatorEndpoint, { id: \"aggregator\" });\nawait server.add(aggregator);\n\nfor (let idx = 0; idx < isSocket.length; idx++) {\n const i = idx + 1;\n const isASocket = isSocket[idx]; // Is the Device we add a Socket or a Light?\n\n const name = `OnOff ${isASocket ? \"Socket\" : \"Light\"} ${i}`;\n\n const endpoint = new Endpoint(\n isASocket\n ? // For a Bridged Device we need to add a BridgedDeviceBasicInformation cluster as server\n OnOffPlugInUnitDevice.with(BridgedDeviceBasicInformationServer)\n : OnOffLightDevice.with(BridgedDeviceBasicInformationServer),\n {\n id: `onoff-${i}`,\n bridgedDeviceBasicInformation: {\n nodeLabel: name,\n productName: name,\n productLabel: name,\n serialNumber: `node-matter-${uniqueId}-${i}`,\n reachable: true,\n },\n },\n );\n await aggregator.add(endpoint);\n\n /**\n * Register state change handlers and events of the endpoint for identify and onoff states to react to the commands.\n *\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic for ${name}, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic for ${name} ...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on${i}` : `off${i}`);\n console.log(`${name} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n}\n\n/**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\nawait server.bringOnline();\n\n/**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\nlogEndpoint(EndpointServer.forEndpoint(server));\n\n/*\n If you want to dynamically add another device during runtime you can do so by doing the following:\n\n const name = `OnOff Light 3`;\n\n const endpoint = new Endpoint(OnOffLightDevice.with(BridgedDeviceBasicInformationServer), {\n id: `onoff-3`,\n bridgedDeviceBasicInformation: {\n nodeLabel: name,\n productName: name,\n productLabel: name,\n serialNumber: `node-matter-${uniqueId}-3`,\n reachable: true,\n },\n });\n await aggregator.add(endpoint);\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on3` : `off3`);\n console.log(`${name} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n\n */\n\n/*\n To remove a device during runtime you can do so by doing the following:\n console.log(\"Removing Light 3 now!!\");\n\n await endpoint.close();\n\n This will automatically remove the endpoint from the bridge.\n */\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/** Defined a shell command from an environment variable and execute it and log the response. */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n /**\n * Collect all needed data\n *\n * This block collects all needed data from cli, environment or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isSocket = Array<boolean>();\n const numDevices = environment.vars.number(\"num\") || 2;\n if (await deviceStorage.has(\"isSocket\")) {\n console.log(`Device types found in storage. --type parameter is ignored.`);\n (await deviceStorage.get<Array<boolean>>(\"isSocket\")).forEach(type => isSocket.push(type));\n }\n for (let i = 1; i <= numDevices; i++) {\n if (isSocket[i - 1] !== undefined) continue;\n isSocket.push(environment.vars.string(`type${i}`) === \"socket\");\n }\n\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n });\n\n return {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n };\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AAAC;AAAA,IACA,MAAAC;AAAA,IACA,UAAAC;AAAA,EACJ;AACJ;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a new device node that is composed of multiple devices.\n * It creates multiple endpoints on the server. For information on how to add a composed device to a bridge please\n * refer to the bridge example!\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { BridgedDeviceBasicInformationServer } from \"@project-chip/matter.js/behavior/definitions/bridged-device-basic-information\";\nimport { VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { AggregatorEndpoint } from \"@project-chip/matter.js/endpoints/AggregatorEndpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\n/** Initialize configuration values */\nconst { isSocket, deviceName, vendorName, passcode, discriminator, vendorId, productName, productId, port, uniqueId } =\n await getConfiguration();\n\n/**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\nconst server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: AggregatorEndpoint.deviceType,\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n});\n\n/**\n * Matter Nodes are a composition of endpoints. Create and add a single multiple endpoint to the node to make it a\n * composed device. This example uses the OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type\n * parameter. It also assigns each Endpoint a unique ID to store the endpoint number for it in the storage to restore\n * the device on restart.\n *\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n\nconst aggregator = new Endpoint(AggregatorEndpoint, { id: \"aggregator\" });\nawait server.add(aggregator);\n\nfor (let idx = 0; idx < isSocket.length; idx++) {\n const i = idx + 1;\n const isASocket = isSocket[idx]; // Is the Device we add a Socket or a Light?\n\n const name = `OnOff ${isASocket ? \"Socket\" : \"Light\"} ${i}`;\n\n const endpoint = new Endpoint(\n isASocket\n ? // For a Bridged Device we need to add a BridgedDeviceBasicInformation cluster as server\n OnOffPlugInUnitDevice.with(BridgedDeviceBasicInformationServer)\n : OnOffLightDevice.with(BridgedDeviceBasicInformationServer),\n {\n id: `onoff-${i}`,\n bridgedDeviceBasicInformation: {\n nodeLabel: name,\n productName: name,\n productLabel: name,\n serialNumber: `node-matter-${uniqueId}-${i}`,\n reachable: true,\n },\n },\n );\n await aggregator.add(endpoint);\n\n /**\n * Register state change handlers and events of the endpoint for identify and onoff states to react to the commands.\n *\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic for ${name}, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic for ${name} ...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on${i}` : `off${i}`);\n console.log(`${name} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n}\n\n/**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\nawait server.bringOnline();\n\n/**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\nlogEndpoint(EndpointServer.forEndpoint(server));\n\n/*\n If you want to dynamically add another device during runtime you can do so by doing the following:\n\n const name = `OnOff Light 3`;\n\n const endpoint = new Endpoint(OnOffLightDevice.with(BridgedDeviceBasicInformationServer), {\n id: `onoff-3`,\n bridgedDeviceBasicInformation: {\n nodeLabel: name,\n productName: name,\n productLabel: name,\n serialNumber: `node-matter-${uniqueId}-3`,\n reachable: true,\n },\n });\n await aggregator.add(endpoint);\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on3` : `off3`);\n console.log(`${name} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n\n */\n\n/*\n To remove a device during runtime you can do so by doing the following:\n console.log(\"Removing Light 3 now!!\");\n\n await endpoint.close();\n\n This will automatically remove the endpoint from the bridge.\n */\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/** Defined a shell command from an environment variable and execute it and log the response. */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n /**\n * Collect all needed data\n *\n * This block collects all needed data from cli, environment or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isSocket = Array<boolean>();\n const numDevices = environment.vars.number(\"num\") || 2;\n if (await deviceStorage.has(\"isSocket\")) {\n console.log(`Device types found in storage. --type parameter is ignored.`);\n (await deviceStorage.get<Array<boolean>>(\"isSocket\")).forEach(type => isSocket.push(type));\n }\n for (let i = 1; i <= numDevices; i++) {\n if (isSocket[i - 1] !== undefined) continue;\n isSocket.push(environment.vars.string(`type${i}`) === \"socket\");\n }\n\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n });\n\n return {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n };\n}\n"],
5
+ "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAiBA,OAAO;AAEP,SAAS,6BAA6B;AACtC,SAAS,2CAA2C;AACpD,SAAS,gBAAgB;AACzB,S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,UAAU,GAAG,QAAQ,UAAQA,UAAS,KAAK,IAAI,CAAC;AAAA,EAC7F;AACA,WAAS,IAAI,GAAG,KAAK,YAAY,KAAK;AAClC,QAAIA,UAAS,IAAI,CAAC,MAAM,OAAW;AACnC,IAAAA,UAAS,KAAK,YAAY,KAAK,OAAO,OAAO,CAAC,EAAE,MAAM,QAAQ;AAAA,EAClE;AAEA,QAAMC,cAAa;AACnB,QAAMC,cAAa;AACnB,QAAMC,YAAW,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,QAAQ;AACrG,QAAMC,iBAAgB,YAAY,KAAK,OAAO,eAAe,KAAM,MAAM,cAAc,IAAI,iBAAiB,IAAI;AAEhH,QAAMC,YAAW,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAM;AACnG,QAAMC,eAAc,qBAAqBN,YAAW,WAAW,OAAO;AACtE,QAAMO,aAAY,YAAY,KAAK,OAAO,WAAW,KAAM,MAAM,cAAc,IAAI,aAAa,KAAM;AAEtG,QAAMC,QAAO,YAAY,KAAK,OAAO,MAAM,KAAK;AAEhD,QAAMC,YACF,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAK,MAAM,EAAE,SAAS,CAAC;AAGvG,QAAM,cAAc,IAAI;AAAA,IACpB,UAAAN;AAAA,IACA,eAAAC;AAAA,IACA,UAAUC;AAAA,IACV,WAAWE;AAAA,IACX,UAAAP;AAAA,IACA,UAAUS;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACH,UAAAT;AAAA,IACA,YAAAC;AAAA,IACA,YAAAC;AAAA,IACA,UAAAC;AAAA,IACA,eAAAC;AAAA,IACA,UAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,MAAAC;AAAA,IACA,UAAAC;AAAA,EACJ;AACJ;",
6
6
  "names": ["isSocket", "deviceName", "vendorName", "passcode", "discriminator", "vendorId", "productName", "productId", "port", "uniqueId"]
7
7
  }
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/ComposedDeviceNode.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a new device node that is composed of multiple devices.\n * It creates multiple endpoints on the server. For information on how to add a composed device to a bridge please\n * refer to the bridge example!\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\n/** Initialize configuration values */\nconst { isSocket, deviceName, vendorName, passcode, discriminator, vendorId, productName, productId, port, uniqueId } =\n await getConfiguration();\n\n/**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\nconst server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(isSocket[0] ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType),\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n});\n\n/**\n * Matter Nodes are a composition of endpoints. Create and add a single multiple endpoint to the node to make it a\n * composed device. This example uses the OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type\n * parameter. It also assigns each Endpoint a unique ID to store the endpoint number for it in the storage to restore\n * the device on restart.\n *\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n\nfor (let idx = 0; idx < isSocket.length; idx++) {\n const i = idx + 1;\n const isASocket = isSocket[idx]; // Is the Device we add a Socket or a Light?\n const endpoint = new Endpoint(isASocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: `onoff-${i}` });\n await server.add(endpoint);\n\n /**\n * Register state change handlers of the endpoint for identify and onoff states to react to the commands.\n *\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic for sub device ${i}, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic for sub device ${i}...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on${i}` : `off${i}`);\n console.log(`OnOff ${i} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n}\n\n/**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\nlogEndpoint(EndpointServer.forEndpoint(server));\n\n/**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\nawait server.run();\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/**\n * Defines a shell command from an environment variable and execute it and log the response\n */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isSocket = Array<boolean>();\n const numDevices = environment.vars.number(\"num\") || 2;\n if (await deviceStorage.has(\"isSocket\")) {\n console.log(`Device types found in storage. --type parameter is ignored.`);\n (await deviceStorage.get<Array<boolean>>(\"isSocket\")).forEach(type => isSocket.push(type));\n }\n for (let i = 1; i < numDevices; i++) {\n if (isSocket[i - 1] !== undefined) continue;\n isSocket.push(environment.vars.string(`type${i}`) === \"socket\");\n }\n\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n });\n\n return {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n };\n}\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,OAAO;AAEP,SAAS,6BAA6B;AACtC,SAAS,cAAc,gBAAgB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,UAAU,sBAAsB;AACzC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAEzB,sBAAsB,EAAE;AAGxB,MAAM,EAAE,UAAU,YAAY,YAAY,UAAU,eAAe,UAAU,aAAa,WAAW,MAAM,SAAS,IAChH,MAAM,iBAAiB;AAK3B,MAAM,SAAS,MAAM,WAAW,OAAO;AAAA;AAAA,EAEnC,IAAI;AAAA;AAAA;AAAA,EAIJ,SAAS;AAAA,IACL;AAAA,EACJ;AAAA;AAAA;AAAA,EAIA,eAAe;AAAA,IACX;AAAA,IACA;AAAA,EACJ;AAAA;AAAA;AAAA,EAIA,oBAAoB;AAAA,IAChB,MAAM;AAAA,IACN,YAAY,aAAa,SAAS,CAAC,IAAI,sBAAsB,aAAa,iBAAiB,UAAU;AAAA,EACzG;AAAA;AAAA;AAAA,EAIA,kBAAkB;AAAA,IACd;AAAA,IACA,UAAU,SAAS,QAAQ;AAAA,IAC3B,WAAW;AAAA,IACX;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,cAAc,YAAY,QAAQ;AAAA,IAClC;AAAA,EACJ;AACJ,CAAC;AAYD,SAAS,MAAM,GAAG,MAAM,SAAS,QAAQ,OAAO;AAC5C,QAAM,IAAI,MAAM;AAChB,QAAM,YAAY,SAAS,GAAG;AAC9B,QAAM,WAAW,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AAAA,EAC7F;AACA,WAAS,IAAI,GAAG,IAAI,YAAY,KAAK;AACjC,QAAIA,UAAS,IAAI,CAAC,MAAM,OAAW;AACnC,IAAAA,UAAS,KAAK,YAAY,KAAK,OAAO,OAAO,CAAC,EAAE,MAAM,QAAQ;AAAA,EAClE;AAEA,QAAMC,cAAa;AACnB,QAAMC,cAAa;AACnB,QAAMC,YAAW,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,QAAQ;AACrG,QAAMC,iBAAgB,YAAY,KAAK,OAAO,eAAe,KAAM,MAAM,cAAc,IAAI,iBAAiB,IAAI;AAEhH,QAAMC,YAAW,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAM;AACnG,QAAMC,eAAc,qBAAqBN,YAAW,WAAW,OAAO;AACtE,QAAMO,aAAY,YAAY,KAAK,OAAO,WAAW,KAAM,MAAM,cAAc,IAAI,aAAa,KAAM;AAEtG,QAAMC,QAAO,YAAY,KAAK,OAAO,MAAM,KAAK;AAEhD,QAAMC,YACF,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAK,MAAM,EAAE,SAAS,CAAC;AAGvG,QAAM,cAAc,IAAI;AAAA,IACpB,UAAAN;AAAA,IACA,eAAAC;AAAA,IACA,UAAUC;AAAA,IACV,WAAWE;AAAA,IACX,UAAAP;AAAA,IACA,UAAUS;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACH,UAAAT;AAAA,IACA,YAAAC;AAAA,IACA,YAAAC;AAAA,IACA,UAAAC;AAAA,IACA,eAAAC;AAAA,IACA,UAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,MAAAC;AAAA,IACA,UAAAC;AAAA,EACJ;AACJ;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a new device node that is composed of multiple devices.\n * It creates multiple endpoints on the server. For information on how to add a composed device to a bridge please\n * refer to the bridge example!\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\n/** Initialize configuration values */\nconst { isSocket, deviceName, vendorName, passcode, discriminator, vendorId, productName, productId, port, uniqueId } =\n await getConfiguration();\n\n/**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\nconst server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(isSocket[0] ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType),\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n});\n\n/**\n * Matter Nodes are a composition of endpoints. Create and add a single multiple endpoint to the node to make it a\n * composed device. This example uses the OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type\n * parameter. It also assigns each Endpoint a unique ID to store the endpoint number for it in the storage to restore\n * the device on restart.\n *\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n\nfor (let idx = 0; idx < isSocket.length; idx++) {\n const i = idx + 1;\n const isASocket = isSocket[idx]; // Is the Device we add a Socket or a Light?\n const endpoint = new Endpoint(isASocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: `onoff-${i}` });\n await server.add(endpoint);\n\n /**\n * Register state change handlers of the endpoint for identify and onoff states to react to the commands.\n *\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic for sub device ${i}, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic for sub device ${i}...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on${i}` : `off${i}`);\n console.log(`OnOff ${i} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n}\n\n/**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\nlogEndpoint(EndpointServer.forEndpoint(server));\n\n/**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\nawait server.run();\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/**\n * Defines a shell command from an environment variable and execute it and log the response\n */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isSocket = Array<boolean>();\n const numDevices = environment.vars.number(\"num\") || 2;\n if (await deviceStorage.has(\"isSocket\")) {\n console.log(`Device types found in storage. --type parameter is ignored.`);\n (await deviceStorage.get<Array<boolean>>(\"isSocket\")).forEach(type => isSocket.push(type));\n }\n for (let i = 1; i < numDevices; i++) {\n if (isSocket[i - 1] !== undefined) continue;\n isSocket.push(environment.vars.string(`type${i}`) === \"socket\");\n }\n\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n });\n\n return {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n };\n}\n"],
5
+ "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAiBA,OAAO;AAEP,SAAS,6BAA6B;AACtC,SAAS,cAAc,gB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Y,QAAQ;AACrG,QAAMC,iBAAgB,YAAY,KAAK,OAAO,eAAe,KAAM,MAAM,cAAc,IAAI,iBAAiB,IAAI;AAEhH,QAAMC,YAAW,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAM;AACnG,QAAMC,eAAc,qBAAqBN,YAAW,WAAW,OAAO;AACtE,QAAMO,aAAY,YAAY,KAAK,OAAO,WAAW,KAAM,MAAM,cAAc,IAAI,aAAa,KAAM;AAEtG,QAAMC,QAAO,YAAY,KAAK,OAAO,MAAM,KAAK;AAEhD,QAAMC,YACF,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAK,MAAM,EAAE,SAAS,CAAC;AAGvG,QAAM,cAAc,IAAI;AAAA,IACpB,UAAAN;AAAA,IACA,eAAAC;AAAA,IACA,UAAUC;AAAA,IACV,WAAWE;AAAA,IACX,UAAAP;AAAA,IACA,UAAUS;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACH,UAAAT;AAAA,IACA,YAAAC;AAAA,IACA,YAAAC;AAAA,IACA,UAAAC;AAAA,IACA,eAAAC;AAAA,IACA,UAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,MAAAC;AAAA,IACA,UAAAC;AAAA,EACJ;AACJ;",
6
6
  "names": ["isSocket", "deviceName", "vendorName", "passcode", "discriminator", "vendorId", "productName", "productId", "port", "uniqueId"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/ControllerNode.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\n\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a Matter controller to pair with a device and interfact with it.\n * It can be used as CLI script, but is more thought as a starting point for your own controller implementation\n * because you need to adjust the code in any way depending on your use case.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { CommissioningController, NodeCommissioningOptions } from \"@project-chip/matter.js\";\nimport { Ble } from \"@project-chip/matter.js/ble\";\nimport {\n BasicInformationCluster,\n DescriptorCluster,\n GeneralCommissioning,\n OnOffCluster,\n} from \"@project-chip/matter.js/cluster\";\nimport { NodeId } from \"@project-chip/matter.js/datatype\";\nimport { NodeStateInformation } from \"@project-chip/matter.js/device\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { Logger } from \"@project-chip/matter.js/log\";\nimport { CommissioningOptions } from \"@project-chip/matter.js/protocol\";\nimport { ManualPairingCodeCodec } from \"@project-chip/matter.js/schema\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { singleton } from \"@project-chip/matter.js/util\";\n\nconst logger = Logger.get(\"Controller\");\n\nrequireMinNodeVersion(16);\n\nconst environment = Environment.default;\n\nif (environment.vars.get(\"ble\")) {\n // Initialize Ble\n Ble.get = singleton(\n () =>\n new BleNode({\n hciId: environment.vars.number(\"ble-hci-id\"),\n }),\n );\n}\n\nconst storageService = environment.get(StorageService);\n\nconsole.log(`Storage location: ${storageService.location} (Directory)`);\nlogger.info(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n);\n\nclass ControllerNode {\n async start() {\n logger.info(`node-matter Controller started`);\n\n /**\n * Collect all needed data\n *\n * This block makes sure to collect all needed data from cli or storage. Replace this with where ever your data\n * come from.\n *\n * Note: This example also uses the initialized storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own contexts\n * (so maybe better not ;-)).\n */\n\n const controllerStorage = (await storageService.open(\"controller\")).createContext(\"data\");\n const ip = (await controllerStorage.has(\"ip\"))\n ? controllerStorage.get<string>(\"ip\")\n : environment.vars.string(\"ip\");\n const port = (await controllerStorage.has(\"port\"))\n ? controllerStorage.get<number>(\"port\")\n : environment.vars.number(\"port\");\n const uniqueId = (await controllerStorage.has(\"uniqueid\"))\n ? await controllerStorage.get<string>(\"uniqueid\")\n : environment.vars.string(\"uniqueid\") ?? Time.nowMs().toString();\n await controllerStorage.set(\"uniqueid\", uniqueId);\n\n const pairingCode = environment.vars.string(\"pairingcode\");\n let longDiscriminator, setupPin, shortDiscriminator;\n if (pairingCode !== undefined) {\n const pairingCodeCodec = ManualPairingCodeCodec.decode(pairingCode);\n shortDiscriminator = pairingCodeCodec.shortDiscriminator;\n longDiscriminator = undefined;\n setupPin = pairingCodeCodec.passcode;\n logger.debug(`Data extracted from pairing code: ${Logger.toJSON(pairingCodeCodec)}`);\n } else {\n longDiscriminator =\n environment.vars.number(\"longDiscriminator\") ??\n (await controllerStorage.get(\"longDiscriminator\", 3840));\n if (longDiscriminator > 4095) throw new Error(\"Discriminator value must be less than 4096\");\n setupPin = environment.vars.number(\"pin\") ?? (await controllerStorage.get(\"pin\", 20202021));\n }\n if ((shortDiscriminator === undefined && longDiscriminator === undefined) || setupPin === undefined) {\n throw new Error(\n \"Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode\",\n );\n }\n\n // Collect commissioning options from commandline parameters\n const commissioningOptions: CommissioningOptions = {\n regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,\n regulatoryCountryCode: \"XX\",\n };\n\n let ble = false;\n if (environment.vars.get(\"ble\")) {\n ble = true;\n const wifiSsid = environment.vars.string(\"ble-wifi-ssid\");\n const wifiCredentials = environment.vars.string(\"ble-wifi-credentials\");\n const threadNetworkName = environment.vars.string(\"ble-thread-networkname\");\n const threadOperationalDataset = environment.vars.string(\"ble-thread-operationaldataset\");\n if (wifiSsid !== undefined && wifiCredentials !== undefined) {\n logger.info(`Registering Commissioning over BLE with WiFi: ${wifiSsid}`);\n commissioningOptions.wifiNetwork = {\n wifiSsid: wifiSsid,\n wifiCredentials: wifiCredentials,\n };\n }\n if (threadNetworkName !== undefined && threadOperationalDataset !== undefined) {\n logger.info(`Registering Commissioning over BLE with Thread: ${threadNetworkName}`);\n commissioningOptions.threadNetwork = {\n networkName: threadNetworkName,\n operationalDataset: threadOperationalDataset,\n };\n }\n }\n\n /**\n * Create Matter Server and Controller Node\n *\n * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a\n * CommissioningController to it and add the just created device instance to it.\n * The Controller node defines the port where the server listens for the UDP packages of the Matter protocol\n * and initializes deice specific certificates and such.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled internally\n * like testEventTrigger (General Diagnostic Cluster) that can be implemented with the logic when these commands\n * are called.\n */\n\n const commissioningController = new CommissioningController({\n environment: {\n environment,\n id: uniqueId,\n },\n autoConnect: false,\n });\n\n /**\n * Start the Matter Server\n *\n * After everything was plugged together we can start the server. When not delayed announcement is set for the\n * CommissioningServer node then this command also starts the announcement of the device into the network.\n */\n await commissioningController.start();\n\n if (!commissioningController.isCommissioned()) {\n const options = {\n commissioning: commissioningOptions,\n discovery: {\n knownAddress: ip !== undefined && port !== undefined ? { ip, port, type: \"udp\" } : undefined,\n identifierData:\n longDiscriminator !== undefined\n ? { longDiscriminator }\n : shortDiscriminator !== undefined\n ? { shortDiscriminator }\n : {},\n discoveryCapabilities: {\n ble,\n },\n },\n passcode: setupPin,\n } as NodeCommissioningOptions;\n logger.info(`Commissioning ... ${Logger.toJSON(options)}`);\n const nodeId = await commissioningController.commissionNode(options);\n\n console.log(`Commissioning successfully done with nodeId ${nodeId}`);\n }\n\n /**\n * TBD\n */\n try {\n const nodes = commissioningController.getCommissionedNodes();\n console.log(\"Found commissioned nodes:\", Logger.toJSON(nodes));\n\n const nodeId = NodeId(environment.vars.number(\"nodeid\") ?? nodes[0]);\n if (!nodes.includes(nodeId)) {\n throw new Error(`Node ${nodeId} not found in commissioned nodes`);\n }\n\n const node = await commissioningController.connectNode(nodeId, {\n attributeChangedCallback: (\n peerNodeId,\n { path: { nodeId, clusterId, endpointId, attributeName }, value },\n ) =>\n console.log(\n `attributeChangedCallback ${peerNodeId}: Attribute ${nodeId}/${endpointId}/${clusterId}/${attributeName} changed to ${Logger.toJSON(\n value,\n )}`,\n ),\n eventTriggeredCallback: (peerNodeId, { path: { nodeId, clusterId, endpointId, eventName }, events }) =>\n console.log(\n `eventTriggeredCallback ${peerNodeId}: Event ${nodeId}/${endpointId}/${clusterId}/${eventName} triggered with ${Logger.toJSON(\n events,\n )}`,\n ),\n stateInformationCallback: (peerNodeId, info) => {\n switch (info) {\n case NodeStateInformation.Connected:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} connected`);\n break;\n case NodeStateInformation.Disconnected:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} disconnected`);\n break;\n case NodeStateInformation.Reconnecting:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} reconnecting`);\n break;\n case NodeStateInformation.WaitingForDeviceDiscovery:\n console.log(\n `stateInformationCallback ${peerNodeId}: Node ${nodeId} waiting for device discovery`,\n );\n break;\n case NodeStateInformation.StructureChanged:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} structure changed`);\n break;\n case NodeStateInformation.Decommissioned:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} decommissioned`);\n break;\n }\n },\n });\n\n // Important: This is a temporary API to proof the methods working and this will change soon and is NOT stable!\n // It is provided to proof the concept\n\n node.logStructure();\n\n // Example to initialize a ClusterClient and access concrete fields as API methods\n const descriptor = node.getRootClusterClient(DescriptorCluster);\n if (descriptor !== undefined) {\n console.log(await descriptor.attributes.deviceTypeList.get()); // you can call that way\n console.log(await descriptor.getServerListAttribute()); // or more convenient that way\n } else {\n console.log(\"No Descriptor Cluster found. This should never happen!\");\n }\n\n // Example to subscribe to a field and get the value\n const info = node.getRootClusterClient(BasicInformationCluster);\n if (info !== undefined) {\n console.log(await info.getProductNameAttribute()); // This call is executed remotely\n //console.log(await info.subscribeProductNameAttribute(value => console.log(\"productName\", value), 5, 30));\n //console.log(await info.getProductNameAttribute()); // This call is resolved locally because we have subscribed to the value!\n } else {\n console.log(\"No BasicInformation Cluster found. This should never happen!\");\n }\n\n // Example to get all Attributes of the commissioned node: */*/*\n //const attributesAll = await interactionClient.getAllAttributes();\n //console.log(\"Attributes-All:\", Logger.toJSON(attributesAll));\n\n // Example to get all Attributes of all Descriptor Clusters of the commissioned node: */DescriptorCluster/*\n //const attributesAllDescriptor = await interactionClient.getMultipleAttributes([{ clusterId: DescriptorCluster.id} ]);\n //console.log(\"Attributes-Descriptor:\", JSON.stringify(attributesAllDescriptor, null, 2));\n\n // Example to get all Attributes of the Basic Information Cluster of endpoint 0 of the commissioned node: 0/BasicInformationCluster/*\n //const attributesBasicInformation = await interactionClient.getMultipleAttributes([{ endpointId: 0, clusterId: BasicInformationCluster.id} ]);\n //console.log(\"Attributes-BasicInformation:\", JSON.stringify(attributesBasicInformation, null, 2));\n\n const devices = node.getDevices();\n if (devices[0] && devices[0].number === 1) {\n // Example to subscribe to all Attributes of endpoint 1 of the commissioned node: */*/*\n //await interactionClient.subscribeMultipleAttributes([{ endpointId: 1, /* subscribe anything from endpoint 1 */ }], 0, 180, data => {\n // console.log(\"Subscribe-All Data:\", Logger.toJSON(data));\n //});\n\n const onOff = devices[0].getClusterClient(OnOffCluster);\n if (onOff !== undefined) {\n let onOffStatus = await onOff.getOnOffAttribute();\n console.log(\"initial onOffStatus\", onOffStatus);\n\n onOff.addOnOffAttributeListener(value => {\n console.log(\"subscription onOffStatus\", value);\n onOffStatus = value;\n });\n // read data every minute to keep up the connection to show the subscription is working\n setInterval(() => {\n onOff\n .toggle()\n .then(() => {\n onOffStatus = !onOffStatus;\n console.log(\"onOffStatus\", onOffStatus);\n })\n .catch(error => logger.error(error));\n }, 60000);\n }\n }\n } finally {\n //await matterServer.close(); // Comment out when subscribes are used, else the connection will be closed\n setTimeout(() => process.exit(0), 1000000);\n }\n }\n}\n\nnew ControllerNode().start().catch(error => logger.error(error));\n"],
5
- "mappings": ";AAEA;AAAA;AAAA;AAAA;AAAA;AAiBA,OAAO;AAEP,SAAS,eAAe;AACxB,SAAS,6BAA6B;AACtC,SAAS,+BAAyD;AAClE,SAAS,WAAW;AACpB;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,cAAc;AAEvB,SAAS,8BAA8B;AACvC,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAE1B,MAAM,SAAS,OAAO,IAAI,YAAY;AAEtC,sBAAsB,EAAE;AAExB,MAAM,cAAc,YAAY;AAEhC,IAAI,YAAY,KAAK,IAAI,KAAK,GAAG;AAE7B,MAAI,MAAM;AAAA,IACN,MACI,IAAI,QAAQ;AAAA,MACR,OAAO,YAAY,KAAK,OAAO,YAAY;AAAA,IAC/C,CAAC;AAAA,EACT;AACJ;AAEA,MAAM,iBAAiB,YAAY,IAAI,cAAc;AAErD,QAAQ,IAAI,qBAAqB,eAAe,QAAQ,cAAc;AACtE,OAAO;AAAA,EACH;AACJ;AAEA,MAAM,eAAe;AAAA,EACjB,MAAM,QAAQ;AACV,WAAO,KAAK,gCAAgC;AAa5C,UAAM,qBAAqB,MAAM,eAAe,KAAK,YAAY,GAAG,cAAc,MAAM;AACxF,UAAM,KAAM,MAAM,kBAAkB,IAAI,IAAI,IACtC,kBAAkB,IAAY,IAAI,IAClC,YAAY,KAAK,OAAO,IAAI;AAClC,UAAM,OAAQ,MAAM,kBAAkB,IAAI,MAAM,IAC1C,kBAAkB,IAAY,MAAM,IACpC,YAAY,KAAK,OAAO,MAAM;AACpC,UAAM,WAAY,MAAM,kBAAkB,IAAI,UAAU,IAClD,MAAM,kBAAkB,IAAY,UAAU,IAC9C,YAAY,KAAK,OAAO,UAAU,KAAK,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AK,qBAAqB,uBAAuB;AAC9D,UAAI,SAAS,QAAW;AACpB,gBAAQ,IAAI,MAAM,KAAK,wBAAwB,CAAC;AAAA,MAGpD,OAAO;AACH,gBAAQ,IAAI,8DAA8D;AAAA,MAC9E;AAcA,YAAM,UAAU,KAAK,WAAW;AAChC,UAAI,QAAQ,CAAC,KAAK,QAAQ,CAAC,EAAE,WAAW,GAAG;AAMvC,cAAM,QAAQ,QAAQ,CAAC,EAAE,iBAAiB,YAAY;AACtD,YAAI,UAAU,QAAW;AACrB,cAAI,cAAc,MAAM,MAAM,kBAAkB;AAChD,kBAAQ,IAAI,uBAAuB,WAAW;AAE9C,gBAAM,0BAA0B,WAAS;AACrC,oBAAQ,IAAI,4BAA4B,KAAK;AAC7C,0BAAc;AAAA,UAClB,CAAC;AAED,sBAAY,MAAM;AACd,kBACK,OAAO,EACP,KAAK,MAAM;AACR,4BAAc,CAAC;AACf,sBAAQ,IAAI,eAAe,WAAW;AAAA,YAC1C,CAAC,EACA,MAAM,WAAS,OAAO,MAAM,KAAK,CAAC;AAAA,UAC3C,GAAG,GAAK;AAAA,QACZ;AAAA,MACJ;AAAA,IACJ,UAAE;AAEE,iBAAW,MAAM,QAAQ,KAAK,CAAC,GAAG,GAAO;AAAA,IAC7C;AAAA,EACJ;AACJ;AAEA,IAAI,eAAe,EAAE,MAAM,EAAE,MAAM,WAAS,OAAO,MAAM,KAAK,CAAC;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a Matter controller to pair with a device and interfact with it.\n * It can be used as CLI script, but is more thought as a starting point for your own controller implementation\n * because you need to adjust the code in any way depending on your use case.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { CommissioningController, NodeCommissioningOptions } from \"@project-chip/matter.js\";\nimport { Ble } from \"@project-chip/matter.js/ble\";\nimport {\n BasicInformationCluster,\n DescriptorCluster,\n GeneralCommissioning,\n OnOffCluster,\n} from \"@project-chip/matter.js/cluster\";\nimport { NodeId } from \"@project-chip/matter.js/datatype\";\nimport { NodeStateInformation } from \"@project-chip/matter.js/device\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { Logger } from \"@project-chip/matter.js/log\";\nimport { CommissioningOptions } from \"@project-chip/matter.js/protocol\";\nimport { ManualPairingCodeCodec } from \"@project-chip/matter.js/schema\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { singleton } from \"@project-chip/matter.js/util\";\n\nconst logger = Logger.get(\"Controller\");\n\nrequireMinNodeVersion(16);\n\nconst environment = Environment.default;\n\nif (environment.vars.get(\"ble\")) {\n // Initialize Ble\n Ble.get = singleton(\n () =>\n new BleNode({\n hciId: environment.vars.number(\"ble-hci-id\"),\n }),\n );\n}\n\nconst storageService = environment.get(StorageService);\n\nconsole.log(`Storage location: ${storageService.location} (Directory)`);\nlogger.info(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n);\n\nclass ControllerNode {\n async start() {\n logger.info(`node-matter Controller started`);\n\n /**\n * Collect all needed data\n *\n * This block makes sure to collect all needed data from cli or storage. Replace this with where ever your data\n * come from.\n *\n * Note: This example also uses the initialized storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own contexts\n * (so maybe better not ;-)).\n */\n\n const controllerStorage = (await storageService.open(\"controller\")).createContext(\"data\");\n const ip = (await controllerStorage.has(\"ip\"))\n ? controllerStorage.get<string>(\"ip\")\n : environment.vars.string(\"ip\");\n const port = (await controllerStorage.has(\"port\"))\n ? controllerStorage.get<number>(\"port\")\n : environment.vars.number(\"port\");\n const uniqueId = (await controllerStorage.has(\"uniqueid\"))\n ? await controllerStorage.get<string>(\"uniqueid\")\n : environment.vars.string(\"uniqueid\") ?? Time.nowMs().toString();\n await controllerStorage.set(\"uniqueid\", uniqueId);\n\n const pairingCode = environment.vars.string(\"pairingcode\");\n let longDiscriminator, setupPin, shortDiscriminator;\n if (pairingCode !== undefined) {\n const pairingCodeCodec = ManualPairingCodeCodec.decode(pairingCode);\n shortDiscriminator = pairingCodeCodec.shortDiscriminator;\n longDiscriminator = undefined;\n setupPin = pairingCodeCodec.passcode;\n logger.debug(`Data extracted from pairing code: ${Logger.toJSON(pairingCodeCodec)}`);\n } else {\n longDiscriminator =\n environment.vars.number(\"longDiscriminator\") ??\n (await controllerStorage.get(\"longDiscriminator\", 3840));\n if (longDiscriminator > 4095) throw new Error(\"Discriminator value must be less than 4096\");\n setupPin = environment.vars.number(\"pin\") ?? (await controllerStorage.get(\"pin\", 20202021));\n }\n if ((shortDiscriminator === undefined && longDiscriminator === undefined) || setupPin === undefined) {\n throw new Error(\n \"Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode\",\n );\n }\n\n // Collect commissioning options from commandline parameters\n const commissioningOptions: CommissioningOptions = {\n regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,\n regulatoryCountryCode: \"XX\",\n };\n\n let ble = false;\n if (environment.vars.get(\"ble\")) {\n ble = true;\n const wifiSsid = environment.vars.string(\"ble-wifi-ssid\");\n const wifiCredentials = environment.vars.string(\"ble-wifi-credentials\");\n const threadNetworkName = environment.vars.string(\"ble-thread-networkname\");\n const threadOperationalDataset = environment.vars.string(\"ble-thread-operationaldataset\");\n if (wifiSsid !== undefined && wifiCredentials !== undefined) {\n logger.info(`Registering Commissioning over BLE with WiFi: ${wifiSsid}`);\n commissioningOptions.wifiNetwork = {\n wifiSsid: wifiSsid,\n wifiCredentials: wifiCredentials,\n };\n }\n if (threadNetworkName !== undefined && threadOperationalDataset !== undefined) {\n logger.info(`Registering Commissioning over BLE with Thread: ${threadNetworkName}`);\n commissioningOptions.threadNetwork = {\n networkName: threadNetworkName,\n operationalDataset: threadOperationalDataset,\n };\n }\n }\n\n /**\n * Create Matter Server and Controller Node\n *\n * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a\n * CommissioningController to it and add the just created device instance to it.\n * The Controller node defines the port where the server listens for the UDP packages of the Matter protocol\n * and initializes deice specific certificates and such.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled internally\n * like testEventTrigger (General Diagnostic Cluster) that can be implemented with the logic when these commands\n * are called.\n */\n\n const commissioningController = new CommissioningController({\n environment: {\n environment,\n id: uniqueId,\n },\n autoConnect: false,\n });\n\n /**\n * Start the Matter Server\n *\n * After everything was plugged together we can start the server. When not delayed announcement is set for the\n * CommissioningServer node then this command also starts the announcement of the device into the network.\n */\n await commissioningController.start();\n\n if (!commissioningController.isCommissioned()) {\n const options = {\n commissioning: commissioningOptions,\n discovery: {\n knownAddress: ip !== undefined && port !== undefined ? { ip, port, type: \"udp\" } : undefined,\n identifierData:\n longDiscriminator !== undefined\n ? { longDiscriminator }\n : shortDiscriminator !== undefined\n ? { shortDiscriminator }\n : {},\n discoveryCapabilities: {\n ble,\n },\n },\n passcode: setupPin,\n } as NodeCommissioningOptions;\n logger.info(`Commissioning ... ${Logger.toJSON(options)}`);\n const nodeId = await commissioningController.commissionNode(options);\n\n console.log(`Commissioning successfully done with nodeId ${nodeId}`);\n }\n\n /**\n * TBD\n */\n try {\n const nodes = commissioningController.getCommissionedNodes();\n console.log(\"Found commissioned nodes:\", Logger.toJSON(nodes));\n\n const nodeId = NodeId(environment.vars.number(\"nodeid\") ?? nodes[0]);\n if (!nodes.includes(nodeId)) {\n throw new Error(`Node ${nodeId} not found in commissioned nodes`);\n }\n\n const node = await commissioningController.connectNode(nodeId, {\n attributeChangedCallback: (\n peerNodeId,\n { path: { nodeId, clusterId, endpointId, attributeName }, value },\n ) =>\n console.log(\n `attributeChangedCallback ${peerNodeId}: Attribute ${nodeId}/${endpointId}/${clusterId}/${attributeName} changed to ${Logger.toJSON(\n value,\n )}`,\n ),\n eventTriggeredCallback: (peerNodeId, { path: { nodeId, clusterId, endpointId, eventName }, events }) =>\n console.log(\n `eventTriggeredCallback ${peerNodeId}: Event ${nodeId}/${endpointId}/${clusterId}/${eventName} triggered with ${Logger.toJSON(\n events,\n )}`,\n ),\n stateInformationCallback: (peerNodeId, info) => {\n switch (info) {\n case NodeStateInformation.Connected:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} connected`);\n break;\n case NodeStateInformation.Disconnected:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} disconnected`);\n break;\n case NodeStateInformation.Reconnecting:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} reconnecting`);\n break;\n case NodeStateInformation.WaitingForDeviceDiscovery:\n console.log(\n `stateInformationCallback ${peerNodeId}: Node ${nodeId} waiting for device discovery`,\n );\n break;\n case NodeStateInformation.StructureChanged:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} structure changed`);\n break;\n case NodeStateInformation.Decommissioned:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} decommissioned`);\n break;\n }\n },\n });\n\n // Important: This is a temporary API to proof the methods working and this will change soon and is NOT stable!\n // It is provided to proof the concept\n\n node.logStructure();\n\n // Example to initialize a ClusterClient and access concrete fields as API methods\n const descriptor = node.getRootClusterClient(DescriptorCluster);\n if (descriptor !== undefined) {\n console.log(await descriptor.attributes.deviceTypeList.get()); // you can call that way\n console.log(await descriptor.getServerListAttribute()); // or more convenient that way\n } else {\n console.log(\"No Descriptor Cluster found. This should never happen!\");\n }\n\n // Example to subscribe to a field and get the value\n const info = node.getRootClusterClient(BasicInformationCluster);\n if (info !== undefined) {\n console.log(await info.getProductNameAttribute()); // This call is executed remotely\n //console.log(await info.subscribeProductNameAttribute(value => console.log(\"productName\", value), 5, 30));\n //console.log(await info.getProductNameAttribute()); // This call is resolved locally because we have subscribed to the value!\n } else {\n console.log(\"No BasicInformation Cluster found. This should never happen!\");\n }\n\n // Example to get all Attributes of the commissioned node: */*/*\n //const attributesAll = await interactionClient.getAllAttributes();\n //console.log(\"Attributes-All:\", Logger.toJSON(attributesAll));\n\n // Example to get all Attributes of all Descriptor Clusters of the commissioned node: */DescriptorCluster/*\n //const attributesAllDescriptor = await interactionClient.getMultipleAttributes([{ clusterId: DescriptorCluster.id} ]);\n //console.log(\"Attributes-Descriptor:\", JSON.stringify(attributesAllDescriptor, null, 2));\n\n // Example to get all Attributes of the Basic Information Cluster of endpoint 0 of the commissioned node: 0/BasicInformationCluster/*\n //const attributesBasicInformation = await interactionClient.getMultipleAttributes([{ endpointId: 0, clusterId: BasicInformationCluster.id} ]);\n //console.log(\"Attributes-BasicInformation:\", JSON.stringify(attributesBasicInformation, null, 2));\n\n const devices = node.getDevices();\n if (devices[0] && devices[0].number === 1) {\n // Example to subscribe to all Attributes of endpoint 1 of the commissioned node: */*/*\n //await interactionClient.subscribeMultipleAttributes([{ endpointId: 1, /* subscribe anything from endpoint 1 */ }], 0, 180, data => {\n // console.log(\"Subscribe-All Data:\", Logger.toJSON(data));\n //});\n\n const onOff = devices[0].getClusterClient(OnOffCluster);\n if (onOff !== undefined) {\n let onOffStatus = await onOff.getOnOffAttribute();\n console.log(\"initial onOffStatus\", onOffStatus);\n\n onOff.addOnOffAttributeListener(value => {\n console.log(\"subscription onOffStatus\", value);\n onOffStatus = value;\n });\n // read data every minute to keep up the connection to show the subscription is working\n setInterval(() => {\n onOff\n .toggle()\n .then(() => {\n onOffStatus = !onOffStatus;\n console.log(\"onOffStatus\", onOffStatus);\n })\n .catch(error => logger.error(error));\n }, 60000);\n }\n }\n } finally {\n //await matterServer.close(); // Comment out when subscribes are used, else the connection will be closed\n setTimeout(() => process.exit(0), 1000000);\n }\n }\n}\n\nnew ControllerNode().start().catch(error => logger.error(error));\n"],
5
+ "mappings": ";AACA;AAAA;AA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OAAO;AACH,gBAAQ,IAAI,8DAA8D;AAAA,MAC9E;AAcA,YAAM,UAAU,KAAK,WAAW;AAChC,UAAI,QAAQ,CAAC,KAAK,QAAQ,CAAC,EAAE,WAAW,GAAG;AAMvC,cAAM,QAAQ,QAAQ,CAAC,EAAE,iBAAiB,YAAY;AACtD,YAAI,UAAU,QAAW;AACrB,cAAI,cAAc,MAAM,MAAM,kBAAkB;AAChD,kBAAQ,IAAI,uBAAuB,WAAW;AAE9C,gBAAM,0BAA0B,WAAS;AACrC,oBAAQ,IAAI,4BAA4B,KAAK;AAC7C,0BAAc;AAAA,UAClB,CAAC;AAED,sBAAY,MAAM;AACd,kBACK,OAAO,EACP,KAAK,MAAM;AACR,4BAAc,CAAC;AACf,sBAAQ,IAAI,eAAe,WAAW;AAAA,YAC1C,CAAC,EACA,MAAM,WAAS,OAAO,MAAM,KAAK,CAAC;AAAA,UAC3C,GAAG,GAAK;AAAA,QACZ;AAAA,MACJ;AAAA,IACJ,UAAE;AAEE,iBAAW,MAAM,QAAQ,KAAK,CAAC,GAAG,GAAO;AAAA,IAC7C;AAAA,EACJ;AACJ;AAEA,IAAI,eAAe,EAAE,MAAM,EAAE,MAAM,WAAS,OAAO,MAAM,KAAK,CAAC;",
6
6
  "names": ["nodeId", "info"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/ControllerNodeLegacy.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\n\n/**\n * @license\n * Copyright 2022-2023 Project CHIP Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a Matter controller to pair with a device and interfact with it.\n * It can be used as CLI script, but is more thought as a starting point for your own controller implementation\n * because you need to adjust the code in any way depending on your use case.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport { CommissioningController, MatterServer, NodeCommissioningOptions } from \"@project-chip/matter-node.js\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { Ble } from \"@project-chip/matter-node.js/ble\";\nimport {\n BasicInformationCluster,\n DescriptorCluster,\n GeneralCommissioning,\n OnOffCluster,\n} from \"@project-chip/matter-node.js/cluster\";\nimport { NodeId } from \"@project-chip/matter-node.js/datatype\";\nimport { NodeStateInformation } from \"@project-chip/matter-node.js/device\";\nimport { Format, Level, Logger } from \"@project-chip/matter-node.js/log\";\nimport { CommissioningOptions } from \"@project-chip/matter-node.js/protocol\";\nimport { ManualPairingCodeCodec } from \"@project-chip/matter-node.js/schema\";\nimport { StorageBackendDisk, StorageManager } from \"@project-chip/matter-node.js/storage\";\nimport {\n getIntParameter,\n getParameter,\n hasParameter,\n requireMinNodeVersion,\n singleton,\n} from \"@project-chip/matter-node.js/util\";\n\nconst logger = Logger.get(\"Controller\");\n\nrequireMinNodeVersion(16);\n\n/** Configure logging */\nswitch (getParameter(\"loglevel\")) {\n case \"fatal\":\n Logger.defaultLogLevel = Level.FATAL;\n break;\n case \"error\":\n Logger.defaultLogLevel = Level.ERROR;\n break;\n case \"warn\":\n Logger.defaultLogLevel = Level.WARN;\n break;\n case \"info\":\n Logger.defaultLogLevel = Level.INFO;\n break;\n}\n\nswitch (getParameter(\"logformat\")) {\n case \"plain\":\n Logger.format = Format.PLAIN;\n break;\n case \"html\":\n Logger.format = Format.HTML;\n break;\n default:\n if (process.stdin?.isTTY) Logger.format = Format.ANSI;\n}\n\nif (hasParameter(\"ble\")) {\n // Initialize Ble\n Ble.get = singleton(\n () =>\n new BleNode({\n hciId: getIntParameter(\"ble-hci-id\"),\n }),\n );\n}\n\nconst storageLocation = getParameter(\"store\") ?? \".controller-node\";\nconst storage = new StorageBackendDisk(storageLocation, hasParameter(\"clearstorage\"));\nlogger.info(`Storage location: ${storageLocation} (Directory)`);\nlogger.info(\n 'Use the parameter \"-store NAME\" to specify a different storage location, use -clearstorage to start with an empty storage.',\n);\n\nclass ControllerNode {\n async start() {\n logger.info(`node-matter Controller started`);\n\n /**\n * Initialize the storage system.\n *\n * The storage manager is then also used by the Matter server, so this code block in general is required,\n * but you can choose a different storage backend as long as it implements the required API.\n */\n\n const storageManager = new StorageManager(storage);\n await storageManager.initialize();\n\n /**\n * Collect all needed data\n *\n * This block makes sure to collect all needed data from cli or storage. Replace this with where ever your data\n * come from.\n *\n * Note: This example also uses the initialized storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own contexts\n * (so maybe better not ;-)).\n */\n\n const controllerStorage = storageManager.createContext(\"Controller\");\n const ip = controllerStorage.has(\"ip\") ? controllerStorage.get<string>(\"ip\") : getParameter(\"ip\");\n const port = controllerStorage.has(\"port\") ? controllerStorage.get<number>(\"port\") : getIntParameter(\"port\");\n\n const pairingCode = getParameter(\"pairingcode\");\n let longDiscriminator, setupPin, shortDiscriminator;\n if (pairingCode !== undefined) {\n const pairingCodeCodec = ManualPairingCodeCodec.decode(pairingCode);\n shortDiscriminator = pairingCodeCodec.shortDiscriminator;\n longDiscriminator = undefined;\n setupPin = pairingCodeCodec.passcode;\n logger.debug(`Data extracted from pairing code: ${Logger.toJSON(pairingCodeCodec)}`);\n } else {\n longDiscriminator =\n getIntParameter(\"longDiscriminator\") ?? controllerStorage.get(\"longDiscriminator\", 3840);\n if (longDiscriminator > 4095) throw new Error(\"Discriminator value must be less than 4096\");\n setupPin = getIntParameter(\"pin\") ?? controllerStorage.get(\"pin\", 20202021);\n }\n if ((shortDiscriminator === undefined && longDiscriminator === undefined) || setupPin === undefined) {\n throw new Error(\n \"Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode\",\n );\n }\n\n // Collect commissioning options from commandline parameters\n const commissioningOptions: CommissioningOptions = {\n regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,\n regulatoryCountryCode: \"XX\",\n };\n\n let ble = false;\n if (hasParameter(\"ble\")) {\n ble = true;\n const wifiSsid = getParameter(\"ble-wifi-ssid\");\n const wifiCredentials = getParameter(\"ble-wifi-credentials\");\n const threadNetworkName = getParameter(\"ble-thread-networkname\");\n const threadOperationalDataset = getParameter(\"ble-thread-operationaldataset\");\n if (wifiSsid !== undefined && wifiCredentials !== undefined) {\n logger.info(`Registering Commissioning over BLE with WiFi: ${wifiSsid}`);\n commissioningOptions.wifiNetwork = {\n wifiSsid: wifiSsid,\n wifiCredentials: wifiCredentials,\n };\n }\n if (threadNetworkName !== undefined && threadOperationalDataset !== undefined) {\n logger.info(`Registering Commissioning over BLE with Thread: ${threadNetworkName}`);\n commissioningOptions.threadNetwork = {\n networkName: threadNetworkName,\n operationalDataset: threadOperationalDataset,\n };\n }\n }\n\n /**\n * Create Matter Server and Controller Node\n *\n * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a\n * CommissioningController to it and add the just created device instance to it.\n * The Controller node defines the port where the server listens for the UDP packages of the Matter protocol\n * and initializes deice specific certificates and such.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled internally\n * like testEventTrigger (General Diagnostic Cluster) that can be implemented with the logic when these commands\n * are called.\n */\n\n const matterServer = new MatterServer(storageManager);\n const commissioningController = new CommissioningController({\n autoConnect: false,\n });\n await matterServer.addCommissioningController(commissioningController);\n\n /**\n * Start the Matter Server\n *\n * After everything was plugged together we can start the server. When not delayed announcement is set for the\n * CommissioningServer node then this command also starts the announcement of the device into the network.\n */\n\n await matterServer.start();\n\n if (!commissioningController.isCommissioned()) {\n const options = {\n commissioning: commissioningOptions,\n discovery: {\n knownAddress: ip !== undefined && port !== undefined ? { ip, port, type: \"udp\" } : undefined,\n identifierData:\n longDiscriminator !== undefined\n ? { longDiscriminator }\n : shortDiscriminator !== undefined\n ? { shortDiscriminator }\n : {},\n discoveryCapabilities: {\n ble,\n },\n },\n passcode: setupPin,\n } as NodeCommissioningOptions;\n logger.info(`Commissioning ... ${Logger.toJSON(options)}`);\n const nodeId = await commissioningController.commissionNode(options);\n\n console.log(`Commissioning successfully done with nodeId ${nodeId}`);\n }\n\n /**\n * TBD\n */\n try {\n const nodes = commissioningController.getCommissionedNodes();\n console.log(\"Found commissioned nodes:\", Logger.toJSON(nodes));\n\n const nodeId = NodeId(getIntParameter(\"nodeid\") ?? nodes[0]);\n if (!nodes.includes(nodeId)) {\n throw new Error(`Node ${nodeId} not found in commissioned nodes`);\n }\n\n const node = await commissioningController.connectNode(nodeId, {\n attributeChangedCallback: (\n peerNodeId,\n { path: { nodeId, clusterId, endpointId, attributeName }, value },\n ) =>\n console.log(\n `attributeChangedCallback ${peerNodeId}: Attribute ${nodeId}/${endpointId}/${clusterId}/${attributeName} changed to ${Logger.toJSON(\n value,\n )}`,\n ),\n eventTriggeredCallback: (peerNodeId, { path: { nodeId, clusterId, endpointId, eventName }, events }) =>\n console.log(\n `eventTriggeredCallback ${peerNodeId}: Event ${nodeId}/${endpointId}/${clusterId}/${eventName} triggered with ${Logger.toJSON(\n events,\n )}`,\n ),\n stateInformationCallback: (peerNodeId, info) => {\n switch (info) {\n case NodeStateInformation.Connected:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} connected`);\n break;\n case NodeStateInformation.Disconnected:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} disconnected`);\n break;\n case NodeStateInformation.Reconnecting:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} reconnecting`);\n break;\n case NodeStateInformation.WaitingForDeviceDiscovery:\n console.log(\n `stateInformationCallback ${peerNodeId}: Node ${nodeId} waiting for device discovery`,\n );\n break;\n case NodeStateInformation.StructureChanged:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} structure changed`);\n break;\n case NodeStateInformation.Decommissioned:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} decommissioned`);\n break;\n }\n },\n });\n\n // Important: This is a temporary API to proof the methods working and this will change soon and is NOT stable!\n // It is provided to proof the concept\n\n node.logStructure();\n\n // Example to initialize a ClusterClient and access concrete fields as API methods\n const descriptor = node.getRootClusterClient(DescriptorCluster);\n if (descriptor !== undefined) {\n console.log(await descriptor.attributes.deviceTypeList.get()); // you can call that way\n console.log(await descriptor.getServerListAttribute()); // or more convenient that way\n } else {\n console.log(\"No Descriptor Cluster found. This should never happen!\");\n }\n\n // Example to subscribe to a field and get the value\n const info = node.getRootClusterClient(BasicInformationCluster);\n if (info !== undefined) {\n console.log(await info.getProductNameAttribute()); // This call is executed remotely\n //console.log(await info.subscribeProductNameAttribute(value => console.log(\"productName\", value), 5, 30));\n //console.log(await info.getProductNameAttribute()); // This call is resolved locally because we have subscribed to the value!\n } else {\n console.log(\"No BasicInformation Cluster found. This should never happen!\");\n }\n\n // Example to get all Attributes of the commissioned node: */*/*\n //const attributesAll = await interactionClient.getAllAttributes();\n //console.log(\"Attributes-All:\", Logger.toJSON(attributesAll));\n\n // Example to get all Attributes of all Descriptor Clusters of the commissioned node: */DescriptorCluster/*\n //const attributesAllDescriptor = await interactionClient.getMultipleAttributes([{ clusterId: DescriptorCluster.id} ]);\n //console.log(\"Attributes-Descriptor:\", JSON.stringify(attributesAllDescriptor, null, 2));\n\n // Example to get all Attributes of the Basic Information Cluster of endpoint 0 of the commissioned node: 0/BasicInformationCluster/*\n //const attributesBasicInformation = await interactionClient.getMultipleAttributes([{ endpointId: 0, clusterId: BasicInformationCluster.id} ]);\n //console.log(\"Attributes-BasicInformation:\", JSON.stringify(attributesBasicInformation, null, 2));\n\n const devices = node.getDevices();\n if (devices[0] && devices[0].number === 1) {\n // Example to subscribe to all Attributes of endpoint 1 of the commissioned node: */*/*\n //await interactionClient.subscribeMultipleAttributes([{ endpointId: 1, /* subscribe anything from endpoint 1 */ }], 0, 180, data => {\n // console.log(\"Subscribe-All Data:\", Logger.toJSON(data));\n //});\n\n const onOff = devices[0].getClusterClient(OnOffCluster);\n if (onOff !== undefined) {\n let onOffStatus = await onOff.getOnOffAttribute();\n console.log(\"initial onOffStatus\", onOffStatus);\n\n onOff.addOnOffAttributeListener(value => {\n console.log(\"subscription onOffStatus\", value);\n onOffStatus = value;\n });\n // read data every minute to keep up the connection to show the subscription is working\n setInterval(() => {\n onOff\n .toggle()\n .then(() => {\n onOffStatus = !onOffStatus;\n console.log(\"onOffStatus\", onOffStatus);\n })\n .catch(error => logger.error(error));\n }, 60000);\n }\n }\n } finally {\n //await matterServer.close(); // Comment out when subscribes are used, else the connection will be closed\n setTimeout(() => process.exit(0), 1000000);\n }\n }\n}\n\nnew ControllerNode().start().catch(error => logger.error(error));\n\nprocess.on(\"SIGINT\", () => {\n // Clean up on CTRL-C\n // Pragmatic way to make sure the storage is correctly closed before the process ends.\n storage.close();\n process.exit(0);\n});\n"],
5
- "mappings": ";AAEA;AAAA;AAAA;AAAA;AAAA;AAgBA,SAAS,yBAAyB,oBAA8C;AAEhF,SAAS,eAAe;AACxB,SAAS,WAAW;AACpB;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC,SAAS,QAAQ,OAAO,cAAc;AAEtC,SAAS,8BAA8B;AACvC,SAAS,oBAAoB,sBAAsB;AACnD;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,MAAM,SAAS,OAAO,IAAI,YAAY;AAEtC,sBAAsB,EAAE;AAGxB,QAAQ,aAAa,UAAU,GAAG;AAAA,EAC9B,KAAK;AACD,WAAO,kBAAkB,MAAM;AAC/B;AAAA,EACJ,KAAK;AACD,WAAO,kBAAkB,MAAM;AAC/B;AAAA,EACJ,KAAK;AACD,WAAO,kBAAkB,MAAM;AAC/B;AAAA,EACJ,KAAK;AACD,WAAO,kBAAkB,MAAM;AAC/B;AACR;AAEA,QAAQ,aAAa,WAAW,GAAG;AAAA,EAC/B,KAAK;AACD,WAAO,SAAS,OAAO;AACvB;AAAA,EACJ,KAAK;AACD,WAAO,SAAS,OAAO;AACvB;AAAA,EACJ;AACI,QAAI,QAAQ,OAAO,MAAO,QAAO,SAAS,OAAO;AACzD;A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,KAAK,CAAC,GAAG,GAAO;AAAA,IAC7C;AAAA,EACJ;AACJ;AAEA,IAAI,eAAe,EAAE,MAAM,EAAE,MAAM,WAAS,OAAO,MAAM,KAAK,CAAC;AAE/D,QAAQ,GAAG,UAAU,MAAM;AAGvB,UAAQ,MAAM;AACd,UAAQ,KAAK,CAAC;AAClB,CAAC;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2023 Project CHIP Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a Matter controller to pair with a device and interfact with it.\n * It can be used as CLI script, but is more thought as a starting point for your own controller implementation\n * because you need to adjust the code in any way depending on your use case.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport { CommissioningController, MatterServer, NodeCommissioningOptions } from \"@project-chip/matter-node.js\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { Ble } from \"@project-chip/matter-node.js/ble\";\nimport {\n BasicInformationCluster,\n DescriptorCluster,\n GeneralCommissioning,\n OnOffCluster,\n} from \"@project-chip/matter-node.js/cluster\";\nimport { NodeId } from \"@project-chip/matter-node.js/datatype\";\nimport { NodeStateInformation } from \"@project-chip/matter-node.js/device\";\nimport { Format, Level, Logger } from \"@project-chip/matter-node.js/log\";\nimport { CommissioningOptions } from \"@project-chip/matter-node.js/protocol\";\nimport { ManualPairingCodeCodec } from \"@project-chip/matter-node.js/schema\";\nimport { StorageBackendDisk, StorageManager } from \"@project-chip/matter-node.js/storage\";\nimport {\n getIntParameter,\n getParameter,\n hasParameter,\n requireMinNodeVersion,\n singleton,\n} from \"@project-chip/matter-node.js/util\";\n\nconst logger = Logger.get(\"Controller\");\n\nrequireMinNodeVersion(16);\n\n/** Configure logging */\nswitch (getParameter(\"loglevel\")) {\n case \"fatal\":\n Logger.defaultLogLevel = Level.FATAL;\n break;\n case \"error\":\n Logger.defaultLogLevel = Level.ERROR;\n break;\n case \"warn\":\n Logger.defaultLogLevel = Level.WARN;\n break;\n case \"info\":\n Logger.defaultLogLevel = Level.INFO;\n break;\n}\n\nswitch (getParameter(\"logformat\")) {\n case \"plain\":\n Logger.format = Format.PLAIN;\n break;\n case \"html\":\n Logger.format = Format.HTML;\n break;\n default:\n if (process.stdin?.isTTY) Logger.format = Format.ANSI;\n}\n\nif (hasParameter(\"ble\")) {\n // Initialize Ble\n Ble.get = singleton(\n () =>\n new BleNode({\n hciId: getIntParameter(\"ble-hci-id\"),\n }),\n );\n}\n\nconst storageLocation = getParameter(\"store\") ?? \".controller-node\";\nconst storage = new StorageBackendDisk(storageLocation, hasParameter(\"clearstorage\"));\nlogger.info(`Storage location: ${storageLocation} (Directory)`);\nlogger.info(\n 'Use the parameter \"-store NAME\" to specify a different storage location, use -clearstorage to start with an empty storage.',\n);\n\nclass ControllerNode {\n async start() {\n logger.info(`node-matter Controller started`);\n\n /**\n * Initialize the storage system.\n *\n * The storage manager is then also used by the Matter server, so this code block in general is required,\n * but you can choose a different storage backend as long as it implements the required API.\n */\n\n const storageManager = new StorageManager(storage);\n await storageManager.initialize();\n\n /**\n * Collect all needed data\n *\n * This block makes sure to collect all needed data from cli or storage. Replace this with where ever your data\n * come from.\n *\n * Note: This example also uses the initialized storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own contexts\n * (so maybe better not ;-)).\n */\n\n const controllerStorage = storageManager.createContext(\"Controller\");\n const ip = controllerStorage.has(\"ip\") ? controllerStorage.get<string>(\"ip\") : getParameter(\"ip\");\n const port = controllerStorage.has(\"port\") ? controllerStorage.get<number>(\"port\") : getIntParameter(\"port\");\n\n const pairingCode = getParameter(\"pairingcode\");\n let longDiscriminator, setupPin, shortDiscriminator;\n if (pairingCode !== undefined) {\n const pairingCodeCodec = ManualPairingCodeCodec.decode(pairingCode);\n shortDiscriminator = pairingCodeCodec.shortDiscriminator;\n longDiscriminator = undefined;\n setupPin = pairingCodeCodec.passcode;\n logger.debug(`Data extracted from pairing code: ${Logger.toJSON(pairingCodeCodec)}`);\n } else {\n longDiscriminator =\n getIntParameter(\"longDiscriminator\") ?? controllerStorage.get(\"longDiscriminator\", 3840);\n if (longDiscriminator > 4095) throw new Error(\"Discriminator value must be less than 4096\");\n setupPin = getIntParameter(\"pin\") ?? controllerStorage.get(\"pin\", 20202021);\n }\n if ((shortDiscriminator === undefined && longDiscriminator === undefined) || setupPin === undefined) {\n throw new Error(\n \"Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode\",\n );\n }\n\n // Collect commissioning options from commandline parameters\n const commissioningOptions: CommissioningOptions = {\n regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,\n regulatoryCountryCode: \"XX\",\n };\n\n let ble = false;\n if (hasParameter(\"ble\")) {\n ble = true;\n const wifiSsid = getParameter(\"ble-wifi-ssid\");\n const wifiCredentials = getParameter(\"ble-wifi-credentials\");\n const threadNetworkName = getParameter(\"ble-thread-networkname\");\n const threadOperationalDataset = getParameter(\"ble-thread-operationaldataset\");\n if (wifiSsid !== undefined && wifiCredentials !== undefined) {\n logger.info(`Registering Commissioning over BLE with WiFi: ${wifiSsid}`);\n commissioningOptions.wifiNetwork = {\n wifiSsid: wifiSsid,\n wifiCredentials: wifiCredentials,\n };\n }\n if (threadNetworkName !== undefined && threadOperationalDataset !== undefined) {\n logger.info(`Registering Commissioning over BLE with Thread: ${threadNetworkName}`);\n commissioningOptions.threadNetwork = {\n networkName: threadNetworkName,\n operationalDataset: threadOperationalDataset,\n };\n }\n }\n\n /**\n * Create Matter Server and Controller Node\n *\n * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a\n * CommissioningController to it and add the just created device instance to it.\n * The Controller node defines the port where the server listens for the UDP packages of the Matter protocol\n * and initializes deice specific certificates and such.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled internally\n * like testEventTrigger (General Diagnostic Cluster) that can be implemented with the logic when these commands\n * are called.\n */\n\n const matterServer = new MatterServer(storageManager);\n const commissioningController = new CommissioningController({\n autoConnect: false,\n });\n await matterServer.addCommissioningController(commissioningController);\n\n /**\n * Start the Matter Server\n *\n * After everything was plugged together we can start the server. When not delayed announcement is set for the\n * CommissioningServer node then this command also starts the announcement of the device into the network.\n */\n\n await matterServer.start();\n\n if (!commissioningController.isCommissioned()) {\n const options = {\n commissioning: commissioningOptions,\n discovery: {\n knownAddress: ip !== undefined && port !== undefined ? { ip, port, type: \"udp\" } : undefined,\n identifierData:\n longDiscriminator !== undefined\n ? { longDiscriminator }\n : shortDiscriminator !== undefined\n ? { shortDiscriminator }\n : {},\n discoveryCapabilities: {\n ble,\n },\n },\n passcode: setupPin,\n } as NodeCommissioningOptions;\n logger.info(`Commissioning ... ${Logger.toJSON(options)}`);\n const nodeId = await commissioningController.commissionNode(options);\n\n console.log(`Commissioning successfully done with nodeId ${nodeId}`);\n }\n\n /**\n * TBD\n */\n try {\n const nodes = commissioningController.getCommissionedNodes();\n console.log(\"Found commissioned nodes:\", Logger.toJSON(nodes));\n\n const nodeId = NodeId(getIntParameter(\"nodeid\") ?? nodes[0]);\n if (!nodes.includes(nodeId)) {\n throw new Error(`Node ${nodeId} not found in commissioned nodes`);\n }\n\n const node = await commissioningController.connectNode(nodeId, {\n attributeChangedCallback: (\n peerNodeId,\n { path: { nodeId, clusterId, endpointId, attributeName }, value },\n ) =>\n console.log(\n `attributeChangedCallback ${peerNodeId}: Attribute ${nodeId}/${endpointId}/${clusterId}/${attributeName} changed to ${Logger.toJSON(\n value,\n )}`,\n ),\n eventTriggeredCallback: (peerNodeId, { path: { nodeId, clusterId, endpointId, eventName }, events }) =>\n console.log(\n `eventTriggeredCallback ${peerNodeId}: Event ${nodeId}/${endpointId}/${clusterId}/${eventName} triggered with ${Logger.toJSON(\n events,\n )}`,\n ),\n stateInformationCallback: (peerNodeId, info) => {\n switch (info) {\n case NodeStateInformation.Connected:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} connected`);\n break;\n case NodeStateInformation.Disconnected:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} disconnected`);\n break;\n case NodeStateInformation.Reconnecting:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} reconnecting`);\n break;\n case NodeStateInformation.WaitingForDeviceDiscovery:\n console.log(\n `stateInformationCallback ${peerNodeId}: Node ${nodeId} waiting for device discovery`,\n );\n break;\n case NodeStateInformation.StructureChanged:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} structure changed`);\n break;\n case NodeStateInformation.Decommissioned:\n console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} decommissioned`);\n break;\n }\n },\n });\n\n // Important: This is a temporary API to proof the methods working and this will change soon and is NOT stable!\n // It is provided to proof the concept\n\n node.logStructure();\n\n // Example to initialize a ClusterClient and access concrete fields as API methods\n const descriptor = node.getRootClusterClient(DescriptorCluster);\n if (descriptor !== undefined) {\n console.log(await descriptor.attributes.deviceTypeList.get()); // you can call that way\n console.log(await descriptor.getServerListAttribute()); // or more convenient that way\n } else {\n console.log(\"No Descriptor Cluster found. This should never happen!\");\n }\n\n // Example to subscribe to a field and get the value\n const info = node.getRootClusterClient(BasicInformationCluster);\n if (info !== undefined) {\n console.log(await info.getProductNameAttribute()); // This call is executed remotely\n //console.log(await info.subscribeProductNameAttribute(value => console.log(\"productName\", value), 5, 30));\n //console.log(await info.getProductNameAttribute()); // This call is resolved locally because we have subscribed to the value!\n } else {\n console.log(\"No BasicInformation Cluster found. This should never happen!\");\n }\n\n // Example to get all Attributes of the commissioned node: */*/*\n //const attributesAll = await interactionClient.getAllAttributes();\n //console.log(\"Attributes-All:\", Logger.toJSON(attributesAll));\n\n // Example to get all Attributes of all Descriptor Clusters of the commissioned node: */DescriptorCluster/*\n //const attributesAllDescriptor = await interactionClient.getMultipleAttributes([{ clusterId: DescriptorCluster.id} ]);\n //console.log(\"Attributes-Descriptor:\", JSON.stringify(attributesAllDescriptor, null, 2));\n\n // Example to get all Attributes of the Basic Information Cluster of endpoint 0 of the commissioned node: 0/BasicInformationCluster/*\n //const attributesBasicInformation = await interactionClient.getMultipleAttributes([{ endpointId: 0, clusterId: BasicInformationCluster.id} ]);\n //console.log(\"Attributes-BasicInformation:\", JSON.stringify(attributesBasicInformation, null, 2));\n\n const devices = node.getDevices();\n if (devices[0] && devices[0].number === 1) {\n // Example to subscribe to all Attributes of endpoint 1 of the commissioned node: */*/*\n //await interactionClient.subscribeMultipleAttributes([{ endpointId: 1, /* subscribe anything from endpoint 1 */ }], 0, 180, data => {\n // console.log(\"Subscribe-All Data:\", Logger.toJSON(data));\n //});\n\n const onOff = devices[0].getClusterClient(OnOffCluster);\n if (onOff !== undefined) {\n let onOffStatus = await onOff.getOnOffAttribute();\n console.log(\"initial onOffStatus\", onOffStatus);\n\n onOff.addOnOffAttributeListener(value => {\n console.log(\"subscription onOffStatus\", value);\n onOffStatus = value;\n });\n // read data every minute to keep up the connection to show the subscription is working\n setInterval(() => {\n onOff\n .toggle()\n .then(() => {\n onOffStatus = !onOffStatus;\n console.log(\"onOffStatus\", onOffStatus);\n })\n .catch(error => logger.error(error));\n }, 60000);\n }\n }\n } finally {\n //await matterServer.close(); // Comment out when subscribes are used, else the connection will be closed\n setTimeout(() => process.exit(0), 1000000);\n }\n }\n}\n\nnew ControllerNode().start().catch(error => logger.error(error));\n\nprocess.on(\"SIGINT\", () => {\n // Clean up on CTRL-C\n // Pragmatic way to make sure the storage is correctly closed before the process ends.\n storage.close();\n process.exit(0);\n});\n"],
5
+ "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAgBA,SAAS,yBAAyB,oBAA8C;AAEhF,SAAS,eAAe;AACxB,SAAS,WAAW;AACpB;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC,SAAS,QAAQ,OAAO,cAAc;AAEtC,SAAS,8BAA8B;AACvC,SAAS,oBAAoB,sBAAsB;A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AChC,UAAI,QAAQ,CAAC,KAAK,QAAQ,CAAC,EAAE,WAAW,GAAG;AAMvC,cAAM,QAAQ,QAAQ,CAAC,EAAE,iBAAiB,YAAY;AACtD,YAAI,UAAU,QAAW;AACrB,cAAI,cAAc,MAAM,MAAM,kBAAkB;AAChD,kBAAQ,IAAI,uBAAuB,WAAW;AAE9C,gBAAM,0BAA0B,WAAS;AACrC,oBAAQ,IAAI,4BAA4B,KAAK;AAC7C,0BAAc;AAAA,UAClB,CAAC;AAED,sBAAY,MAAM;AACd,kBACK,OAAO,EACP,KAAK,MAAM;AACR,4BAAc,CAAC;AACf,sBAAQ,IAAI,eAAe,WAAW;AAAA,YAC1C,CAAC,EACA,MAAM,WAAS,OAAO,MAAM,KAAK,CAAC;AAAA,UAC3C,GAAG,GAAK;AAAA,QACZ;AAAA,MACJ;AAAA,IACJ,UAAE;AAEE,iBAAW,MAAM,QAAQ,KAAK,CAAC,GAAG,GAAO;AAAA,IAC7C;AAAA,EACJ;AACJ;AAEA,IAAI,eAAe,EAAE,MAAM,EAAE,MAAM,WAAS,OAAO,MAAM,KAAK,CAAC;AAE/D,QAAQ,GAAG,UAAU,MAAM;AAGvB,UAAQ,MAAM;AACd,UAAQ,KAAK,CAAC;AAClB,CAAC;",
6
6
  "names": ["nodeId", "info"]
7
7
  }
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/DeviceNode.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a simple on-off Matter device as a light or as a socket.\n * It can be used as CLI script and starting point for your own device node implementation.\n * This example is CJS conform and do not use top level await's.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\nasync function main() {\n /** Initialize configuration values */\n const {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n } = await getConfiguration();\n\n /**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\n const server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(isSocket ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType),\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n });\n\n /**\n * Matter Nodes are a composition of endpoints. Create and add a single endpoint to the node. This example uses the\n * OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type parameter. It also assigns this Part a\n * unique ID to store the endpoint number for it in the storage to restore the device on restart.\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n const endpoint = new Endpoint(isSocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: \"onoff\" });\n await server.add(endpoint);\n\n /**\n * Register state change handlers and events of the node for identify and onoff states to react to the commands.\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic ...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? \"on\" : \"off\");\n console.log(`OnOff is now ${value ? \"ON\" : \"OFF\"}`);\n });\n\n /**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\n logEndpoint(EndpointServer.forEndpoint(server));\n\n /**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\n await server.run();\n}\n\nmain().catch(error => console.error(error));\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/** Defined a shell command from an environment variable and execute it and log the response. */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n /**\n * Collect all needed data\n *\n * This block collects all needed data from cli, environment or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isSocket = await deviceStorage.get(\"isSocket\", environment.vars.get(\"type\") === \"socket\");\n if (await deviceStorage.has(\"isSocket\")) {\n console.log(`Device type ${isSocket ? \"socket\" : \"light\"} found in storage. --type parameter is ignored.`);\n }\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs())).toString();\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n });\n\n return {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n };\n}\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,OAAO;AAEP,SAAS,6BAA6B;AACtC,SAAS,cAAc,gBAAgB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,UAAU,sBAAsB;AACzC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAEzB,sBAAsB,EAAE;AAExB,eAAe,OAAO;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AU;AAAA,IACV,WAAW;AAAA,IACX;AAAA,IACA,UAAU;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a simple on-off Matter device as a light or as a socket.\n * It can be used as CLI script and starting point for your own device node implementation.\n * This example is CJS conform and do not use top level await's.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\nasync function main() {\n /** Initialize configuration values */\n const {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n } = await getConfiguration();\n\n /**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\n const server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(isSocket ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType),\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n });\n\n /**\n * Matter Nodes are a composition of endpoints. Create and add a single endpoint to the node. This example uses the\n * OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type parameter. It also assigns this Part a\n * unique ID to store the endpoint number for it in the storage to restore the device on restart.\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n const endpoint = new Endpoint(isSocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: \"onoff\" });\n await server.add(endpoint);\n\n /**\n * Register state change handlers and events of the node for identify and onoff states to react to the commands.\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic ...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? \"on\" : \"off\");\n console.log(`OnOff is now ${value ? \"ON\" : \"OFF\"}`);\n });\n\n /**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\n logEndpoint(EndpointServer.forEndpoint(server));\n\n /**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\n await server.run();\n}\n\nmain().catch(error => console.error(error));\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/** Defined a shell command from an environment variable and execute it and log the response. */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n /**\n * Collect all needed data\n *\n * This block collects all needed data from cli, environment or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isSocket = await deviceStorage.get(\"isSocket\", environment.vars.get(\"type\") === \"socket\");\n if (await deviceStorage.has(\"isSocket\")) {\n console.log(`Device type ${isSocket ? \"socket\" : \"light\"} found in storage. --type parameter is ignored.`);\n }\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs())).toString();\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n });\n\n return {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n };\n}\n"],
5
+ "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAgBA,OAAO;AAEP,SAAS,6BAA6B;AACtC,SAAS,cAAc,gBAAgB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,UAAU,sBAAsB;AACzC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAEzB,sBAAsB,EAAE;AAExB,eAAe,OAAO;AAElB,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI,MAAM,iBAAiB;AAK3B,QAAM,SAAS,MAAM,WAAW,OAAO;AAAA;AAAA,IAEnC,IAAI;AAAA;AAAA;AAAA,IAIJ,SAAS;AAAA,MACL;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,eAAe;AAAA,MACX;AAAA,MACA;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,oBAAoB;AAAA,MAChB,MAAM;AAAA,MACN,YAAY,aAAa,WAAW,sBAAsB,aAAa,iBAAiB,UAAU;AAAA,IACtG;AAAA;AAAA;AAAA,IAIA,kBAAkB;AAAA,MACd;AAAA,MACA,UAAU,SAAS,QAAQ;AAAA,MAC3B,WAAW;AAAA,MACX;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA,cAAc,YAAY,QAAQ;AAAA,MAClC;AAAA,IACJ;AAAA,EACJ,CAAC;AASD,QAAM,WAAW,IAAI,SAAS,WAAW,wBAAwB,kBAAkB,EAAE,IAAI,QAAQ,CAAC;AAClG,QAAM,OAAO,IAAI,QAAQ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AK,OAAO,eAAe,KAAM,MAAM,cAAc,IAAI,iBAAiB,IAAI;AAEhH,QAAM,WAAW,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAM;AACnG,QAAM,cAAc,qBAAqB,WAAW,WAAW,OAAO;AACtE,QAAM,YAAY,YAAY,KAAK,OAAO,WAAW,KAAM,MAAM,cAAc,IAAI,aAAa,KAAM;AAEtG,QAAM,OAAO,YAAY,KAAK,OAAO,MAAM,KAAK;AAEhD,QAAM,WACF,YAAY,KAAK,OAAO,UAAU,MAAM,MAAM,cAAc,IAAI,YAAY,KAAK,MAAM,CAAC,GAAG,SAAS;AAGxG,QAAM,cAAc,IAAI;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,WAAW;AAAA,IACX;AAAA,IACA,UAAU;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/DeviceNodeFull.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example is not optimized for simplicity, but to show all the advanced use cases for matter.js.\n * If you want to see a simple minimalistic and more standard example please look at DeviceNode.ts or the other examples.\n *\n * This example shows how to create a simple on-off Matter device as a light or as a socket.\n * It can be used as CLI script and starting point for your own device node implementation.\n * Additional to this it shows the following:\n * * How to modify the existing clusters on Root and also Device Endpoints\n * * How to add own Cluster implementations for Standard clusters\n * * How to add a custom Cluster to an Endpoint\n * * Which events are available to get status information from the Node aon commissioning and session/subscription changes\n * * How to get cluster state values\n * * How to set one or multiple state values in a transaction.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { GeneralDiagnostics } from \"@project-chip/matter-node.js/cluster\";\nimport { createFileLogger } from \"@project-chip/matter-node.js/log\";\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { NetworkCommissioningServer } from \"@project-chip/matter.js/behavior/definitions/network-commissioning\";\nimport { OnOffServer } from \"@project-chip/matter.js/behavior/definitions/on-off\";\nimport { Ble } from \"@project-chip/matter.js/ble\";\nimport { NetworkCommissioning } from \"@project-chip/matter.js/cluster\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { RootRequirements } from \"@project-chip/matter.js/endpoint/definitions\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { FabricAction } from \"@project-chip/matter.js/fabric\";\nimport { Level, Logger, levelFromString } from \"@project-chip/matter.js/log\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { QrCode } from \"@project-chip/matter.js/schema\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { ByteArray, singleton } from \"@project-chip/matter.js/util\";\nimport { execSync } from \"child_process\";\nimport { DummyThreadNetworkCommissioningServer } from \"./cluster/DummyThreadNetworkCommissioningServer.js\";\nimport { DummyWifiNetworkCommissioningServer } from \"./cluster/DummyWifiNetworkCommissioningServer.js\";\nimport {\n MyFancyCommandRequest,\n MyFancyCommandResponse,\n MyFancyOwnFunctionalityBehavior,\n} from \"./cluster/MyFancyOwnFunctionality.js\";\n\n/**\n * The following code brings some convenience to the CLI script. It allows to set the log level and format via\n * command line parameters. It also initializes the BLE stack if the `--ble` parameter is present.\n * Some of these parameters can also be replaced by generically accepted parameters or even environment variables. See the comments in the relevant places for information.\n * When using this code as basis for your own device node implementation, you can remove this part or hard code it.\n */\n\nrequireMinNodeVersion(16);\n\n// To configure Logging use\n// * \"--log-level\" or environment variable \"MATTER_LOG_LEVEL\" or \"environment.vars.set('log.level', Level.DEBUG)\"\n// Allowed values are: Level.FATAL, Level.ERROR, Level.WARN, Level.NOTICE, Level.INFO, Level.DEBUG\n// * \"--log-format\" or environment variable \"MATTER_LOG_FORMAT\" or \"environment.vars.set('log.format', Format.PLAIN)\"\n// Allowed values are: Format.PLAIN, Format.HTML, Format.ANSI,\n\nconst environment = Environment.default;\n\n// Alternatively \"--ble-enable\" or environment variable \"BLE_ENABLED\"\n// Alternatively \"--ble-hciId\" or environment variable \"BLE_HCIID\"\nif (environment.vars.get(\"ble.enable\")) {\n // Initialize Ble\n Ble.get = singleton(\n () =>\n new BleNode({\n hciId: environment.vars.number(\"ble.hciId\"),\n }),\n );\n}\n\nfunction executeCommand(scriptParamName: string) {\n const script = environment.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\n/**\n * Collect all needed data\n *\n * This block collects all needed data from cli or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n\nconst logFile = environment.vars.string(\"logfile.filename\");\nif (logFile !== undefined) {\n Logger.addLogger(\"filelogger\", await createFileLogger(logFile), {\n defaultLogLevel: levelFromString(environment.vars.string(\"logfile.loglevel\")) ?? Level.DEBUG,\n });\n}\n\nconst storageService = environment.get(StorageService);\nconsole.log(`Storage location: ${storageService.location} (Directory)`);\nconsole.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n);\n\nconst deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\nif (await deviceStorage.has(\"isSocket\")) {\n console.log(\"Device type found in storage. --type parameter is ignored.\");\n}\nconst isSocket = await deviceStorage.get(\"isSocket\", environment.vars.string(\"type\") === \"socket\");\nconst deviceName = \"Matter test device\";\nconst vendorName = \"matter-node.js\";\nconst passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\nconst discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n// product name / id and vendor id should match what is in the device certificate\nconst vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\nconst productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\nconst productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\nconst port = environment.vars.number(\"port\") ?? 5540;\n\nconst uniqueId = environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\nawait deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n});\n\n// Matter exposes functionality in groups called \"clusters\". For this example device we override the matter.js \"On/Off\"\n// cluster implementation to print status to the console.\nclass OnOffShellExecServer extends OnOffServer {\n // Intercept the \"on\" command to the Matter On/Off cluster to print a log message.\n override async on() {\n executeCommand(\"on\");\n await super.on();\n }\n\n // This is the functional inverse of on() above.\n //\n // For demonstration purposes we update state ourselves rather than deferring to matter.js's default \"off\" handler\n // via super.off().\n override async off() {\n executeCommand(\"off\");\n this.state.onOff = false;\n }\n\n // Use event handlers to log on/off state reactively, after it changes.\n override initialize() {\n this.events.onOff$Changed.on(value => {\n console.log(`Light is now ${value ? \"ON\" : \"OFF\"}`);\n });\n }\n}\n\nclass TestGeneralDiagnosticsServer extends RootRequirements.GeneralDiagnosticsServer {\n override initialize() {\n this.state.testEventTriggersEnabled = true; // set to true if you support test triggers ...\n super.initialize();\n }\n\n override testEventTrigger({ enableKey, eventTrigger }: GeneralDiagnostics.TestEventTriggerRequest) {\n console.log(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`);\n }\n}\n\nclass MyFancyOwnFunctionalityServer extends MyFancyOwnFunctionalityBehavior {\n /** We return the incoming value and store the length of the string in our attribute and send it out as event */\n override myFancyCommand(request: MyFancyCommandRequest): MyFancyCommandResponse {\n const { value } = request;\n this.state.myFancyValue = value.length;\n\n this.events.myFancyEvent.emit({ eventValue: value }, this.context);\n\n return { response: value };\n }\n\n override initialize() {\n this.state.myFancyValue = -1; // Always initialize with -1\n }\n}\n\n/**\n * Create Device instance and add needed Listener\n *\n * Create an instance of the matter device class you want to use.\n * This example uses the OnOffLightDevice or OnOffPluginUnitDevice depending on the value of the type parameter.\n * To execute the on/off scripts defined as parameters a listener for the onOff attribute is registered via the\n * device specific API.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled device internally\n * like identify that can be implemented with the logic when these commands are called.\n */\n\n// Devices are compositions of behaviors like OnOffServer above. To extend an existing device you use builder methods.\n//\n// In this case we are using with() to install our On/Off cluster behavior.\n// .with(\"Lighting\") not needed because we always have it in by default because we have default implementation\nconst OnOffDevice = isSocket\n ? vendorId === 0xfff4\n ? OnOffPlugInUnitDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer)\n : OnOffPlugInUnitDevice.with(OnOffShellExecServer)\n : vendorId === 0xfff4\n ? OnOffLightDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer)\n : OnOffLightDevice.with(OnOffShellExecServer);\n\n/**\n * Modify automatically added clusters of the Root endpoint if needed\n * In this example we change the networkCommissioning cluster into one for \"Wifi only\" devices when BLE is used\n * for commissioning, to demonstrate how to do this.\n * If you want to implement Ethernet only devices that get connected to the network via LAN/Ethernet cable,\n * then all this is not needed.\n * The same as shown here for Wi-Fi is also possible theoretical for Thread only or combined devices.\n */\n\n// We use the Basic Root Endpoint without a NetworkCommissioning cluster\nlet RootEndpoint = ServerNode.RootEndpoint.with(TestGeneralDiagnosticsServer);\n\nlet wifiOrThreadAdded = false;\nif (Ble.enabled) {\n // matter.js will create a Ethernet-only device by default when ut comes to Network Commissioning Features.\n // To offer e.g. a \"Wi-Fi only device\" (or any other combination) we need to override the Network Commissioning\n // cluster and implement all the need handling here. This is a \"static implementation\" for pure demonstration\n // purposes and just \"simulates\" the actions to be done. In a real world implementation this would be done by\n // the device implementor based on the relevant networking stack.\n // The NetworkCommissioningCluster and all logics are described in Matter Core Specifications section 11.8\n if (environment.vars.has(\"ble.wifi.fake\")) {\n RootEndpoint = RootEndpoint.with(DummyWifiNetworkCommissioningServer);\n wifiOrThreadAdded = true;\n } else if (environment.vars.has(\"ble.thread.fake\")) {\n RootEndpoint = RootEndpoint.with(DummyThreadNetworkCommissioningServer);\n wifiOrThreadAdded = true;\n }\n} else {\n RootEndpoint = RootEndpoint.with(\n NetworkCommissioningServer.with(NetworkCommissioning.Feature.EthernetNetworkInterface),\n );\n}\n\nconst networkId = new ByteArray(32);\n// Physical devices appear as \"nodes\" on a Matter network. As a device implementer you use a NodeServer to bring a\n// device online.\n//\n// Note there are a large number of options to NodeServer that we are allowing to take default values here. See\n// CompositeWindowCovering.ts for a more detailed example.\nconst server = await ServerNode.create(RootEndpoint, {\n id: uniqueId,\n network: {\n port,\n discoveryCapabilities: {\n onIpNetwork: !environment.vars.has(\"ble.enable\"),\n ble: environment.vars.has(\"ble.enable\"),\n },\n ble: environment.vars.has(\"ble.enable\"), // TODO remove when state init is fixed\n },\n commissioning: {\n passcode,\n discriminator,\n },\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(OnOffDevice.deviceType),\n },\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `node-matter-${uniqueId}`,\n uniqueId,\n },\n\n // @ts-expect-error ... TS do not see the types because both next clusters was added conditionally\n networkCommissioning: {\n maxNetworks: 1,\n interfaceEnabled: true,\n lastConnectErrorValue: 0,\n lastNetworkId: wifiOrThreadAdded ? null : networkId,\n lastNetworkingStatus: wifiOrThreadAdded ? null : NetworkCommissioning.NetworkCommissioningStatus.Success,\n networks: [{ networkId: networkId, connected: !wifiOrThreadAdded }],\n scanMaxTimeSeconds: wifiOrThreadAdded ? 3 : undefined,\n connectMaxTimeSeconds: wifiOrThreadAdded ? 3 : undefined,\n },\n myFancyFunctionality: {\n myFancyValue: 0,\n },\n});\n\n// Nodes are a composition of endpoints. Add a single endpoint to the node, our example light device.\nconst endpoint = new Endpoint(OnOffDevice, { id: \"onoff\" });\nawait server.add(endpoint);\n\n/**\n * This event is triggered when the device is initially commissioned successfully.\n * This means: It is added to the first fabric.\n */\nserver.lifecycle.commissioned.on(() => console.log(\"Server was initially commissioned successfully!\"));\n\n/** This event is triggered when all fabrics are removed from the device, usually it also does a factory reset then. */\nserver.lifecycle.decommissioned.on(() => console.log(\"Server was fully decommissioned successfully!\"));\n\n/** This event is triggered when the device went online. This means that it is discoverable in the network. */\nserver.lifecycle.online.on(() => console.log(\"Server is online\"));\n\n/** This event is triggered when the device went offline. it is not longer discoverable or connectable in the network. */\nserver.lifecycle.offline.on(() => console.log(\"Server is offline\"));\n\n/**\n * This event is triggered when a fabric is added, removed or updated on the device. Use this if more granular\n * information is needed.\n */\nserver.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {\n let action = \"\";\n switch (fabricAction) {\n case FabricAction.Added:\n action = \"added\";\n break;\n case FabricAction.Removed:\n action = \"removed\";\n break;\n case FabricAction.Updated:\n action = \"updated\";\n break;\n }\n console.log(`Commissioned Fabrics changed event (${action}) for ${fabricIndex} triggered`);\n console.log(server.state.commissioning.fabrics[fabricIndex]);\n});\n\n/**\n * This event is triggered when an operative new session was opened by a Controller.\n * It is not triggered for the initial commissioning process, just afterwards for real connections.\n */\nserver.events.sessions.opened.on(session => console.log(`Session opened`, session));\n\n/**\n * This event is triggered when an operative session is closed by a Controller or because the Device goes offline.\n */\nserver.events.sessions.closed.on(session => console.log(`Session closed`, session));\n\n/** This event is triggered when a subscription gets added or removed on an operative session. */\nserver.events.sessions.subscriptionsChanged.on(session => {\n console.log(`Session subscriptions changed`, session);\n console.log(`Status of all sessions`, server.state.sessions.sessions);\n});\n\n// React on a change of identificationTime to do Identify stuff for the own device\nendpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic, ideally blink a light every 0.5s ...`);\n});\n\nendpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic ...`);\n});\n\n// Our device is now built and we can bring the node online.\n//\n// Note that you may serve multiple nodes from a single process. We only have one, however, so we can use the run()\n// method of the node.\n\nlogEndpoint(EndpointServer.forEndpoint(server));\n\n/**\n * In order to start the node and announce it into the network we start the node. This method resolves when the Matter\n * node enters his online state. Alternatively, we could also use `await server.run()` which\n * resolves when the node goes offline again, but we want to execute code afterwards, so we use start() here\n */\nawait server.bringOnline();\n\nconsole.log(\"Initial Fabrics\", server.state.operationalCredentials.fabrics);\n\n/**\n * If the node is not commissioned already we display the QR code on console. The QR code is also logged\n */\nif (!server.lifecycle.isCommissioned) {\n const { qrPairingCode, manualPairingCode } = server.state.commissioning.pairingCodes;\n\n console.log(QrCode.get(qrPairingCode));\n console.log(`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`);\n console.log(`Manual pairing code: ${manualPairingCode}`);\n} else {\n console.log(\"Device is already commissioned. Waiting for controllers to connect ...\");\n\n /**\n * Sometimes reading or writing attributes is required. The following code shows how this works.\n * For read it is basically `endpoint.state.clustername.attributename`.\n * The set method allows to set one or multiple values via the structure of also clustername.attributename. When multiple values are set they are considered being one transaction which would be rolled back completely if one value fails to be set.\n */\n\n // Read onOff attribute from onOff cluster\n const onOffValue = endpoint.state.onOff.onOff;\n console.log(`current OnOff attribute: ${onOffValue}`);\n\n if (vendorId === 0xfff4) {\n // Set onOff attribute from OnOff cluster AND the myFancyValue of the MyFancyOwnFunctionality cluster together\n await endpoint.set({\n onOff: {\n onOff: !onOffValue,\n },\n // @ts-expect-error Needed because the Fancy cluster is added conditionally, so TS do not get that it's there.\n myFancyOwnFunctionality: {\n myFancyValue: 36,\n },\n });\n } else {\n // Set onOff attribute from OnOff cluster only\n await endpoint.set({\n onOff: {\n onOff: !onOffValue,\n },\n });\n }\n}\n\n/**\n * To correctly tear down the now we can use server[Symbol.asyncDispose]().\n */\nprocess.on(\"SIGINT\", () => {\n // Clean up on CTRL-C\n server\n .close()\n .then(() => process.exit(0))\n .catch(err => console.error(err));\n});\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,OAAO;AAEP,SAAS,eAAe;AAExB,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AACpB,SAAS,4BAA4B;AACrC,SAAS,cAAc,gBAAgB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,UAAU,sBAAsB;AACzC,SAAS,wBAAwB;AACjC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,oBAAoB;AAC7B,SAAS,OAAO,QAAQ,uBAAuB;AAC/C,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,WAAW,iBAAiB;AACrC,SAAS,gBAAgB;AACzB,SAAS,6CAA6C;AACtD,SAAS,2CAA2C;AACpD;AAAA,EAGI;AAAA,OACG;AASP,sBAAsB,EAAE;AAQxB,MAAM,cAAc,YAAY;AAIhC,IAAI,YAAY,KAAK,IAAI,YAAY,GAAG;AAEpC,MAAI,MAAM;AAAA,IACN,MACI,IAAI,QAAQ;AAAA,MACR,OAAO,YAAY,KAAK,OAAO,WAAW;AA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AAS,iBAAiB,GAAG,MAAM;AAC/C,UAAQ,IAAI,0DAA0D;AAC1E,CAAC;AAED,SAAS,OAAO,SAAS,gBAAgB,GAAG,MAAM;AAC9C,UAAQ,IAAI,yBAAyB;AACzC,CAAC;AAOD,YAAY,eAAe,YAAY,MAAM,CAAC;AAO9C,MAAM,OAAO,YAAY;AAEzB,QAAQ,IAAI,mBAAmB,OAAO,MAAM,uBAAuB,OAAO;AAK1E,IAAI,CAAC,OAAO,UAAU,gBAAgB;AAClC,QAAM,EAAE,eAAe,kBAAkB,IAAI,OAAO,MAAM,cAAc;AAExE,UAAQ,IAAI,OAAO,IAAI,aAAa,CAAC;AACrC,UAAQ,IAAI,gFAAgF,aAAa,EAAE;AAC3G,UAAQ,IAAI,wBAAwB,iBAAiB,EAAE;AAC3D,OAAO;AACH,UAAQ,IAAI,wEAAwE;AASpF,QAAM,aAAa,SAAS,MAAM,MAAM;AACxC,UAAQ,IAAI,4BAA4B,UAAU,EAAE;AAEpD,MAAI,aAAa,OAAQ;AAErB,UAAM,SAAS,IAAI;AAAA,MACf,OAAO;AAAA,QACH,OAAO,CAAC;AAAA,MACZ;AAAA;AAAA,MAEA,yBAAyB;AAAA,QACrB,cAAc;AAAA,MAClB;AAAA,IACJ,CAAC;AAAA,EACL,OAAO;AAEH,UAAM,SAAS,IAAI;AAAA,MACf,OAAO;AAAA,QACH,OAAO,CAAC;AAAA,MACZ;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;AAKA,QAAQ,GAAG,UAAU,MAAM;AAEvB,SACK,MAAM,EACN,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC,EAC1B,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AACxC,CAAC;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example is not optimized for simplicity, but to show all the advanced use cases for matter.js.\n * If you want to see a simple minimalistic and more standard example please look at DeviceNode.ts or the other examples.\n *\n * This example shows how to create a simple on-off Matter device as a light or as a socket.\n * It can be used as CLI script and starting point for your own device node implementation.\n * Additional to this it shows the following:\n * * How to modify the existing clusters on Root and also Device Endpoints\n * * How to add own Cluster implementations for Standard clusters\n * * How to add a custom Cluster to an Endpoint\n * * Which events are available to get status information from the Node aon commissioning and session/subscription changes\n * * How to get cluster state values\n * * How to set one or multiple state values in a transaction.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { GeneralDiagnostics } from \"@project-chip/matter-node.js/cluster\";\nimport { createFileLogger } from \"@project-chip/matter-node.js/log\";\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { NetworkCommissioningServer } from \"@project-chip/matter.js/behavior/definitions/network-commissioning\";\nimport { OnOffServer } from \"@project-chip/matter.js/behavior/definitions/on-off\";\nimport { Ble } from \"@project-chip/matter.js/ble\";\nimport { NetworkCommissioning } from \"@project-chip/matter.js/cluster\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { RootRequirements } from \"@project-chip/matter.js/endpoint/definitions\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { FabricAction } from \"@project-chip/matter.js/fabric\";\nimport { Level, Logger, levelFromString } from \"@project-chip/matter.js/log\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { QrCode } from \"@project-chip/matter.js/schema\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { ByteArray, singleton } from \"@project-chip/matter.js/util\";\nimport { execSync } from \"child_process\";\nimport { DummyThreadNetworkCommissioningServer } from \"./cluster/DummyThreadNetworkCommissioningServer.js\";\nimport { DummyWifiNetworkCommissioningServer } from \"./cluster/DummyWifiNetworkCommissioningServer.js\";\nimport {\n MyFancyCommandRequest,\n MyFancyCommandResponse,\n MyFancyOwnFunctionalityBehavior,\n} from \"./cluster/MyFancyOwnFunctionality.js\";\n\n/**\n * The following code brings some convenience to the CLI script. It allows to set the log level and format via\n * command line parameters. It also initializes the BLE stack if the `--ble` parameter is present.\n * Some of these parameters can also be replaced by generically accepted parameters or even environment variables. See the comments in the relevant places for information.\n * When using this code as basis for your own device node implementation, you can remove this part or hard code it.\n */\n\nrequireMinNodeVersion(16);\n\n// To configure Logging use\n// * \"--log-level\" or environment variable \"MATTER_LOG_LEVEL\" or \"environment.vars.set('log.level', Level.DEBUG)\"\n// Allowed values are: Level.FATAL, Level.ERROR, Level.WARN, Level.NOTICE, Level.INFO, Level.DEBUG\n// * \"--log-format\" or environment variable \"MATTER_LOG_FORMAT\" or \"environment.vars.set('log.format', Format.PLAIN)\"\n// Allowed values are: Format.PLAIN, Format.HTML, Format.ANSI,\n\nconst environment = Environment.default;\n\n// Alternatively \"--ble-enable\" or environment variable \"BLE_ENABLED\"\n// Alternatively \"--ble-hciId\" or environment variable \"BLE_HCIID\"\nif (environment.vars.get(\"ble.enable\")) {\n // Initialize Ble\n Ble.get = singleton(\n () =>\n new BleNode({\n hciId: environment.vars.number(\"ble.hciId\"),\n }),\n );\n}\n\nfunction executeCommand(scriptParamName: string) {\n const script = environment.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\n/**\n * Collect all needed data\n *\n * This block collects all needed data from cli or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n\nconst logFile = environment.vars.string(\"logfile.filename\");\nif (logFile !== undefined) {\n Logger.addLogger(\"filelogger\", await createFileLogger(logFile), {\n defaultLogLevel: levelFromString(environment.vars.string(\"logfile.loglevel\")) ?? Level.DEBUG,\n });\n}\n\nconst storageService = environment.get(StorageService);\nconsole.log(`Storage location: ${storageService.location} (Directory)`);\nconsole.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n);\n\nconst deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\nif (await deviceStorage.has(\"isSocket\")) {\n console.log(\"Device type found in storage. --type parameter is ignored.\");\n}\nconst isSocket = await deviceStorage.get(\"isSocket\", environment.vars.string(\"type\") === \"socket\");\nconst deviceName = \"Matter test device\";\nconst vendorName = \"matter-node.js\";\nconst passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\nconst discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n// product name / id and vendor id should match what is in the device certificate\nconst vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\nconst productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\nconst productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\nconst port = environment.vars.number(\"port\") ?? 5540;\n\nconst uniqueId = environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\nawait deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\n});\n\n// Matter exposes functionality in groups called \"clusters\". For this example device we override the matter.js \"On/Off\"\n// cluster implementation to print status to the console.\nclass OnOffShellExecServer extends OnOffServer {\n // Intercept the \"on\" command to the Matter On/Off cluster to print a log message.\n override async on() {\n executeCommand(\"on\");\n await super.on();\n }\n\n // This is the functional inverse of on() above.\n //\n // For demonstration purposes we update state ourselves rather than deferring to matter.js's default \"off\" handler\n // via super.off().\n override async off() {\n executeCommand(\"off\");\n this.state.onOff = false;\n }\n\n // Use event handlers to log on/off state reactively, after it changes.\n override initialize() {\n this.events.onOff$Changed.on(value => {\n console.log(`Light is now ${value ? \"ON\" : \"OFF\"}`);\n });\n }\n}\n\nclass TestGeneralDiagnosticsServer extends RootRequirements.GeneralDiagnosticsServer {\n override initialize() {\n this.state.testEventTriggersEnabled = true; // set to true if you support test triggers ...\n super.initialize();\n }\n\n override testEventTrigger({ enableKey, eventTrigger }: GeneralDiagnostics.TestEventTriggerRequest) {\n console.log(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`);\n }\n}\n\nclass MyFancyOwnFunctionalityServer extends MyFancyOwnFunctionalityBehavior {\n /** We return the incoming value and store the length of the string in our attribute and send it out as event */\n override myFancyCommand(request: MyFancyCommandRequest): MyFancyCommandResponse {\n const { value } = request;\n this.state.myFancyValue = value.length;\n\n this.events.myFancyEvent.emit({ eventValue: value }, this.context);\n\n return { response: value };\n }\n\n override initialize() {\n this.state.myFancyValue = -1; // Always initialize with -1\n }\n}\n\n/**\n * Create Device instance and add needed Listener\n *\n * Create an instance of the matter device class you want to use.\n * This example uses the OnOffLightDevice or OnOffPluginUnitDevice depending on the value of the type parameter.\n * To execute the on/off scripts defined as parameters a listener for the onOff attribute is registered via the\n * device specific API.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled device internally\n * like identify that can be implemented with the logic when these commands are called.\n */\n\n// Devices are compositions of behaviors like OnOffServer above. To extend an existing device you use builder methods.\n//\n// In this case we are using with() to install our On/Off cluster behavior.\n// .with(\"Lighting\") not needed because we always have it in by default because we have default implementation\nconst OnOffDevice = isSocket\n ? vendorId === 0xfff4\n ? OnOffPlugInUnitDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer)\n : OnOffPlugInUnitDevice.with(OnOffShellExecServer)\n : vendorId === 0xfff4\n ? OnOffLightDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer)\n : OnOffLightDevice.with(OnOffShellExecServer);\n\n/**\n * Modify automatically added clusters of the Root endpoint if needed\n * In this example we change the networkCommissioning cluster into one for \"Wifi only\" devices when BLE is used\n * for commissioning, to demonstrate how to do this.\n * If you want to implement Ethernet only devices that get connected to the network via LAN/Ethernet cable,\n * then all this is not needed.\n * The same as shown here for Wi-Fi is also possible theoretical for Thread only or combined devices.\n */\n\n// We use the Basic Root Endpoint without a NetworkCommissioning cluster\nlet RootEndpoint = ServerNode.RootEndpoint.with(TestGeneralDiagnosticsServer);\n\nlet wifiOrThreadAdded = false;\nif (Ble.enabled) {\n // matter.js will create a Ethernet-only device by default when ut comes to Network Commissioning Features.\n // To offer e.g. a \"Wi-Fi only device\" (or any other combination) we need to override the Network Commissioning\n // cluster and implement all the need handling here. This is a \"static implementation\" for pure demonstration\n // purposes and just \"simulates\" the actions to be done. In a real world implementation this would be done by\n // the device implementor based on the relevant networking stack.\n // The NetworkCommissioningCluster and all logics are described in Matter Core Specifications section 11.8\n if (environment.vars.has(\"ble.wifi.fake\")) {\n RootEndpoint = RootEndpoint.with(DummyWifiNetworkCommissioningServer);\n wifiOrThreadAdded = true;\n } else if (environment.vars.has(\"ble.thread.fake\")) {\n RootEndpoint = RootEndpoint.with(DummyThreadNetworkCommissioningServer);\n wifiOrThreadAdded = true;\n }\n} else {\n RootEndpoint = RootEndpoint.with(\n NetworkCommissioningServer.with(NetworkCommissioning.Feature.EthernetNetworkInterface),\n );\n}\n\nconst networkId = new ByteArray(32);\n// Physical devices appear as \"nodes\" on a Matter network. As a device implementer you use a NodeServer to bring a\n// device online.\n//\n// Note there are a large number of options to NodeServer that we are allowing to take default values here. See\n// CompositeWindowCovering.ts for a more detailed example.\nconst server = await ServerNode.create(RootEndpoint, {\n id: uniqueId,\n network: {\n port,\n discoveryCapabilities: {\n onIpNetwork: !environment.vars.has(\"ble.enable\"),\n ble: environment.vars.has(\"ble.enable\"),\n },\n ble: environment.vars.has(\"ble.enable\"), // TODO remove when state init is fixed\n },\n commissioning: {\n passcode,\n discriminator,\n },\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(OnOffDevice.deviceType),\n },\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `node-matter-${uniqueId}`,\n uniqueId,\n },\n\n // @ts-expect-error ... TS do not see the types because both next clusters was added conditionally\n networkCommissioning: {\n maxNetworks: 1,\n interfaceEnabled: true,\n lastConnectErrorValue: 0,\n lastNetworkId: wifiOrThreadAdded ? null : networkId,\n lastNetworkingStatus: wifiOrThreadAdded ? null : NetworkCommissioning.NetworkCommissioningStatus.Success,\n networks: [{ networkId: networkId, connected: !wifiOrThreadAdded }],\n scanMaxTimeSeconds: wifiOrThreadAdded ? 3 : undefined,\n connectMaxTimeSeconds: wifiOrThreadAdded ? 3 : undefined,\n },\n myFancyFunctionality: {\n myFancyValue: 0,\n },\n});\n\n// Nodes are a composition of endpoints. Add a single endpoint to the node, our example light device.\nconst endpoint = new Endpoint(OnOffDevice, { id: \"onoff\" });\nawait server.add(endpoint);\n\n/**\n * This event is triggered when the device is initially commissioned successfully.\n * This means: It is added to the first fabric.\n */\nserver.lifecycle.commissioned.on(() => console.log(\"Server was initially commissioned successfully!\"));\n\n/** This event is triggered when all fabrics are removed from the device, usually it also does a factory reset then. */\nserver.lifecycle.decommissioned.on(() => console.log(\"Server was fully decommissioned successfully!\"));\n\n/** This event is triggered when the device went online. This means that it is discoverable in the network. */\nserver.lifecycle.online.on(() => console.log(\"Server is online\"));\n\n/** This event is triggered when the device went offline. it is not longer discoverable or connectable in the network. */\nserver.lifecycle.offline.on(() => console.log(\"Server is offline\"));\n\n/**\n * This event is triggered when a fabric is added, removed or updated on the device. Use this if more granular\n * information is needed.\n */\nserver.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {\n let action = \"\";\n switch (fabricAction) {\n case FabricAction.Added:\n action = \"added\";\n break;\n case FabricAction.Removed:\n action = \"removed\";\n break;\n case FabricAction.Updated:\n action = \"updated\";\n break;\n }\n console.log(`Commissioned Fabrics changed event (${action}) for ${fabricIndex} triggered`);\n console.log(server.state.commissioning.fabrics[fabricIndex]);\n});\n\n/**\n * This event is triggered when an operative new session was opened by a Controller.\n * It is not triggered for the initial commissioning process, just afterwards for real connections.\n */\nserver.events.sessions.opened.on(session => console.log(`Session opened`, session));\n\n/**\n * This event is triggered when an operative session is closed by a Controller or because the Device goes offline.\n */\nserver.events.sessions.closed.on(session => console.log(`Session closed`, session));\n\n/** This event is triggered when a subscription gets added or removed on an operative session. */\nserver.events.sessions.subscriptionsChanged.on(session => {\n console.log(`Session subscriptions changed`, session);\n console.log(`Status of all sessions`, server.state.sessions.sessions);\n});\n\n// React on a change of identificationTime to do Identify stuff for the own device\nendpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic, ideally blink a light every 0.5s ...`);\n});\n\nendpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic ...`);\n});\n\n// Our device is now built and we can bring the node online.\n//\n// Note that you may serve multiple nodes from a single process. We only have one, however, so we can use the run()\n// method of the node.\n\nlogEndpoint(EndpointServer.forEndpoint(server));\n\n/**\n * In order to start the node and announce it into the network we start the node. This method resolves when the Matter\n * node enters his online state. Alternatively, we could also use `await server.run()` which\n * resolves when the node goes offline again, but we want to execute code afterwards, so we use start() here\n */\nawait server.bringOnline();\n\nconsole.log(\"Initial Fabrics\", server.state.operationalCredentials.fabrics);\n\n/**\n * If the node is not commissioned already we display the QR code on console. The QR code is also logged\n */\nif (!server.lifecycle.isCommissioned) {\n const { qrPairingCode, manualPairingCode } = server.state.commissioning.pairingCodes;\n\n console.log(QrCode.get(qrPairingCode));\n console.log(`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`);\n console.log(`Manual pairing code: ${manualPairingCode}`);\n} else {\n console.log(\"Device is already commissioned. Waiting for controllers to connect ...\");\n\n /**\n * Sometimes reading or writing attributes is required. The following code shows how this works.\n * For read it is basically `endpoint.state.clustername.attributename`.\n * The set method allows to set one or multiple values via the structure of also clustername.attributename. When multiple values are set they are considered being one transaction which would be rolled back completely if one value fails to be set.\n */\n\n // Read onOff attribute from onOff cluster\n const onOffValue = endpoint.state.onOff.onOff;\n console.log(`current OnOff attribute: ${onOffValue}`);\n\n if (vendorId === 0xfff4) {\n // Set onOff attribute from OnOff cluster AND the myFancyValue of the MyFancyOwnFunctionality cluster together\n await endpoint.set({\n onOff: {\n onOff: !onOffValue,\n },\n // @ts-expect-error Needed because the Fancy cluster is added conditionally, so TS do not get that it's there.\n myFancyOwnFunctionality: {\n myFancyValue: 36,\n },\n });\n } else {\n // Set onOff attribute from OnOff cluster only\n await endpoint.set({\n onOff: {\n onOff: !onOffValue,\n },\n });\n }\n}\n\n/**\n * To correctly tear down the now we can use server[Symbol.asyncDispose]().\n */\nprocess.on(\"SIGINT\", () => {\n // Clean up on CTRL-C\n server\n .close()\n .then(() => process.exit(0))\n .catch(err => console.error(err));\n});\n"],
5
+ "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAyBA,OAAO;AAEP,SAAS,eAAe;AAExB,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AACpB,SAAS,4BAA4B;AACrC,SAAS,cAAc,gBAAgB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,UAAU,sBAAsB;AACzC,SAAS,wBAAwB;AACjC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,oBAAoB;AAC7B,SAAS,OAAO,QAAQ,uBAAuB;AAC/C,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,WAAW,iBAAiB;AACrC,SAAS,gBAAgB;AACzB,SAAS,6CAA6C;AACtD,SAAS,2CAA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,QAAQ,MAAM,GAAG,CAAC;AACxC,CAAC;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/IlluminatedRollerShade.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport {\n MovementDirection,\n MovementType,\n WindowCoveringServer,\n} from \"@project-chip/matter.js/behaviors/window-covering\";\nimport { OnOffLightDevice, OnOffLightRequirements } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { WindowCoveringDevice } from \"@project-chip/matter.js/devices/WindowCoveringDevice\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\n\n/**\n * This example demonstrates implementation of a \"composed\" device comprising multiple sub-devices\n *\n * Our example device, the Excelsior 1000 EZ-Nite\u2122, is a roller shade with an illuminated valance.\n */\n\nconst LiftingWindowCoveringServer = WindowCoveringServer.with(\"Lift\", \"AbsolutePosition\", \"PositionAwareLift\");\n\n/**\n * Implementation of the Matter WindowCovering cluster for the shade motor.\n */\nclass RollerShade extends LiftingWindowCoveringServer {\n override async handleMovement(\n type: MovementType,\n reversed: boolean,\n direction: MovementDirection,\n targetPercent100ths?: number,\n ) {\n console.log(\n \"Move window shade\",\n direction === MovementDirection.Open ? \"Open\" : \"Close\",\n targetPercent100ths !== undefined ? `${targetPercent100ths / 100}%` : \"\",\n );\n\n // Updates the shade position\n await super.handleMovement(type, reversed, direction, targetPercent100ths);\n }\n}\n\n/**\n * Implementation of the OnOff cluster for our valance light.\n */\nclass ValanceLight extends OnOffLightRequirements.OnOffServer {\n override initialize() {\n this.reactTo(this.events.onOff$Changed, this.#stateChanged);\n }\n\n #stateChanged(value: boolean) {\n console.log(`Valance is now ${value ? \"illuminated\" : \"dark\"}`);\n }\n}\n\n/**\n * Our Matter node.\n */\nconst node = new ServerNode({\n id: \"excelsior1000\",\n\n productDescription: {},\n\n commissioning: {\n passcode: 20202021,\n discriminator: 3840,\n },\n\n basicInformation: {\n vendorName: \"Acme Corporation\",\n productName: \"Excelsior 1000 EZ-Nite\u2122\",\n vendorId: 0xfff1,\n productId: 0x8000,\n serialNumber: \"1234-12345-123\",\n },\n\n parts: [\n {\n type: WindowCoveringDevice.with(RollerShade),\n id: \"shade\",\n },\n\n {\n type: OnOffLightDevice.with(ValanceLight),\n id: \"valance\",\n },\n ],\n});\n\nawait node.run();\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,OAAO;AAEP;AAAA,EACI;AAAA,EAEA;AAAA,OACG;AACP,SAAS,kBAAkB,8BAA8B;AACzD,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAQ3B,MAAM,8BAA8B,qBAAqB,KAAK,QAAQ,oBAAoB,mBAAmB;AAK7G,MAAM,oBAAoB,4BAA4B;AAAA,EAClD,MAAe,eACX,MACA,UACA,WACA,qBACF;AACE,YAAQ;AAAA,MACJ;AAAA,MACA,cAAc,kBAAkB,OAAO,SAAS;AAAA,MAChD,wBAAwB,SAAY,GAAG,sBAAsB,GAAG,MAAM;AAAA,IAC1E;AAGA,UAAM,MAAM,eAAe,MAAM,UAAU,WAAW,mBAAmB;AAAA,EAC7E;AACJ;AAKA,MAAM,qBAAqB,uBAAuB,YAAY;AAAA,EACjD,aAAa;AAClB,SAAK,QAAQ,KAAK,OAAO,eAAe,KAAK,aAAa;AAAA,EAC9D;AAAA,EAEA,cAAc,OAAgB;AAC1B,YAAQ,IAAI,kBAAkB,QAAQ,gBAAgB,MAAM,EAAE;AAAA,EAClE;AACJ;AAKA,MAAM,OAAO,IAAI,WAAW;AAAA,EACxB,IAAI;AAAA,EAEJ,oBAAoB,CAAC;AAAA,EAErB,eAAe;AAAA,IACX,UAAU;AAAA,IACV,eAAe;AAAA,EACnB;AAAA,EAEA,kBAAkB;AAAA,IACd,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,UAAU;AAAA,IACV,WAAW;AAAA,IACX,cAAc;AAAA,EAClB;AAAA,EAEA,OAAO;AAAA,IACH;AAAA,MACI,MAAM,qBAAqB,KAAK,WAAW;AAAA,MAC3C,IAAI;AAAA,IACR;AAAA,IAEA;AAAA,MACI,MAAM,iBAAiB,KAAK,YAAY;AAAA,MACxC,IAAI;AAAA,IACR;AAAA,EACJ;AACJ,CAAC;AAED,MAAM,KAAK,IAAI;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport {\n MovementDirection,\n MovementType,\n WindowCoveringServer,\n} from \"@project-chip/matter.js/behaviors/window-covering\";\nimport { OnOffLightDevice, OnOffLightRequirements } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { WindowCoveringDevice } from \"@project-chip/matter.js/devices/WindowCoveringDevice\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\n\n/**\n * This example demonstrates implementation of a \"composed\" device comprising multiple sub-devices\n *\n * Our example device, the Excelsior 1000 EZ-Nite\u2122, is a roller shade with an illuminated valance.\n */\n\nconst LiftingWindowCoveringServer = WindowCoveringServer.with(\"Lift\", \"AbsolutePosition\", \"PositionAwareLift\");\n\n/**\n * Implementation of the Matter WindowCovering cluster for the shade motor.\n */\nclass RollerShade extends LiftingWindowCoveringServer {\n override async handleMovement(\n type: MovementType,\n reversed: boolean,\n direction: MovementDirection,\n targetPercent100ths?: number,\n ) {\n console.log(\n \"Move window shade\",\n direction === MovementDirection.Open ? \"Open\" : \"Close\",\n targetPercent100ths !== undefined ? `${targetPercent100ths / 100}%` : \"\",\n );\n\n // Updates the shade position\n await super.handleMovement(type, reversed, direction, targetPercent100ths);\n }\n}\n\n/**\n * Implementation of the OnOff cluster for our valance light.\n */\nclass ValanceLight extends OnOffLightRequirements.OnOffServer {\n override initialize() {\n this.reactTo(this.events.onOff$Changed, this.#stateChanged);\n }\n\n #stateChanged(value: boolean) {\n console.log(`Valance is now ${value ? \"illuminated\" : \"dark\"}`);\n }\n}\n\n/**\n * Our Matter node.\n */\nconst node = new ServerNode({\n id: \"excelsior1000\",\n\n productDescription: {},\n\n commissioning: {\n passcode: 20202021,\n discriminator: 3840,\n },\n\n basicInformation: {\n vendorName: \"Acme Corporation\",\n productName: \"Excelsior 1000 EZ-Nite\u2122\",\n vendorId: 0xfff1,\n productId: 0x8000,\n serialNumber: \"1234-12345-123\",\n },\n\n parts: [\n {\n type: WindowCoveringDevice.with(RollerShade),\n id: \"shade\",\n },\n\n {\n type: OnOffLightDevice.with(ValanceLight),\n id: \"valance\",\n },\n ],\n});\n\nawait node.run();\n"],
5
+ "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAOA,OAAO;AAEP;AAAA,EACI;AAAA,EAEA;AAAA,OACG;AACP,SAAS,kBAAkB,8BAA8B;AACzD,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAQ3B,MAAM,8BAA8B,qBAAqB,KAAK,QAAQ,oBAAoB,mBAAmB;AAK7G,MAAM,oBAAoB,4BAA4B;AAAA,EAClD,MAAe,eACX,MACA,UACA,WACA,qBACF;AACE,YAAQ;AAAA,MACJ;AAAA,MACA,cAAc,kBAAkB,OAAO,SAAS;AAAA,MAChD,wBAAwB,SAAY,GAAG,sBAAsB,GAAG,MAAM;AAAA,IAC1E;AAGA,UAAM,MAAM,eAAe,MAAM,UAAU,WAAW,mBAAmB;AAAA,EAC7E;AACJ;AAKA,MAAM,qBAAqB,uBAAuB,YAAY;AAAA,EACjD,aAAa;AAClB,SAAK,QAAQ,KAAK,OAAO,eAAe,KAAK,aAAa;AAAA,EAC9D;AAAA,EAEA,cAAc,OAAgB;AAC1B,YAAQ,IAAI,kBAAkB,QAAQ,gBAAgB,MAAM,EAAE;AAAA,EAClE;AACJ;AAKA,MAAM,OAAO,IAAI,WAAW;AAAA,EACxB,IAAI;AAAA,EAEJ,oBAAoB,CAAC;AAAA,EAErB,eAAe;AAAA,IACX,UAAU;AAAA,IACV,eAAe;AAAA,EACnB;AAAA,EAEA,kBAAkB;AAAA,IACd,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,UAAU;AAAA,IACV,WAAW;AAAA,IACX,cAAc;AAAA,EAClB;AAAA,EAEA,OAAO;AAAA,IACH;AAAA,MACI,MAAM,qBAAqB,KAAK,WAAW;AAAA,MAC3C,IAAI;AAAA,IACR;AAAA,IAEA;AAAA,MACI,MAAM,iBAAiB,KAAK,YAAY;AAAA,MACxC,IAAI;AAAA,IACR;AAAA,EACJ;AACJ,CAAC;AAED,MAAM,KAAK,IAAI;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/LegacyStorageConverter.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport \"@project-chip/matter-node.js\";\nimport { StorageBackendDisk } from \"@project-chip/matter-node.js/storage\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { LocalStorage } from \"node-localstorage\";\n\nconst environment = Environment.default;\n\nconst legacyStoragePath = environment.vars.string(\"legacy.storage.path\");\nconst newStoragePath = environment.vars.string(\"storage.path\");\n\nif (!legacyStoragePath || !newStoragePath) {\n console.error(\"Usage: node LegacyStorageConverter.js --legacy-storage-path=<path> --storage-path=<path>\");\n process.exit(1);\n}\n\nconst legacyLocalStorage = new LocalStorage(legacyStoragePath);\n\nconst legacyNodes = new Array<string>();\nObject.keys(legacyLocalStorage).forEach(key => {\n const firstLevel = key.split(\".\")[0];\n if (!legacyNodes.includes(firstLevel)) {\n legacyNodes.push(firstLevel);\n }\n});\n\nconst storageService = environment.get(StorageService);\n\nconst legacyStorage = new StorageBackendDisk(legacyStoragePath);\nlegacyStorage.initialize();\n\nconst uniqueIds: Record<string, string> = {};\nif (legacyNodes.includes(\"Device\")) {\n console.log(\"Example Device found ...\");\n legacyNodes.splice(legacyNodes.indexOf(\"Device\"), 1);\n\n const newDeviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n for (const key of legacyStorage.keys([\"Device\"])) {\n console.log(\"Migrate Device.\", key);\n const value = legacyStorage.get([\"Device\"], key);\n await newDeviceStorage.set(key, value);\n if (key === \"uniqueid\") {\n uniqueIds[\"0\"] = String(value);\n await newDeviceStorage.set(key, String(value));\n } else if (key.startsWith(\"uniqueid\")) {\n const id = parseInt(key.substring(8));\n uniqueIds[id - 1] = String(value);\n await newDeviceStorage.set(key, String(value));\n }\n }\n}\n\nif (legacyNodes.includes(\"Controller\")) {\n console.log(\"Example Controller found ...\");\n legacyNodes.splice(legacyNodes.indexOf(\"Controller\"), 1);\n\n const newControllerStorage = (await storageService.open(\"controller\")).createContext(\"data\");\n\n for (const key of legacyStorage.keys([\"Controller\"])) {\n console.log(\"Migrate Controller.\", key);\n const value = legacyStorage.get([\"Controller\"], key);\n await newControllerStorage.set(key, value);\n if (key === \"uniqueid\") {\n uniqueIds[\"0\"] = String(value);\n await newControllerStorage.set(key, String(value));\n }\n }\n}\n\nconsole.log(uniqueIds);\n\nif (!Object.keys(uniqueIds).length) {\n console.error(\"No uniqueId(s) found in legacy storage. Can not convert the node storage.\");\n process.exit(1);\n}\n\nfor (const nodeId of legacyNodes) {\n if (!uniqueIds[nodeId]) {\n const rootCertId = legacyStorage.get([\"0\", \"RootCertificateManager\"], \"rootCertId\");\n\n if (nodeId !== \"0\" || rootCertId === undefined) {\n console.error(`No uniqueId found for node ${nodeId}. Can not convert the node storage.`);\n continue;\n }\n\n // Migrate the controller storage\n const newControllerStorage = (await storageService.open(\"controller\")).createContext(\"data\");\n const uniqueId = Time.nowMs().toString();\n await newControllerStorage.set(\"uniqueid\", uniqueId);\n\n const newNodeStorage = await storageService.open(uniqueId);\n\n const credentialsStorage = newNodeStorage.createContext(\"credentials\");\n await credentialsStorage.set(\"rootCertId\", rootCertId);\n await credentialsStorage.set(\n \"nextCertificateId\",\n legacyStorage.get([\"0\", \"RootCertificateManager\"], \"nextCertificateId\"),\n );\n await credentialsStorage.set(\n \"rootCertBytes\",\n legacyStorage.get([\"0\", \"RootCertificateManager\"], \"rootCertBytes\"),\n );\n await credentialsStorage.set(\n \"rootKeyIdentifier\",\n legacyStorage.get([\"0\", \"RootCertificateManager\"], \"rootKeyIdentifier\"),\n );\n await credentialsStorage.set(\"rootKeyPair\", legacyStorage.get([\"0\", \"RootCertificateManager\"], \"rootKeyPair\"));\n await credentialsStorage.set(\"fabric\", legacyStorage.get([\"0\", \"MatterController\"], \"fabric\"));\n\n const sessionsStorage = newNodeStorage.createContext(\"sessions\");\n await sessionsStorage.set(\n \"resumptionRecords\",\n legacyStorage.get([nodeId, \"SessionManager\"], \"resumptionRecords\"),\n );\n\n const nodesStorage = newNodeStorage.createContext(\"nodes\");\n await nodesStorage.set(\n \"resumptionRecords\",\n legacyStorage.get([nodeId, \"MatterController\"], \"commissionedNodes\"),\n );\n\n console.log(`Controller Node ${nodeId} with new unique id ${uniqueId} migrated successfully.`);\n } else {\n // Migrate the device storage\n const newNodeStorage = await storageService.open(uniqueIds[nodeId]);\n\n const nextEndpointNumber = legacyStorage.get<number>([nodeId, \"EndpointStructure\"], \"nextEndpointId\");\n if (nextEndpointNumber !== undefined && nextEndpointNumber > 2) {\n console.log(\n \"It seems you used a bridged or composed example before, please make sure to use all details (type, ids,...) in the parameters when starting the new example. When using a bridge and you had changed devices after pairing it could happen that the new example introduces new devices to the controller. If you are unsure unpair the old example and start fresh.\",\n );\n }\n\n const eventsStorage = newNodeStorage.createContext(\"events\");\n await eventsStorage.set(\"lastEventNumber\", legacyStorage.get([nodeId, \"EventHandler\"], \"lastEventNumber\"));\n\n const fabricsStorage = newNodeStorage.createContext(\"fabrics\");\n await fabricsStorage.set(\"fabrics\", legacyStorage.get([nodeId, \"FabricManager\"], \"fabrics\"));\n await fabricsStorage.set(\"nextFabricIndex\", legacyStorage.get([nodeId, \"FabricManager\"], \"nextFabricIndex\"));\n\n const sessionsStorage = newNodeStorage.createContext(\"sessions\");\n await sessionsStorage.set(\n \"resumptionRecords\",\n legacyStorage.get([nodeId, \"SessionManager\"], \"resumptionRecords\"),\n );\n\n console.log(`Device Node ${nodeId} with unique id ${uniqueIds[nodeId]} migrated successfully.`);\n }\n}\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,OAAO;AACP,SAAS,0BAA0B;AACnC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,YAAY;AACrB,SAAS,oBAAoB;AAE7B,MAAM,cAAc,YAAY;AAEhC,MAAM,oBAAoB,YAAY,KAAK,OAAO,qBAAqB;AACvE,MAAM,iBAAiB,YAAY,KAAK,OAAO,cAAc;AAE7D,IAAI,CAAC,qBAAqB,CAAC,gBAAgB;AACvC,UAAQ,MAAM,0FAA0F;AACxG,UAAQ,KAAK,CAAC;AAClB;AAEA,MAAM,qBAAqB,IAAI,aAAa,iBAAiB;AAE7D,MAAM,cAAc,IAAI,MAAc;AACtC,OAAO,KAAK,kBAAkB,EAAE,QAAQ,SAAO;AAC3C,QAAM,aAAa,IAAI,MAAM,GAAG,EAAE,CAAC;AACnC,MAAI,CAAC,YAAY,SAAS,UAAU,GAAG;AACnC,gBAAY,KAAK,UAAU;AAAA,EAC/B;AACJ,CAAC;AAED,MAAM,iBAAiB,YAAY,IAAI,cAAc;AAErD,MAAM,gBAAgB,IAAI,mBAAmB,iBAAiB;AAC9D,cAAc,WAAW;AAEzB,MAAM,YAAoC,C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Ae,eAAe,cAAc,OAAO;AACzD,UAAM,aAAa;AAAA,MACf;AAAA,MACA,cAAc,IAAI,CAAC,QAAQ,kBAAkB,GAAG,mBAAmB;AAAA,IACvE;AAEA,YAAQ,IAAI,mBAAmB,MAAM,uBAAuB,QAAQ,yBAAyB;AAAA,EACjG,OAAO;AAEH,UAAM,iBAAiB,MAAM,eAAe,KAAK,UAAU,MAAM,CAAC;AAElE,UAAM,qBAAqB,cAAc,IAAY,CAAC,QAAQ,mBAAmB,GAAG,gBAAgB;AACpG,QAAI,uBAAuB,UAAa,qBAAqB,GAAG;AAC5D,cAAQ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAEA,UAAM,gBAAgB,eAAe,cAAc,QAAQ;AAC3D,UAAM,cAAc,IAAI,mBAAmB,cAAc,IAAI,CAAC,QAAQ,cAAc,GAAG,iBAAiB,CAAC;AAEzG,UAAM,iBAAiB,eAAe,cAAc,SAAS;AAC7D,UAAM,eAAe,IAAI,WAAW,cAAc,IAAI,CAAC,QAAQ,eAAe,GAAG,SAAS,CAAC;AAC3F,UAAM,eAAe,IAAI,mBAAmB,cAAc,IAAI,CAAC,QAAQ,eAAe,GAAG,iBAAiB,CAAC;AAE3G,UAAM,kBAAkB,eAAe,cAAc,UAAU;AAC/D,UAAM,gBAAgB;AAAA,MAClB;AAAA,MACA,cAAc,IAAI,CAAC,QAAQ,gBAAgB,GAAG,mBAAmB;AAAA,IACrE;AAEA,YAAQ,IAAI,eAAe,MAAM,mBAAmB,UAAU,MAAM,CAAC,yBAAyB;AAAA,EAClG;AACJ;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport \"@project-chip/matter-node.js\";\nimport { StorageBackendDisk } from \"@project-chip/matter-node.js/storage\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { LocalStorage } from \"node-localstorage\";\n\nconst environment = Environment.default;\n\nconst legacyStoragePath = environment.vars.string(\"legacy.storage.path\");\nconst newStoragePath = environment.vars.string(\"storage.path\");\n\nif (!legacyStoragePath || !newStoragePath) {\n console.error(\"Usage: node LegacyStorageConverter.js --legacy-storage-path=<path> --storage-path=<path>\");\n process.exit(1);\n}\n\nconst legacyLocalStorage = new LocalStorage(legacyStoragePath);\n\nconst legacyNodes = new Array<string>();\nObject.keys(legacyLocalStorage).forEach(key => {\n const firstLevel = key.split(\".\")[0];\n if (!legacyNodes.includes(firstLevel)) {\n legacyNodes.push(firstLevel);\n }\n});\n\nconst storageService = environment.get(StorageService);\n\nconst legacyStorage = new StorageBackendDisk(legacyStoragePath);\nlegacyStorage.initialize();\n\nconst uniqueIds: Record<string, string> = {};\nif (legacyNodes.includes(\"Device\")) {\n console.log(\"Example Device found ...\");\n legacyNodes.splice(legacyNodes.indexOf(\"Device\"), 1);\n\n const newDeviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n for (const key of legacyStorage.keys([\"Device\"])) {\n console.log(\"Migrate Device.\", key);\n const value = legacyStorage.get([\"Device\"], key);\n await newDeviceStorage.set(key, value);\n if (key === \"uniqueid\") {\n uniqueIds[\"0\"] = String(value);\n await newDeviceStorage.set(key, String(value));\n } else if (key.startsWith(\"uniqueid\")) {\n const id = parseInt(key.substring(8));\n uniqueIds[id - 1] = String(value);\n await newDeviceStorage.set(key, String(value));\n }\n }\n}\n\nif (legacyNodes.includes(\"Controller\")) {\n console.log(\"Example Controller found ...\");\n legacyNodes.splice(legacyNodes.indexOf(\"Controller\"), 1);\n\n const newControllerStorage = (await storageService.open(\"controller\")).createContext(\"data\");\n\n for (const key of legacyStorage.keys([\"Controller\"])) {\n console.log(\"Migrate Controller.\", key);\n const value = legacyStorage.get([\"Controller\"], key);\n await newControllerStorage.set(key, value);\n if (key === \"uniqueid\") {\n uniqueIds[\"0\"] = String(value);\n await newControllerStorage.set(key, String(value));\n }\n }\n}\n\nconsole.log(uniqueIds);\n\nif (!Object.keys(uniqueIds).length) {\n console.error(\"No uniqueId(s) found in legacy storage. Can not convert the node storage.\");\n process.exit(1);\n}\n\nfor (const nodeId of legacyNodes) {\n if (!uniqueIds[nodeId]) {\n const rootCertId = legacyStorage.get([\"0\", \"RootCertificateManager\"], \"rootCertId\");\n\n if (nodeId !== \"0\" || rootCertId === undefined) {\n console.error(`No uniqueId found for node ${nodeId}. Can not convert the node storage.`);\n continue;\n }\n\n // Migrate the controller storage\n const newControllerStorage = (await storageService.open(\"controller\")).createContext(\"data\");\n const uniqueId = Time.nowMs().toString();\n await newControllerStorage.set(\"uniqueid\", uniqueId);\n\n const newNodeStorage = await storageService.open(uniqueId);\n\n const credentialsStorage = newNodeStorage.createContext(\"credentials\");\n await credentialsStorage.set(\"rootCertId\", rootCertId);\n await credentialsStorage.set(\n \"nextCertificateId\",\n legacyStorage.get([\"0\", \"RootCertificateManager\"], \"nextCertificateId\"),\n );\n await credentialsStorage.set(\n \"rootCertBytes\",\n legacyStorage.get([\"0\", \"RootCertificateManager\"], \"rootCertBytes\"),\n );\n await credentialsStorage.set(\n \"rootKeyIdentifier\",\n legacyStorage.get([\"0\", \"RootCertificateManager\"], \"rootKeyIdentifier\"),\n );\n await credentialsStorage.set(\"rootKeyPair\", legacyStorage.get([\"0\", \"RootCertificateManager\"], \"rootKeyPair\"));\n await credentialsStorage.set(\"fabric\", legacyStorage.get([\"0\", \"MatterController\"], \"fabric\"));\n\n const sessionsStorage = newNodeStorage.createContext(\"sessions\");\n await sessionsStorage.set(\n \"resumptionRecords\",\n legacyStorage.get([nodeId, \"SessionManager\"], \"resumptionRecords\"),\n );\n\n const nodesStorage = newNodeStorage.createContext(\"nodes\");\n await nodesStorage.set(\n \"resumptionRecords\",\n legacyStorage.get([nodeId, \"MatterController\"], \"commissionedNodes\"),\n );\n\n console.log(`Controller Node ${nodeId} with new unique id ${uniqueId} migrated successfully.`);\n } else {\n // Migrate the device storage\n const newNodeStorage = await storageService.open(uniqueIds[nodeId]);\n\n const nextEndpointNumber = legacyStorage.get<number>([nodeId, \"EndpointStructure\"], \"nextEndpointId\");\n if (nextEndpointNumber !== undefined && nextEndpointNumber > 2) {\n console.log(\n \"It seems you used a bridged or composed example before, please make sure to use all details (type, ids,...) in the parameters when starting the new example. When using a bridge and you had changed devices after pairing it could happen that the new example introduces new devices to the controller. If you are unsure unpair the old example and start fresh.\",\n );\n }\n\n const eventsStorage = newNodeStorage.createContext(\"events\");\n await eventsStorage.set(\"lastEventNumber\", legacyStorage.get([nodeId, \"EventHandler\"], \"lastEventNumber\"));\n\n const fabricsStorage = newNodeStorage.createContext(\"fabrics\");\n await fabricsStorage.set(\"fabrics\", legacyStorage.get([nodeId, \"FabricManager\"], \"fabrics\"));\n await fabricsStorage.set(\"nextFabricIndex\", legacyStorage.get([nodeId, \"FabricManager\"], \"nextFabricIndex\"));\n\n const sessionsStorage = newNodeStorage.createContext(\"sessions\");\n await sessionsStorage.set(\n \"resumptionRecords\",\n legacyStorage.get([nodeId, \"SessionManager\"], \"resumptionRecords\"),\n );\n\n console.log(`Device Node ${nodeId} with unique id ${uniqueIds[nodeId]} migrated successfully.`);\n }\n}\n"],
5
+ "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAMA,OAAO;AACP,SAAS,0BAA0B;AACnC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,YAAY;AACrB,SAAS,oBAAoB;AAE7B,MAAM,cAAc,YAAY;AAEhC,MAAM,oBAAoB,YAAY,KAAK,OAAO,qBAAqB;AACvE,MAAM,iBAAiB,YAAY,KAAK,OAAO,cAAc;AAE7D,IAAI,CAAC,qBAAqB,CAAC,gBAAgB;AACvC,UAAQ,MAAM,0FAA0F;AACxG,UAAQ,KAAK,CAAC;AAClB;AAEA,MAAM,qBAAqB,IAAI,aAAa,iBAAiB;AAE7D,MAAM,cAAc,IAAI,MAAc;AACtC,OAAO,KAAK,kBAAkB,EAAE,QAAQ,SAAO;AAC3C,QAAM,aAAa,IAA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
  }
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/LightDevice.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// This demonstrates bringing a \"light\" device online with matter.js.\n\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { OnOffLightDevice, OnOffLightRequirements } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\n\n// Matter exposes functionality in groups called \"clusters\". For this example device we override the matter.js \"On/Off\"\n// cluster implementation to print status to the console.\nclass ReportingOnOffServer extends OnOffLightRequirements.OnOffServer {\n // Intercept the \"on\" command to the Matter On/Off cluster to print a log message.\n override async on() {\n console.log(\"Turning light ON\");\n await super.on();\n }\n\n // This is the functional inverse of on() above.\n //\n // For demonstration purposes we update state ourselves rather than deferring to matter.js's default \"off\" handler\n // via super.off().\n override off() {\n console.log(\"Turning light OFF\");\n this.state.onOff = false;\n }\n\n // Use event handlers to log on/off state reactively, after it changes.\n override initialize() {\n this.events.onOff$Changed.on(value => {\n console.log(`Light is now ${value ? \"ON\" : \"OFF\"}`);\n });\n }\n}\n\n// Devices are compositions of behaviors like OnOffServer above. To extend an existing device you use builder methods.\n//\n// In this case we are using with() to install our On/Off cluster behavior.\nconst ExampleLight = OnOffLightDevice.with(ReportingOnOffServer);\n\n// Physical devices appear as \"nodes\" on a Matter network. As a device implementer you use a NodeServer to bring a\n// device online.\n//\n// Note there are a large number of options to NodeServer that we are allowing to take default values here. See\n// IlluminatedRollerShade.ts for a more detailed example.\nconst node = await ServerNode.create();\n\n// Nodes are a composition of endpoints. Add a single endpoint to the node, our example light device.\nawait node.add(ExampleLight);\n\n// Our device is now built and we can bring the node online.\n//\n// Note that you may serve multiple nodes from a single process. We only have one, however, so we can use the run()\n// method of the node.\nawait node.run();\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AASA,OAAO;AAEP,SAAS,kBAAkB,8BAA8B;AACzD,SAAS,kBAAkB;AAI3B,MAAM,6BAA6B,uBAAuB,YAAY;AAAA;AAAA,EAElE,MAAe,KAAK;AAChB,YAAQ,IAAI,kBAAkB;AAC9B,UAAM,MAAM,GAAG;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,MAAM;AACX,YAAQ,IAAI,mBAAmB;AAC/B,SAAK,MAAM,QAAQ;AAAA,EACvB;AAAA;AAAA,EAGS,aAAa;AAClB,SAAK,OAAO,cAAc,GAAG,WAAS;AAClC,cAAQ,IAAI,gBAAgB,QAAQ,OAAO,KAAK,EAAE;AAAA,IACtD,CAAC;AAAA,EACL;AACJ;AAKA,MAAM,eAAe,iBAAiB,KAAK,oBAAoB;AAO/D,MAAM,OAAO,MAAM,WAAW,OAAO;AAGrC,MAAM,KAAK,IAAI,YAAY;AAM3B,MAAM,KAAK,IAAI;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// This demonstrates bringing a \"light\" device online with matter.js.\n\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { OnOffLightDevice, OnOffLightRequirements } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\n\n// Matter exposes functionality in groups called \"clusters\". For this example device we override the matter.js \"On/Off\"\n// cluster implementation to print status to the console.\nclass ReportingOnOffServer extends OnOffLightRequirements.OnOffServer {\n // Intercept the \"on\" command to the Matter On/Off cluster to print a log message.\n override async on() {\n console.log(\"Turning light ON\");\n await super.on();\n }\n\n // This is the functional inverse of on() above.\n //\n // For demonstration purposes we update state ourselves rather than deferring to matter.js's default \"off\" handler\n // via super.off().\n override off() {\n console.log(\"Turning light OFF\");\n this.state.onOff = false;\n }\n\n // Use event handlers to log on/off state reactively, after it changes.\n override initialize() {\n this.events.onOff$Changed.on(value => {\n console.log(`Light is now ${value ? \"ON\" : \"OFF\"}`);\n });\n }\n}\n\n// Devices are compositions of behaviors like OnOffServer above. To extend an existing device you use builder methods.\n//\n// In this case we are using with() to install our On/Off cluster behavior.\nconst ExampleLight = OnOffLightDevice.with(ReportingOnOffServer);\n\n// Physical devices appear as \"nodes\" on a Matter network. As a device implementer you use a NodeServer to bring a\n// device online.\n//\n// Note there are a large number of options to NodeServer that we are allowing to take default values here. See\n// IlluminatedRollerShade.ts for a more detailed example.\nconst node = await ServerNode.create();\n\n// Nodes are a composition of endpoints. Add a single endpoint to the node, our example light device.\nawait node.add(ExampleLight);\n\n// Our device is now built and we can bring the node online.\n//\n// Note that you may serve multiple nodes from a single process. We only have one, however, so we can use the run()\n// method of the node.\nawait node.run();\n"],
5
+ "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AASA,OAAO;AAEP,SAAS,kBAAkB,8BAA8B;AACzD,SAAS,kBAAkB;AAI3B,MAAM,6BAA6B,uBAAuB,YAAY;AAAA;AAAA,EAElE,MAAe,KAAK;AAChB,YAAQ,IAAI,kBAAkB;AAC9B,UAAM,MAAM,GAAG;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,MAAM;AACX,YAAQ,IAAI,mBAAmB;AAC/B,SAAK,MAAM,QAAQ;AAAA,EACvB;AAAA;AAAA,EAGS,aAAa;AAClB,SAAK,OAAO,cAAc,GAAG,WAAS;AAClC,cAAQ,IAAI,gBAAgB,QAAQ,OAAO,KAAK,EAAE;AAAA,IACtD,CAAC;AAAA,EACL;AACJ;AAKA,MAAM,eAAe,iBAAiB,KAAK,oBAAoB;AAO/D,MAAM,OAAO,MAAM,WAAW,OAAO;AAGrC,MAAM,KAAK,IAAI,YAAY;AAM3B,MAAM,KAAK,IAAI;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/MultiDeviceNode.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a new device node that is composed of multiple devices.\n * It creates multiple endpoints on the server. For information on how to add a composed device to a bridge please\n * refer to the bridge example!\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\nconst devices = await getConfiguration();\nfor (let idx = 1; idx < devices.length; idx++) {\n const {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n } = devices[idx];\n const i = idx + 1;\n\n /**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\n const server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(isSocket ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType),\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n });\n\n console.log(\n `Added device ${i} on port ${port} and unique id ${uniqueId}: Passcode: ${passcode}, Discriminator: ${discriminator}`,\n );\n\n const endpoint = new Endpoint(isSocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: \"onoff\" });\n await server.add(endpoint);\n\n /**\n * Register state change handlers of the node for identify and onoff states to react to the commands.\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic for device ${i}, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic for device ${i}...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on${i}` : `off${i}`);\n console.log(`OnOff ${i} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n\n /**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\n logEndpoint(EndpointServer.forEndpoint(server));\n\n console.log(\"----------------------------\");\n console.log(`QR Code for Device ${i} on port ${port}:`);\n console.log(\"----------------------------\");\n\n /**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\n await server.bringOnline();\n}\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/**\n * Defines a shell command from an environment variable and execute it and log the response\n */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n let defaultPasscode = 20202021;\n let defaultDiscriminator = 3840;\n let defaultPort = 5550;\n\n const devices = [];\n const numDevices = environment.vars.number(\"num\") ?? 2;\n for (let i = 1; i <= numDevices; i++) {\n const isSocket = await deviceStorage.get(`isSocket${i}`, environment.vars.string(`type${i}`) === \"socket\");\n if (await deviceStorage.has(`isSocket${i}`)) {\n console.log(`Device type ${isSocket ? \"socket\" : \"light\"} found in storage. --type parameter is ignored.`);\n }\n const deviceName = `Matter ${environment.vars.string(`type${i}`) ?? \"light\"} device ${i}`;\n const vendorName = \"matter-node.js\";\n const passcode =\n environment.vars.number(`passcode${i}`) ?? (await deviceStorage.get(`passcode${i}`, defaultPasscode++));\n const discriminator =\n environment.vars.number(`discriminator${i}`) ??\n (await deviceStorage.get(`discriminator${i}`, defaultDiscriminator++));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(`vendorid${i}`) ?? (await deviceStorage.get(`vendorid${i}`, 0xfff1));\n const productName = `node-matter OnOff-Device ${i}`;\n const productId =\n environment.vars.number(`productid${i}`) ?? (await deviceStorage.get(`productid${i}`, 0x8000));\n\n const port = environment.vars.number(`port${i}`) ?? defaultPort++;\n\n const uniqueId =\n environment.vars.string(`uniqueid${i}`) ??\n (await deviceStorage.get(`uniqueid${i}`, `${i}-${Time.nowMs()}`));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set(`passcode${i}`, passcode);\n await deviceStorage.set(`discriminator${i}`, discriminator);\n await deviceStorage.set(`vendorid${i}`, vendorId);\n await deviceStorage.set(`productid${i}`, productId);\n await deviceStorage.set(`isSocket${i}`, isSocket);\n await deviceStorage.set(`uniqueid${i}`, uniqueId);\n\n devices.push({\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n });\n }\n\n return devices;\n}\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,OAAO;AAEP,SAAS,6BAA6B;AACtC,SAAS,cAAc,gBAAgB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,UAAU,sBAAsB;AACzC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAEzB,sBAAsB,EAAE;AAExB,MAAM,UAAU,MAAM,iBAAiB;AACvC,SAAS,MAAM,GAAG,MAAM,QAAQ,QAAQ,OAAO;AAC3C,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI,QAAQ,GAAG;AACf,QAAM,IAAI,MAAM;AAKhB,QAAM,SAAS,MAAM,WAAW,OAAO;AAAA;AAAA,IAEnC,IAAI;AAAA;AAAA;AAAA,IAIJ,SAAS;AAAA,MACL;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,eAAe;AAAA,MACX;AAAA,MACA;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,oBAAoB;AAAA,MAChB,MAAM;AAAA,MACN,YAAY,aAAa,WAAW,sBAAsB,aAAa,iBAAiB,UAAU;AAAA,IACtG;AAAA;AAAA;AAAA,IAIA,kBAAkB;AAAA,MACd;AAAA,MACA,UAAU,S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AW,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,EAAE;AAGnE,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAChD,UAAM,cAAc,IAAI,gBAAgB,CAAC,IAAI,aAAa;AAC1D,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAChD,UAAM,cAAc,IAAI,YAAY,CAAC,IAAI,SAAS;AAClD,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAChD,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAEhD,IAAAA,SAAQ,KAAK;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAOA;AACX;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a new device node that is composed of multiple devices.\n * It creates multiple endpoints on the server. For information on how to add a composed device to a bridge please\n * refer to the bridge example!\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { OnOffLightDevice } from \"@project-chip/matter.js/devices/OnOffLightDevice\";\nimport { OnOffPlugInUnitDevice } from \"@project-chip/matter.js/devices/OnOffPlugInUnitDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\nconst devices = await getConfiguration();\nfor (let idx = 1; idx < devices.length; idx++) {\n const {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n } = devices[idx];\n const i = idx + 1;\n\n /**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\n const server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(isSocket ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType),\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n });\n\n console.log(\n `Added device ${i} on port ${port} and unique id ${uniqueId}: Passcode: ${passcode}, Discriminator: ${discriminator}`,\n );\n\n const endpoint = new Endpoint(isSocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: \"onoff\" });\n await server.add(endpoint);\n\n /**\n * Register state change handlers of the node for identify and onoff states to react to the commands.\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic for device ${i}, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic for device ${i}...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on${i}` : `off${i}`);\n console.log(`OnOff ${i} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n\n /**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\n logEndpoint(EndpointServer.forEndpoint(server));\n\n console.log(\"----------------------------\");\n console.log(`QR Code for Device ${i} on port ${port}:`);\n console.log(\"----------------------------\");\n\n /**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\n await server.bringOnline();\n}\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/**\n * Defines a shell command from an environment variable and execute it and log the response\n */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n let defaultPasscode = 20202021;\n let defaultDiscriminator = 3840;\n let defaultPort = 5550;\n\n const devices = [];\n const numDevices = environment.vars.number(\"num\") ?? 2;\n for (let i = 1; i <= numDevices; i++) {\n const isSocket = await deviceStorage.get(`isSocket${i}`, environment.vars.string(`type${i}`) === \"socket\");\n if (await deviceStorage.has(`isSocket${i}`)) {\n console.log(`Device type ${isSocket ? \"socket\" : \"light\"} found in storage. --type parameter is ignored.`);\n }\n const deviceName = `Matter ${environment.vars.string(`type${i}`) ?? \"light\"} device ${i}`;\n const vendorName = \"matter-node.js\";\n const passcode =\n environment.vars.number(`passcode${i}`) ?? (await deviceStorage.get(`passcode${i}`, defaultPasscode++));\n const discriminator =\n environment.vars.number(`discriminator${i}`) ??\n (await deviceStorage.get(`discriminator${i}`, defaultDiscriminator++));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(`vendorid${i}`) ?? (await deviceStorage.get(`vendorid${i}`, 0xfff1));\n const productName = `node-matter OnOff-Device ${i}`;\n const productId =\n environment.vars.number(`productid${i}`) ?? (await deviceStorage.get(`productid${i}`, 0x8000));\n\n const port = environment.vars.number(`port${i}`) ?? defaultPort++;\n\n const uniqueId =\n environment.vars.string(`uniqueid${i}`) ??\n (await deviceStorage.get(`uniqueid${i}`, `${i}-${Time.nowMs()}`));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set(`passcode${i}`, passcode);\n await deviceStorage.set(`discriminator${i}`, discriminator);\n await deviceStorage.set(`vendorid${i}`, vendorId);\n await deviceStorage.set(`productid${i}`, productId);\n await deviceStorage.set(`isSocket${i}`, isSocket);\n await deviceStorage.set(`uniqueid${i}`, uniqueId);\n\n devices.push({\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n });\n }\n\n return devices;\n}\n"],
5
+ "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAiBA,OAAO;AAEP,SAAS,6BAA6B;AACtC,SAAS,cAAc,gBAAgB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,UAAU,sBAAsB;AACzC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAEzB,sBAAsB,EAAE;AAExB,MAAM,UAAU,MAAM,iBAAiB;AACvC,SAAS,MAAM,GAAG,MAAM,QAAQ,QAAQ,OAAO;AAC3C,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI,QAAQ,GAAG;AACf,QAAM,IAAI,MAAM;AAKhB,QAAM,SAA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O,WAAW,CAAC,EAAE,KAAM,MAAM,cAAc,IAAI,WAAW,CAAC,IAAI,KAAM;AAC3G,UAAM,cAAc,4BAA4B,CAAC;AACjD,UAAM,YACF,YAAY,KAAK,OAAO,YAAY,CAAC,EAAE,KAAM,MAAM,cAAc,IAAI,YAAY,CAAC,IAAI,KAAM;AAEhG,UAAM,OAAO,YAAY,KAAK,OAAO,OAAO,CAAC,EAAE,KAAK;AAEpD,UAAM,WACF,YAAY,KAAK,OAAO,WAAW,CAAC,EAAE,KACrC,MAAM,cAAc,IAAI,WAAW,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,EAAE;AAGnE,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAChD,UAAM,cAAc,IAAI,gBAAgB,CAAC,IAAI,aAAa;AAC1D,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAChD,UAAM,cAAc,IAAI,YAAY,CAAC,IAAI,SAAS;AAClD,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAChD,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAEhD,IAAAA,SAAQ,KAAK;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAOA;AACX;",
6
6
  "names": ["devices"]
7
7
  }
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/SensorDeviceNode.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a simple Sensor Matter device as temperature or humidity device.\n * It can be used as CLI script and starting point for your own device node implementation.\n * This example is CJS conform and do not use top level await's.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { HumiditySensorDevice } from \"@project-chip/matter.js/devices/HumiditySensorDevice\";\nimport { TemperatureSensorDevice } from \"@project-chip/matter.js/devices/TemperatureSensorDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\nasync function main() {\n /** Initialize configuration values */\n const {\n isTemperature,\n interval,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n } = await getConfiguration();\n\n /**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\n const server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(\n isTemperature ? TemperatureSensorDevice.deviceType : HumiditySensorDevice.deviceType,\n ),\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n });\n\n /**\n * Matter Nodes are a composition of endpoints. Create and add a single endpoint to the node. This example uses the\n * OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type parameter. It also assigns this Part a\n * unique ID to store the endpoint number for it in the storage to restore the device on restart.\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n let endpoint: Endpoint;\n if (isTemperature) {\n endpoint = new Endpoint(TemperatureSensorDevice, {\n id: \"tempsensor\",\n temperatureMeasurement: {\n // Use this to initialize the measuredValue with the most uptodate value.\n // If you do not know the value and also can not request it, best use \"null\" (if allowed by the cluster).\n measuredValue: getIntValueFromCommandOrRandom(\"value\"),\n },\n });\n } else {\n endpoint = new Endpoint(HumiditySensorDevice, {\n id: \"humsensor\",\n relativeHumidityMeasurement: {\n // Use this to initialize the measuredValue with the most uptodate value.\n // If you do not know the value and also can not request it, best use \"null\" (if allowed by the cluster).\n measuredValue: getIntValueFromCommandOrRandom(\"value\", false),\n },\n });\n }\n\n await server.add(endpoint);\n\n /**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\n logEndpoint(EndpointServer.forEndpoint(server));\n\n const updateInterval = setInterval(() => {\n let setter: Promise<void>;\n if (isTemperature) {\n setter = endpoint.set({\n temperatureMeasurement: {\n measuredValue: getIntValueFromCommandOrRandom(\"value\"),\n },\n });\n } else {\n setter = endpoint.set({\n relativeHumidityMeasurement: {\n measuredValue: getIntValueFromCommandOrRandom(\"value\", false),\n },\n });\n }\n setter.catch(error => console.error(\"Error updating measured value:\", error));\n }, interval * 1000);\n\n // Cleanup our update interval when node goes offline\n server.lifecycle.offline.on(() => clearTimeout(updateInterval));\n\n /**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\n await server.run();\n}\n\nmain().catch(error => console.error(error));\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/** Defined a shell command from an environment variable and execute it and log the response. */\n\nfunction getIntValueFromCommandOrRandom(scriptParamName: string, allowNegativeValues = true) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) {\n if (!allowNegativeValues) return Math.round(Math.random() * 100);\n return (Math.round(Math.random() * 100) - 50) * 100;\n }\n let result = execSync(script).toString().trim();\n if ((result.startsWith(\"'\") && result.endsWith(\"'\")) || (result.startsWith('\"') && result.endsWith('\"')))\n result = result.slice(1, -1);\n console.log(`Command result: ${result}`);\n let value = Math.round(parseFloat(result));\n if (!allowNegativeValues && value < 0) value = 0;\n return value;\n}\n\nasync function getConfiguration() {\n /**\n * Collect all needed data\n *\n * This block collects all needed data from cli, environment or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isTemperature = await deviceStorage.get(\"isTemperature\", environment.vars.get(\"type\") !== \"humidity\");\n if (await deviceStorage.has(\"isTemperature\")) {\n console.log(\n `Device type ${isTemperature ? \"temperature\" : \"humidity\"} found in storage. --type parameter is ignored.`,\n );\n }\n let interval = environment.vars.number(\"interval\") ?? (await deviceStorage.get(\"interval\", 60));\n if (interval < 1) {\n console.log(`Invalid Interval ${interval}, set to 60s`);\n interval = 60;\n }\n\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isTemperature ? \"Temperature\" : \"Humidity\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n interval,\n isTemperature,\n uniqueid: uniqueId,\n });\n\n return {\n isTemperature,\n interval,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n };\n}\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,OAAO;AAEP,SAAS,6BAA6B;AACtC,SAAS,cAAc,gBAAgB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AACxC,SAAS,UAAU,sBAAsB;AACzC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAEzB,sBAAsB,EAAE;AAExB,eAAe,OAAO;AAElB,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI,MAAM,iBAAiB;AAK3B,QAAM,SAAS,MAAM,WAAW,OAAO;AAAA;AAAA,IAEnC,IAAI;AAAA;AAAA;AAAA,IAIJ,SAAS;AAAA,MACL;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,eAAe;AAAA,MACX;AAAA,MACA;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,oBAAoB;AAAA,MAChB,MAAM;AAAA,MACN,YAAY;AAAA,QAC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B,QAAM,aAAa;AACnB,QAAM,WAAW,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,QAAQ;AACrG,QAAM,gBAAgB,YAAY,KAAK,OAAO,eAAe,KAAM,MAAM,cAAc,IAAI,iBAAiB,IAAI;AAEhH,QAAM,WAAW,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAM;AACnG,QAAM,cAAc,qBAAqB,gBAAgB,gBAAgB,UAAU;AACnF,QAAM,YAAY,YAAY,KAAK,OAAO,WAAW,KAAM,MAAM,cAAc,IAAI,aAAa,KAAM;AAEtG,QAAM,OAAO,YAAY,KAAK,OAAO,MAAM,KAAK;AAEhD,QAAM,WACF,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAK,MAAM,EAAE,SAAS,CAAC;AAGvG,QAAM,cAAc,IAAI;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;",
4
+ "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a simple Sensor Matter device as temperature or humidity device.\n * It can be used as CLI script and starting point for your own device node implementation.\n * This example is CJS conform and do not use top level await's.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter-node.js\";\n\nimport { requireMinNodeVersion } from \"@project-chip/matter-node.js/util\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { logEndpoint } from \"@project-chip/matter.js/device\";\nimport { HumiditySensorDevice } from \"@project-chip/matter.js/devices/HumiditySensorDevice\";\nimport { TemperatureSensorDevice } from \"@project-chip/matter.js/devices/TemperatureSensorDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { Time } from \"@project-chip/matter.js/time\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\nasync function main() {\n /** Initialize configuration values */\n const {\n isTemperature,\n interval,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n } = await getConfiguration();\n\n /**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\n const server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(\n isTemperature ? TemperatureSensorDevice.deviceType : HumiditySensorDevice.deviceType,\n ),\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n });\n\n /**\n * Matter Nodes are a composition of endpoints. Create and add a single endpoint to the node. This example uses the\n * OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type parameter. It also assigns this Part a\n * unique ID to store the endpoint number for it in the storage to restore the device on restart.\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n let endpoint: Endpoint;\n if (isTemperature) {\n endpoint = new Endpoint(TemperatureSensorDevice, {\n id: \"tempsensor\",\n temperatureMeasurement: {\n // Use this to initialize the measuredValue with the most uptodate value.\n // If you do not know the value and also can not request it, best use \"null\" (if allowed by the cluster).\n measuredValue: getIntValueFromCommandOrRandom(\"value\"),\n },\n });\n } else {\n endpoint = new Endpoint(HumiditySensorDevice, {\n id: \"humsensor\",\n relativeHumidityMeasurement: {\n // Use this to initialize the measuredValue with the most uptodate value.\n // If you do not know the value and also can not request it, best use \"null\" (if allowed by the cluster).\n measuredValue: getIntValueFromCommandOrRandom(\"value\", false),\n },\n });\n }\n\n await server.add(endpoint);\n\n /**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\n logEndpoint(EndpointServer.forEndpoint(server));\n\n const updateInterval = setInterval(() => {\n let setter: Promise<void>;\n if (isTemperature) {\n setter = endpoint.set({\n temperatureMeasurement: {\n measuredValue: getIntValueFromCommandOrRandom(\"value\"),\n },\n });\n } else {\n setter = endpoint.set({\n relativeHumidityMeasurement: {\n measuredValue: getIntValueFromCommandOrRandom(\"value\", false),\n },\n });\n }\n setter.catch(error => console.error(\"Error updating measured value:\", error));\n }, interval * 1000);\n\n // Cleanup our update interval when node goes offline\n server.lifecycle.offline.on(() => clearTimeout(updateInterval));\n\n /**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\n await server.run();\n}\n\nmain().catch(error => console.error(error));\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/** Defined a shell command from an environment variable and execute it and log the response. */\n\nfunction getIntValueFromCommandOrRandom(scriptParamName: string, allowNegativeValues = true) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) {\n if (!allowNegativeValues) return Math.round(Math.random() * 100);\n return (Math.round(Math.random() * 100) - 50) * 100;\n }\n let result = execSync(script).toString().trim();\n if ((result.startsWith(\"'\") && result.endsWith(\"'\")) || (result.startsWith('\"') && result.endsWith('\"')))\n result = result.slice(1, -1);\n console.log(`Command result: ${result}`);\n let value = Math.round(parseFloat(result));\n if (!allowNegativeValues && value < 0) value = 0;\n return value;\n}\n\nasync function getConfiguration() {\n /**\n * Collect all needed data\n *\n * This block collects all needed data from cli, environment or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isTemperature = await deviceStorage.get(\"isTemperature\", environment.vars.get(\"type\") !== \"humidity\");\n if (await deviceStorage.has(\"isTemperature\")) {\n console.log(\n `Device type ${isTemperature ? \"temperature\" : \"humidity\"} found in storage. --type parameter is ignored.`,\n );\n }\n let interval = environment.vars.number(\"interval\") ?? (await deviceStorage.get(\"interval\", 60));\n if (interval < 1) {\n console.log(`Invalid Interval ${interval}, set to 60s`);\n interval = 60;\n }\n\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isTemperature ? \"Temperature\" : \"Humidity\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n interval,\n isTemperature,\n uniqueid: uniqueId,\n });\n\n return {\n isTemperature,\n interval,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n };\n}\n"],
5
+ "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAgBA,OAAO;AAEP,SAAS,6BAA6B;AACtC,SAAS,cAAc,gBAAgB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AACxC,SAAS,UAAU,sBAAsB;AACzC,SAAS,aAAa,sBAAsB;AAC5C,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAEzB,sBAAsB,EAAE;AAExB,eAAe,OAAO;AAElB,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI,MAAM,iBAAiB;AAK3B,QAAM,SAAS,MAAM,WAAW,OAAO;AAAA;AAAA,IAEnC,IAAI;AAAA;AAAA;AAAA,IAIJ,SAAS;AAAA,MACL;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,eAAe;AAAA,MACX;AAAA,MACA;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,oBAAoB;AAAA,MAChB,MAAM;AAAA,MACN,YAAY;AAAA,QACR,gBAAgB,wBAAwB,aAAa,qBAAqB;AAAA,MAC9E;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,kBAAkB;AAAA,MACd;AAAA,MACA,UAAU,SAAS,QAAQ;AAAA,MAC3B,WAAW;AAAA,MACX;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA,cAAc,YAAY,QAAQ;AAAA,MAClC;AAAA,IACJ;A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AAY,KAAM;AACnG,QAAM,cAAc,qBAAqB,gBAAgB,gBAAgB,UAAU;AACnF,QAAM,YAAY,YAAY,KAAK,OAAO,WAAW,KAAM,MAAM,cAAc,IAAI,aAAa,KAAM;AAEtG,QAAM,OAAO,YAAY,KAAK,OAAO,MAAM,KAAK;AAEhD,QAAM,WACF,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAK,MAAM,EAAE,SAAS,CAAC;AAGvG,QAAM,cAAc,IAAI;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@project-chip/matter-node.js-examples",
3
- "version": "0.10.0-alpha.0-20240607-fbc64d30",
3
+ "version": "0.10.0-alpha.0-20240608-7a34e6fa",
4
4
  "description": "CLI/Reference implementation scripts for Matter protocol for node.js",
5
5
  "keywords": [
6
6
  "iot",
@@ -64,10 +64,10 @@
64
64
  "typescript": "~5.4.5"
65
65
  },
66
66
  "dependencies": {
67
- "@project-chip/matter-node-ble.js": "0.10.0-alpha.0-20240607-fbc64d30",
68
- "@project-chip/matter-node.js": "0.10.0-alpha.0-20240607-fbc64d30",
69
- "@project-chip/matter.js": "0.10.0-alpha.0-20240607-fbc64d30",
70
- "@project-chip/matter.js-tools": "0.10.0-alpha.0-20240607-fbc64d30"
67
+ "@project-chip/matter-node-ble.js": "0.10.0-alpha.0-20240608-7a34e6fa",
68
+ "@project-chip/matter-node.js": "0.10.0-alpha.0-20240608-7a34e6fa",
69
+ "@project-chip/matter.js": "0.10.0-alpha.0-20240608-7a34e6fa",
70
+ "@project-chip/matter.js-tools": "0.10.0-alpha.0-20240608-7a34e6fa"
71
71
  },
72
72
  "engines": {
73
73
  "_comment": "For Crypto.hkdf support",
@@ -83,5 +83,5 @@
83
83
  "publishConfig": {
84
84
  "access": "public"
85
85
  },
86
- "gitHead": "3a7a14f335581d32e43329fdacfae823e6eeb5e1"
86
+ "gitHead": "48f46c83e65c5519786b6450ee7cd999d1a0b326"
87
87
  }
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  /**
4
3
  * @license
5
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  /**
4
3
  * @license
5
4
  * Copyright 2022-2023 Project CHIP Authors
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2022-2024 Matter.js Authors