@project-chip/matter-node.js-examples 0.11.0-alpha.0-20240911-db8f7c80 → 0.11.0-alpha.0-20241007-547af42a8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. package/README.md +3 -271
  2. package/dist/esm/examples/BridgedDevicesNodeLegacy.js +5 -4
  3. package/dist/esm/examples/BridgedDevicesNodeLegacy.js.map +1 -2
  4. package/dist/esm/examples/ComposedDeviceNodeLegacy.js +4 -3
  5. package/dist/esm/examples/ComposedDeviceNodeLegacy.js.map +1 -2
  6. package/dist/esm/examples/ControllerNodeLegacy.js +7 -6
  7. package/dist/esm/examples/ControllerNodeLegacy.js.map +1 -2
  8. package/dist/esm/examples/DeviceNodeFullLegacy.js +8 -6
  9. package/dist/esm/examples/DeviceNodeFullLegacy.js.map +1 -2
  10. package/dist/esm/examples/LegacyStorageConverter.js +2 -2
  11. package/dist/esm/examples/LegacyStorageConverter.js.map +0 -1
  12. package/dist/esm/examples/MultiDeviceNodeLegacy.js +5 -4
  13. package/dist/esm/examples/MultiDeviceNodeLegacy.js.map +1 -2
  14. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.js +7 -6
  15. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.js.map +1 -2
  16. package/dist/esm/package.json +3 -0
  17. package/package.json +16 -37
  18. package/src/examples/BridgedDevicesNodeLegacy.ts +4 -3
  19. package/src/examples/ComposedDeviceNodeLegacy.ts +4 -3
  20. package/src/examples/ControllerNodeLegacy.ts +6 -5
  21. package/src/examples/DeviceNodeFullLegacy.ts +7 -5
  22. package/src/examples/LegacyStorageConverter.ts +2 -2
  23. package/src/examples/MultiDeviceNodeLegacy.ts +4 -4
  24. package/src/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.ts +7 -6
  25. package/src/tsconfig.json +13 -13
  26. package/dist/esm/examples/BridgedDevicesNode.js +0 -144
  27. package/dist/esm/examples/BridgedDevicesNode.js.map +0 -7
  28. package/dist/esm/examples/ComposedDeviceNode.js +0 -123
  29. package/dist/esm/examples/ComposedDeviceNode.js.map +0 -7
  30. package/dist/esm/examples/ControllerNode.js +0 -194
  31. package/dist/esm/examples/ControllerNode.js.map +0 -7
  32. package/dist/esm/examples/DeviceNode.js +0 -127
  33. package/dist/esm/examples/DeviceNode.js.map +0 -7
  34. package/dist/esm/examples/DeviceNodeFull.js +0 -253
  35. package/dist/esm/examples/DeviceNodeFull.js.map +0 -7
  36. package/dist/esm/examples/IlluminatedRollerShade.js +0 -60
  37. package/dist/esm/examples/IlluminatedRollerShade.js.map +0 -7
  38. package/dist/esm/examples/LightDevice.js +0 -35
  39. package/dist/esm/examples/LightDevice.js.map +0 -7
  40. package/dist/esm/examples/MultiDeviceNode.js +0 -140
  41. package/dist/esm/examples/MultiDeviceNode.js.map +0 -7
  42. package/dist/esm/examples/SensorDeviceNode.js +0 -175
  43. package/dist/esm/examples/SensorDeviceNode.js.map +0 -7
  44. package/dist/esm/examples/cluster/DummyThreadNetworkCommissioningServer.js +0 -121
  45. package/dist/esm/examples/cluster/DummyThreadNetworkCommissioningServer.js.map +0 -7
  46. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServer.js +0 -121
  47. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServer.js.map +0 -7
  48. package/dist/esm/examples/cluster/MyFancyOwnFunctionality.js +0 -110
  49. package/dist/esm/examples/cluster/MyFancyOwnFunctionality.js.map +0 -7
  50. package/dist/esm/tutorial/example01.js +0 -5
  51. package/dist/esm/tutorial/example01.js.map +0 -7
  52. package/dist/esm/tutorial/example02.js +0 -7
  53. package/dist/esm/tutorial/example02.js.map +0 -7
  54. package/dist/esm/tutorial/example03.js +0 -15
  55. package/dist/esm/tutorial/example03.js.map +0 -7
  56. package/dist/esm/tutorial/example04.js +0 -10
  57. package/dist/esm/tutorial/example04.js.map +0 -7
  58. package/dist/esm/tutorial/example05.js +0 -14
  59. package/dist/esm/tutorial/example05.js.map +0 -7
  60. package/src/examples/BridgedDevicesNode.ts +0 -259
  61. package/src/examples/ComposedDeviceNode.ts +0 -196
  62. package/src/examples/ControllerNode.ts +0 -314
  63. package/src/examples/DeviceNode.ts +0 -201
  64. package/src/examples/DeviceNodeFull.ts +0 -440
  65. package/src/examples/IlluminatedRollerShade.ts +0 -96
  66. package/src/examples/LightDevice.ts +0 -61
  67. package/src/examples/MultiDeviceNode.ts +0 -208
  68. package/src/examples/SensorDeviceNode.ts +0 -247
  69. package/src/examples/cluster/DummyThreadNetworkCommissioningServer.ts +0 -156
  70. package/src/examples/cluster/DummyWifiNetworkCommissioningServer.ts +0 -154
  71. package/src/examples/cluster/MyFancyOwnFunctionality.ts +0 -185
  72. package/src/tutorial/example01.ts +0 -6
  73. package/src/tutorial/example02.ts +0 -9
  74. package/src/tutorial/example03.ts +0 -19
  75. package/src/tutorial/example04.ts +0 -13
  76. package/src/tutorial/example05.ts +0 -19
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/DeviceNodeFullLegacy.ts"],
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 * IMPORTANT: This example uses a Legacy API which will be deprecated in the future.\n * It is just still here to support developers in converting their code to the new API!\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 */\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 {\n StorageBackendDisk,\n commandExecutor,\n getIntParameter,\n getParameter,\n hasParameter,\n requireMinNodeVersion,\n} from \"@project-chip/matter.js-nodejs\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { CommissioningServer, MatterServer } from \"@project-chip/matter.js\";\nimport { LogFormat, LogLevel, Logger, StorageManager, Time, singleton } from \"@project-chip/matter.js-general\";\nimport { Ble } from \"@project-chip/matter.js/ble\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport { OnOffLightDevice, OnOffPluginUnitDevice, logEndpoint } from \"@project-chip/matter.js/device\";\nimport { QrCode } from \"@project-chip/matter.js/schema\";\nimport DummyWifiNetworkCommissioningClusterServer from \"./cluster/DummyWifiNetworkCommissioningServerLegacy.js\";\n\nconst logger = Logger.get(\"Device\");\n\nrequireMinNodeVersion(16);\n\n/** Configure logging */\nswitch (getParameter(\"loglevel\")) {\n case \"fatal\":\n Logger.defaultLogLevel = LogLevel.FATAL;\n break;\n case \"error\":\n Logger.defaultLogLevel = LogLevel.ERROR;\n break;\n case \"warn\":\n Logger.defaultLogLevel = LogLevel.WARN;\n break;\n case \"info\":\n Logger.defaultLogLevel = LogLevel.INFO;\n break;\n}\n\nswitch (getParameter(\"logformat\")) {\n case \"plain\":\n Logger.format = LogFormat.PLAIN;\n break;\n case \"html\":\n Logger.format = LogFormat.HTML;\n break;\n default:\n if (process.stdin?.isTTY) Logger.format = LogFormat.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\") ?? \".device-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 Device {\n private matterServer: MatterServer | undefined;\n\n async start() {\n logger.info(`node-matter`);\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 deviceStorage = storageManager.createContext(\"Device\");\n\n if (deviceStorage.has(\"isSocket\")) {\n logger.info(\"Device type found in storage. -type parameter is ignored.\");\n }\n const isSocket = deviceStorage.get(\"isSocket\", getParameter(\"type\") === \"socket\");\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = getIntParameter(\"passcode\") ?? deviceStorage.get(\"passcode\", 20202021);\n const discriminator = getIntParameter(\"discriminator\") ?? deviceStorage.get(\"discriminator\", 3840);\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = getIntParameter(\"vendorid\") ?? deviceStorage.get(\"vendorid\", 0xfff1);\n const productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\n const productId = getIntParameter(\"productid\") ?? deviceStorage.get(\"productid\", 0x8000);\n\n const netInterface = getParameter(\"netinterface\");\n const port = getIntParameter(\"port\") ?? 5540;\n\n const uniqueId = getIntParameter(\"uniqueid\") ?? deviceStorage.get(\"uniqueid\", Time.nowMs());\n\n deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n isSocket,\n uniqueid: uniqueId,\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 const onOffDevice = isSocket ? new OnOffPluginUnitDevice() : new OnOffLightDevice();\n onOffDevice.addOnOffListener(on => commandExecutor(on ? \"on\" : \"off\")?.());\n\n onOffDevice.addCommandHandler(\"identify\", async ({ request: { identifyTime } }) =>\n logger.info(`Identify called for OnOffDevice: ${identifyTime}`),\n );\n\n /**\n * Create Matter Server and CommissioningServer Node\n *\n * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a\n * commissioningServer to it and add the just created device instance to it.\n * The CommissioningServer 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 this.matterServer = new MatterServer(storageManager, { mdnsInterface: netInterface });\n\n const commissioningServer = new CommissioningServer({\n port,\n deviceName,\n deviceType: DeviceTypeId(onOffDevice.deviceType),\n passcode,\n discriminator,\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `node-matter-${uniqueId}`,\n },\n delayedAnnouncement: hasParameter(\"ble\"), // Delay announcement when BLE is used to show how limited advertisement works\n activeSessionsChangedCallback: fabricIndex => {\n console.log(\n `activeSessionsChangedCallback: Active sessions changed on Fabric ${fabricIndex}`,\n commissioningServer.getActiveSessionInformation(fabricIndex),\n );\n },\n commissioningChangedCallback: fabricIndex => {\n console.log(\n `commissioningChangedCallback: Commissioning changed on Fabric ${fabricIndex}`,\n commissioningServer.getCommissionedFabricInformation(fabricIndex)[0],\n );\n },\n });\n\n // optionally add a listener for the testEventTrigger command from the GeneralDiagnostics cluster\n commissioningServer.addCommandHandler(\"testEventTrigger\", async ({ request: { enableKey, eventTrigger } }) =>\n logger.info(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`),\n );\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 if (hasParameter(\"ble\")) {\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 commissioningServer.addRootClusterServer(DummyWifiNetworkCommissioningClusterServer);\n }\n\n commissioningServer.addDevice(onOffDevice);\n\n await this.matterServer.addCommissioningServer(commissioningServer);\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 this.matterServer.start();\n\n logEndpoint(commissioningServer.getRootEndpoint());\n\n // When we want to limit the initial announcement to one medium (e.g. BLE) then we need to delay the\n // announcement and provide the limiting information.\n // Without delaying the announcement is directly triggered with the above \"start()\" call.\n if (hasParameter(\"ble\")) {\n // Announce operational in BLE network only if we have ble enabled, else everywhere\n await commissioningServer.advertise({ ble: true });\n }\n\n /**\n * Print Pairing Information\n *\n * If the device is not already commissioned (this info is stored in the storage system) then get and print the\n * pairing details. This includes the QR code that can be scanned by the Matter app to pair the device.\n */\n\n logger.info(\"Listening\");\n if (!commissioningServer.isCommissioned()) {\n const pairingData = commissioningServer.getPairingCode({\n ble: hasParameter(\"ble\"),\n onIpNetwork: false,\n });\n\n const { qrPairingCode, manualPairingCode } = pairingData;\n\n console.log(QrCode.get(qrPairingCode));\n logger.info(\n `QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`,\n );\n logger.info(`Manual pairing code: ${manualPairingCode}`);\n } else {\n logger.info(\"Device is already commissioned. Waiting for controllers to connect ...\");\n }\n }\n\n async stop() {\n await this.matterServer?.close();\n }\n}\n\nconst device = new Device();\ndevice\n .start()\n .then(() => {\n /* done */\n })\n .catch(err => console.error(err));\n\nprocess.on(\"SIGINT\", () => {\n // Clean up on CTRL-C\n device\n .stop()\n .then(() => {\n // Pragmatic way to make sure the storage is correctly closed before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project-chip/matter.js-nodejs";
8
- import { Time } from "@project-chip/matter.js-general";
7
+ import { StorageBackendDisk } from "@project-chip/matter-node.js/storage";
8
+ import { Time } from "@project-chip/matter-node.js/util";
9
9
  import { Environment, StorageService } from "@project-chip/matter.js/environment";
10
10
  import { LocalStorage } from "node-localstorage";
11
11
  const environment = Environment.default;
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/LegacyStorageConverter.ts"],
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 { StorageBackendDisk } from \"@project-chip/matter.js-nodejs\";\n\nimport { Time } from \"@project-chip/matter.js-general\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\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. Cannot 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}. Cannot 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[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Ac,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;",
6
5
  "names": []
7
6
  }
@@ -5,15 +5,16 @@
5
5
  * SPDX-License-Identifier: Apache-2.0
6
6
  */
7
7
  import {
8
- StorageBackendDisk,
9
8
  commandExecutor,
10
9
  getIntParameter,
11
10
  getParameter,
12
11
  hasParameter,
13
- requireMinNodeVersion
14
- } from "@project-chip/matter.js-nodejs";
12
+ requireMinNodeVersion,
13
+ Time
14
+ } from "@project-chip/matter-node.js/util";
15
+ import { LogFormat, Logger, LogLevel } from "@project-chip/matter-node.js/log";
16
+ import { StorageBackendDisk, StorageManager } from "@project-chip/matter-node.js/storage";
15
17
  import { CommissioningServer, MatterServer } from "@project-chip/matter.js";
16
- import { LogFormat, LogLevel, Logger, StorageManager, Time } from "@project-chip/matter.js-general";
17
18
  import { VendorId } from "@project-chip/matter.js/datatype";
18
19
  import { DeviceTypes, OnOffLightDevice, OnOffPluginUnitDevice } from "@project-chip/matter.js/device";
19
20
  import { QrCode } from "@project-chip/matter.js/schema";
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/examples/MultiDeviceNodeLegacy.ts"],
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 * IMPORTANT: This example uses a Legacy API which will be deprecated in the future.\n * It is just still here to support developers in converting their code to the new API!\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. When you want to add a composed devices to a Aggregator you need to\n * add all endpoints of the composed device to an \"ComposedDevice\" instance! (not shown in this 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 {\n StorageBackendDisk,\n commandExecutor,\n getIntParameter,\n getParameter,\n hasParameter,\n requireMinNodeVersion,\n} from \"@project-chip/matter.js-nodejs\";\n\nimport { CommissioningServer, MatterServer } from \"@project-chip/matter.js\";\n\nimport { LogFormat, LogLevel, Logger, StorageManager, Time } from \"@project-chip/matter.js-general\";\nimport { VendorId } from \"@project-chip/matter.js/datatype\";\nimport { DeviceTypes, OnOffLightDevice, OnOffPluginUnitDevice } from \"@project-chip/matter.js/device\";\nimport { QrCode } from \"@project-chip/matter.js/schema\";\n\nconst logger = Logger.get(\"MultiDevice\");\n\nrequireMinNodeVersion(16);\n\n/** Configure logging */\nswitch (getParameter(\"loglevel\")) {\n case \"fatal\":\n Logger.defaultLogLevel = LogLevel.FATAL;\n break;\n case \"error\":\n Logger.defaultLogLevel = LogLevel.ERROR;\n break;\n case \"warn\":\n Logger.defaultLogLevel = LogLevel.WARN;\n break;\n case \"info\":\n Logger.defaultLogLevel = LogLevel.INFO;\n break;\n}\n\nswitch (getParameter(\"logformat\")) {\n case \"plain\":\n Logger.format = LogFormat.PLAIN;\n break;\n case \"html\":\n Logger.format = LogFormat.HTML;\n break;\n default:\n if (process.stdin?.isTTY) Logger.format = LogFormat.ANSI;\n}\n\nconst storageLocation = getParameter(\"store\") ?? \".device-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 Device {\n private matterServer: MatterServer | undefined;\n\n async start() {\n logger.info(`node-matter`);\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 const netInterface = getParameter(\"netinterface\");\n\n const deviceStorage = storageManager.createContext(\"Device\");\n\n /**\n * Create Matter Server and CommissioningServer Node\n *\n * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a\n * commissioningServer to it and add the just created device instance to it.\n * The CommissioningServer 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 this.matterServer = new MatterServer(storageManager, { mdnsInterface: netInterface });\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 const commissioningServers = new Array<CommissioningServer>();\n\n let defaultPasscode = 20202021;\n let defaultDiscriminator = 3840;\n let defaultPort = 5550;\n\n const numDevices = getIntParameter(\"num\") || 2;\n for (let i = 1; i <= numDevices; i++) {\n if (deviceStorage.has(`isSocket${i}`)) {\n logger.info(\"Device type found in storage. -type parameter is ignored.\");\n }\n const isSocket = deviceStorage.get(`isSocket${i}`, getParameter(`type${i}`) === \"socket\");\n const deviceName = `Matter ${getParameter(`type${i}`) ?? \"light\"} device ${i}`;\n const deviceType =\n getParameter(`type${i}`) === \"socket\"\n ? DeviceTypes.ON_OFF_PLUGIN_UNIT.code\n : DeviceTypes.ON_OFF_LIGHT.code;\n const vendorName = \"matter-node.js\";\n const passcode = getIntParameter(`passcode${i}`) ?? deviceStorage.get(`passcode${i}`, defaultPasscode++);\n const discriminator =\n getIntParameter(`discriminator${i}`) ?? deviceStorage.get(`discriminator${i}`, defaultDiscriminator++);\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = getIntParameter(`vendorid${i}`) ?? deviceStorage.get(`vendorid${i}`, 0xfff1);\n const productName = `node-matter OnOff-Device ${i}`;\n const productId = getIntParameter(`productid${i}`) ?? deviceStorage.get(`productid${i}`, 0x8000);\n\n const port = getIntParameter(`port${i}`) ?? defaultPort++;\n\n const uniqueId =\n getIntParameter(`uniqueid${i}`) ?? deviceStorage.get(`uniqueid${i}`, `${i}-${Time.nowMs()}`);\n\n deviceStorage.set(`passcode${i}`, passcode);\n deviceStorage.set(`discriminator${i}`, discriminator);\n deviceStorage.set(`vendorid${i}`, vendorId);\n deviceStorage.set(`productid${i}`, productId);\n deviceStorage.set(`isSocket${i}`, isSocket);\n deviceStorage.set(`uniqueid${i}`, uniqueId);\n\n const commissioningServer = new CommissioningServer({\n port,\n deviceName,\n deviceType,\n passcode,\n discriminator,\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `node-matter-${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 onOffDevice =\n getParameter(`type${i}`) === \"socket\" ? new OnOffPluginUnitDevice() : new OnOffLightDevice();\n onOffDevice.addFixedLabel(\"orientation\", getParameter(`orientation${i}`) ?? `orientation ${i}`);\n onOffDevice.addOnOffListener(on => commandExecutor(on ? `on${i}` : `off${i}`)?.());\n commissioningServer.addDevice(onOffDevice);\n\n await this.matterServer.addCommissioningServer(commissioningServer);\n\n commissioningServers.push(commissioningServer);\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\n await this.matterServer.start();\n\n /**\n * Print Pairing Information\n *\n * If the device is not already commissioned (this info is stored in the storage system) then get and print the\n * pairing details. This includes the QR code that can be scanned by the Matter app to pair the device.\n */\n\n logger.info(\"Listening\");\n console.log();\n commissioningServers.forEach((commissioningServer, index) => {\n console.log(\"----------------------------\");\n console.log(`Device ${index + 1}:`);\n if (!commissioningServer.isCommissioned()) {\n const pairingData = commissioningServer.getPairingCode();\n const { qrPairingCode, manualPairingCode } = pairingData;\n\n console.log(QrCode.get(qrPairingCode));\n console.log(\n `QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`,\n );\n console.log(`Manual pairing code: ${manualPairingCode}`);\n } else {\n console.log(\"Device is already commissioned. Waiting for controllers to connect ...\");\n }\n console.log();\n });\n }\n\n async stop() {\n await this.matterServer?.close();\n }\n}\n\nconst device = new Device();\ndevice\n .start()\n .then(() => {\n /* done */\n })\n .catch(err => console.error(err));\n\nprocess.on(\"SIGINT\", () => {\n // Clean up on CTRL-C\n device\n .stop()\n .then(() => {\n // Pragmatic way to make sure the storage is correctly closed before the process ends.\n storage.close();\n process.exit(0);\n })\n .catch(err => console.error(err));\n});\n"],
5
- "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAsBA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,qBAAqB,oBAAoB;AAElD,SAAS,WAAW,UAAU,QAAQ,gBAAgB,YAAY;AAClE,SAAS,gBAAgB;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AACvB,YAAQ,IAAI;AACZ,yBAAqB,QAAQ,CAAC,qBAAqB,UAAU;AACzD,cAAQ,IAAI,8BAA8B;AAC1C,cAAQ,IAAI,UAAU,QAAQ,CAAC,GAAG;AAClC,UAAI,CAAC,oBAAoB,eAAe,GAAG;AACvC,cAAM,cAAc,oBAAoB,eAAe;AACvD,cAAM,EAAE,eAAe,kBAAkB,IAAI;AAE7C,gBAAQ,IAAI,OAAO,IAAI,aAAa,CAAC;AACrC,gBAAQ;AAAA,UACJ,gFAAgF,aAAa;AAAA,QACjG;AACA,gBAAQ,IAAI,wBAAwB,iBAAiB,EAAE;AAAA,MAC3D,OAAO;AACH,gBAAQ,IAAI,wEAAwE;AAAA,MACxF;AACA,cAAQ,IAAI;AAAA,IAChB,CAAC;AAAA,EACL;AAAA,EAEA,MAAM,OAAO;AACT,UAAM,KAAK,cAAc,MAAM;AAAA,EACnC;AACJ;AAEA,MAAM,SAAS,IAAI,OAAO;AAC1B,OACK,MAAM,EACN,KAAK,MAAM;AAEZ,CAAC,EACA,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AAEpC,QAAQ,GAAG,UAAU,MAAM;AAEvB,SACK,KAAK,EACL,KAAK,MAAM;AAER,YAAQ,MAAM;AACd,YAAQ,KAAK,CAAC;AAAA,EAClB,CAAC,EACA,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AACxC,CAAC;",
6
5
  "names": []
7
6
  }
@@ -3,13 +3,14 @@
3
3
  * Copyright 2022-2024 Matter.js Authors
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { getParameter } from "@project-chip/matter.js-nodejs";
6
+ import { getParameter } from "@project-chip/matter-node.js/util";
7
+ import { MatterDevice } from "@project-chip/matter.js";
7
8
  import {
8
9
  ClusterServer,
9
10
  GeneralCommissioningCluster,
10
11
  NetworkCommissioning
11
12
  } from "@project-chip/matter.js/cluster";
12
- import { Bytes } from "../../../../general/dist/cjs/index.js";
13
+ import { Bytes } from "@project-chip/matter.js/util";
13
14
  const firstNetworkId = new Uint8Array(32);
14
15
  const WifiNetworkCluster = NetworkCommissioning.Cluster.with(NetworkCommissioning.Feature.WiFiNetworkInterface);
15
16
  const Server = ClusterServer(
@@ -64,7 +65,7 @@ const Server = ClusterServer(
64
65
  console.log(
65
66
  `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(ssid)} ${Bytes.toHex(credentials)} ${breadcrumb}`
66
67
  );
67
- session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
68
+ MatterDevice.of(session).assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
68
69
  if (breadcrumb !== void 0) {
69
70
  const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);
70
71
  generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);
@@ -86,7 +87,7 @@ const Server = ClusterServer(
86
87
  console.log(
87
88
  `---> removeNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`
88
89
  );
89
- session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
90
+ MatterDevice.of(session).assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
90
91
  if (breadcrumb !== void 0) {
91
92
  const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);
92
93
  generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);
@@ -108,7 +109,7 @@ const Server = ClusterServer(
108
109
  console.log(
109
110
  `---> connectNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`
110
111
  );
111
- session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
112
+ MatterDevice.of(session).assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
112
113
  if (breadcrumb !== void 0) {
113
114
  const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);
114
115
  generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);
@@ -120,7 +121,7 @@ const Server = ClusterServer(
120
121
  lastNetworkingStatus?.setLocal(networkingStatus);
121
122
  lastNetworkId?.setLocal(firstNetworkId);
122
123
  lastConnectErrorValue?.setLocal(null);
123
- const device = session.context;
124
+ const device = MatterDevice.of(session);
124
125
  await device.startAnnouncement();
125
126
  return {
126
127
  networkingStatus,
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { getParameter } from \"@project-chip/matter.js-nodejs\";\nimport {\n ClusterServer,\n ClusterServerObj,\n GeneralCommissioningCluster,\n NetworkCommissioning,\n} from \"@project-chip/matter.js/cluster\";\nimport { Bytes } from \"../../../../general/dist/cjs/index.js\";\n\nconst firstNetworkId = new Uint8Array(32);\n\nconst WifiNetworkCluster = NetworkCommissioning.Cluster.with(NetworkCommissioning.Feature.WiFiNetworkInterface);\n\n/**\n * This represents a Dummy version of a Wifi Network Commissioning Cluster Server without real Wifi related logic, beside\n * returning some values provided as CLI parameters. This dummy implementation is only there for tests/as showcase for BLE\n * commissioning of a device.\n */\nconst Server: ClusterServerObj<typeof WifiNetworkCluster> = ClusterServer(\n NetworkCommissioning.Cluster.with(NetworkCommissioning.Feature.WiFiNetworkInterface),\n {\n maxNetworks: 1,\n interfaceEnabled: true,\n lastConnectErrorValue: 0,\n lastNetworkId: null,\n lastNetworkingStatus: null,\n networks: [{ networkId: firstNetworkId, connected: false }],\n scanMaxTimeSeconds: 3,\n connectMaxTimeSeconds: 3,\n supportedWiFiBands: [NetworkCommissioning.WiFiBand[\"2G4\"]],\n },\n {\n scanNetworks: async ({ request: { ssid, breadcrumb }, attributes: { lastNetworkingStatus }, endpoint }) => {\n console.log(\n `---> scanNetworks called on NetworkCommissioning cluster: ${ssid ? Bytes.toHex(ssid) : undefined} ${breadcrumb}`,\n );\n\n // Simulate successful scan\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n\n return {\n networkingStatus,\n wiFiScanResults: [\n {\n security: {\n unencrypted: false,\n wep: false,\n wpaPersonal: false,\n wpa2Personal: true,\n wpa3Personal: true,\n },\n ssid: ssid || Bytes.fromString(getParameter(\"ble-wifi-scan-ssid\") ?? \"TestSSID\"), // Set a valid existing local Wi-Fi SSID here\n bssid: Bytes.fromString(getParameter(\"ble-wifi-scan-bssid\") ?? \"00:00:00:00:00:00\"),\n channel: 1,\n },\n ],\n };\n },\n addOrUpdateWiFiNetwork: async ({\n request: { ssid, credentials, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId },\n endpoint,\n session,\n }) => {\n console.log(\n `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(ssid)} ${Bytes.toHex(credentials)} ${breadcrumb}`,\n );\n\n session.context.assertFailSafeArmed(\"Failsafe timer needs to be armed to add or update networks.\");\n\n // Simulate successful add or update\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n },\n removeNetwork: async ({\n request: { networkId, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId },\n endpoint,\n session,\n }) => {\n console.log(\n `---> removeNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,\n );\n\n session.context.assertFailSafeArmed(\"Failsafe timer needs to be armed to add or update networks.\");\n\n // Simulate successful add or update\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n },\n connectNetwork: async ({\n request: { networkId, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId, lastConnectErrorValue, networks },\n endpoint,\n session,\n }) => {\n console.log(\n `---> connectNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,\n );\n\n session.context.assertFailSafeArmed(\"Failsafe timer needs to be armed to add or update networks.\");\n\n // Simulate successful connection\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkList = networks.getLocal();\n networkList[0].connected = true;\n networks.setLocal(networkList);\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n lastConnectErrorValue?.setLocal(null);\n\n // Announce operational in IP network\n const device = session.context;\n await device.startAnnouncement();\n\n return {\n networkingStatus,\n errorValue: null,\n };\n },\n reorderNetwork: async ({\n request: { networkId, networkIndex, breadcrumb },\n attributes: { lastNetworkingStatus },\n endpoint,\n }) => {\n console.log(\n `---> reorderNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${networkIndex} ${breadcrumb}`,\n );\n\n // Simulate successful connection\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n },\n },\n);\n\nexport default Server;\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,oBAAoB;AAC7B;AAAA,EACI;AAAA,EAEA;AAAA,EACA;AAAA,OACG;AACP,SAAS,aAAa;AAEtB,MAAM,iBAAiB,IAAI,WAAW,EAAE;AAExC,MAAM,qBAAqB,qBAAqB,QAAQ,KAAK,qBAAqB,QAAQ,oBAAoB;AAO9G,MAAM,SAAsD;AAAA,EACxD,qBAAqB,QAAQ,KAAK,qBAAqB,QAAQ,oBAAoB;AAAA,EACnF;AAAA,IACI,aAAa;AAAA,IACb,kBAAkB;AAAA,IAClB,uBAAuB;AAAA,IACvB,eAAe;AAAA,IACf,sBAAsB;AAAA,IACtB,UAAU,CAAC,EAAE,WAAW,gBAAgB,WAAW,MAAM,CAAC;AAAA,IAC1D,oBAAoB;AAAA,IACpB,uBAAuB;AAAA,IACvB,oBAAoB,CAAC,qBAAqB,SAAS,KAAK,CAAC;AAAA,EAC7D;AAAA,EACA;AAAA,IACI,cAAc,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,GAAG,YAAY,EAAE,qBAAqB,GAAG,SAAS,MAAM;AACvG,cAAQ;AAAA,QACJ,6DAA6D,OAAO,MAAM,MAAM,IAAI,IAAI,MAAS,IAAI,UAAU;AAAA,MACnH;AAGA,UAAI,eAAe,QAAW;AAC1B,cAAM,8BAA8B,SAAS,iBAAiB,2BAA2B;AACzF,qCAA6B,uBAAuB,UAAU;AAAA,MAClE;AAEA,YAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,4BAAsB,SAAS,gBAAgB;AAE/C,aAAO;AAAA,QACH;AAAA,QACA,iBAAiB;AAAA,UACb;AAAA,YACI,UAAU;AAAA,cACN,aAAa;AAAA,cACb,KAAK;AAAA,cACL,aAAa;AAAA,cACb,cAAc;AAAA,cACd,cAAc;AAAA,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AAAA,EACJ;AACJ;AAEA,IAAO,oDAAQ;",
6
5
  "names": []
7
6
  }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@project-chip/matter-node.js-examples",
3
- "version": "0.11.0-alpha.0-20240911-db8f7c80",
4
- "description": "CLI/Reference implementation scripts for Matter protocol for node.js",
3
+ "version": "0.11.0-alpha.0-20241007-547af42a8",
4
+ "description": "Matter.js examples and reference implementations",
5
5
  "keywords": [
6
6
  "iot",
7
7
  "home automation",
@@ -9,7 +9,7 @@
9
9
  "smart device"
10
10
  ],
11
11
  "license": "Apache-2.0",
12
- "author": "Project CHIP Authors",
12
+ "author": "matter.js authors",
13
13
  "contributors": [
14
14
  "Martin Turon <mturon@google.com>",
15
15
  "Marco Fucci di Napoli <mfucci@gmail.com>",
@@ -21,54 +21,33 @@
21
21
  "homepage": "https://github.com/project-chip/matter.js",
22
22
  "repository": {
23
23
  "type": "git",
24
- "url": "https://github.com/project-chip/matter.js.git"
24
+ "url": "git+https://github.com/project-chip/matter.js.git"
25
25
  },
26
26
  "scripts": {
27
27
  "clean": "matter-build clean",
28
28
  "build": "matter-build",
29
29
  "build-clean": "matter-build --clean",
30
- "matter-light": "matter-run src/examples/LightDevice.ts",
31
- "matter-sensor": "matter-run src/examples/SensorDeviceNode.ts",
32
- "matter-excelsior1000": "matter-run src/examples/IlluminatedRollerShade.ts",
33
- "matter-device": "matter-run src/examples/DeviceNode.ts",
34
- "matter-bridge": "matter-run src/examples/BridgedDevicesNode.ts",
35
- "matter-composeddevice": "matter-run src/examples/ComposedDeviceNode.ts",
36
- "matter-multidevice": "matter-run src/examples/MultiDeviceNode.ts",
37
- "matter-controller": "matter-run src/examples/ControllerNode.ts",
38
30
  "matter-device-legacy": "matter-run src/examples/DeviceNodeLegacy.ts",
39
31
  "matter-bridge-legacy": "matter-run src/examples/BridgedDevicesNodeLegacy.ts",
40
32
  "matter-composeddevice-legacy": "matter-run src/examples/ComposedDeviceNodeLegacy.ts",
41
33
  "matter-multidevice-legacy": "matter-run src/examples/MultiDeviceNodeLegacy.ts",
42
34
  "matter-controller-legacy": "matter-run src/examples/ControllerNodeLegacy.ts",
43
- "matter-legacystorageconverter": "matter-run src/examples/LegacyStorageConverter.ts",
44
- "bundle-device": "esbuild src/examples/DeviceNode.ts --bundle --platform=node --conditions=esbuild --external:@stoprocent/bleno --external:@stoprocent/bluetooth-hci-socket --sourcemap --minify --outfile=build/bundle/DeviceNode.cjs",
45
- "matter-device-bundled": "node --enable-source-maps build/bundle/DeviceNode.cjs"
35
+ "matter-legacystorageconverter": "matter-run src/examples/LegacyStorageConverter.ts"
46
36
  },
47
37
  "bin": {
48
- "matter-light": "./dist/esm/examples/LightDevice.ts",
49
- "matter-excelsior1000": "./dist/esm/examples/IlluminatedRollerShade.ts",
50
- "matter-sensor": "./dist/esm/examples/SensorDeviceNode.js",
51
- "matter-device": "./dist/esm/examples/DeviceNode.js",
52
- "matter-bridge": "./dist/esm/examples/BridgedDevicesNode.js",
53
- "matter-composeddevice": "./dist/esm/examples/ComposedDeviceNode.js",
54
- "matter-multidevice": "./dist/esm/examples/MultiDeviceNode.js",
55
- "matter-controller": "./dist/esm/examples/ControllerNode.js",
56
- "matter-device-legacy": "./dist/esm/examples/DeviceNodeLegacy.js",
57
- "matter-bridge-legacy": "./dist/esm/examples/BridgedDevicesNodeLegacy.js",
58
- "matter-composeddevice-legacy": "./dist/esm/examples/ComposedDeviceNodeLegacy.js",
59
- "matter-multidevice-legacy": "./dist/esm/examples/MultiDeviceNodeLegacy.js",
60
- "matter-controller-legacy": "./dist/esm/examples/ControllerNodeLegacy.js",
61
- "matter-legacystorageconverter": "./dist/esm/examples/LegacyStorageConverter.js"
62
- },
63
- "devDependencies": {
64
- "typescript": "~5.5.3"
38
+ "matter-device-legacy": "dist/esm/examples/DeviceNodeLegacy.js",
39
+ "matter-bridge-legacy": "dist/esm/examples/BridgedDevicesNodeLegacy.js",
40
+ "matter-composeddevice-legacy": "dist/esm/examples/ComposedDeviceNodeLegacy.js",
41
+ "matter-multidevice-legacy": "dist/esm/examples/MultiDeviceNodeLegacy.js",
42
+ "matter-controller-legacy": "dist/esm/examples/ControllerNodeLegacy.js",
43
+ "matter-legacystorageconverter": "dist/esm/examples/LegacyStorageConverter.js"
65
44
  },
66
45
  "dependencies": {
67
- "@project-chip/matter-node-ble.js": "0.11.0-alpha.0-20240911-db8f7c80",
68
- "@project-chip/matter.js-nodejs": "0.11.0-alpha.0-20240911-db8f7c80",
69
- "@project-chip/matter.js": "0.11.0-alpha.0-20240911-db8f7c80",
70
- "@project-chip/matter.js-general": "0.11.0-alpha.0-20240911-db8f7c80",
71
- "@project-chip/matter.js-tools": "0.11.0-alpha.0-20240911-db8f7c80"
46
+ "@project-chip/matter-node-ble.js": "0.11.0-alpha.0-20241007-547af42a8",
47
+ "@project-chip/matter.js": "0.11.0-alpha.0-20241007-547af42a8"
48
+ },
49
+ "devDependencies": {
50
+ "@matter/tools": "0.11.0-alpha.0-20241007-547af42a8"
72
51
  },
73
52
  "engines": {
74
53
  "node": ">=18.0.0"
@@ -19,17 +19,18 @@
19
19
  * Import needed modules from @project-chip/matter-node.js
20
20
  */
21
21
  // Include this first to auto-register Crypto, Network and Time Node.js implementations
22
+ import { StorageBackendDisk, StorageManager } from "@project-chip/matter-node.js/storage";
22
23
  import {
23
- StorageBackendDisk,
24
24
  commandExecutor,
25
25
  getIntParameter,
26
26
  getParameter,
27
27
  hasParameter,
28
28
  requireMinNodeVersion,
29
- } from "@project-chip/matter.js-nodejs";
29
+ Time,
30
+ } from "@project-chip/matter-node.js/util";
30
31
 
32
+ import { LogFormat, Logger, LogLevel } from "@project-chip/matter-node.js/log";
31
33
  import { CommissioningServer, MatterServer } from "@project-chip/matter.js";
32
- import { LogFormat, LogLevel, Logger, StorageManager, Time } from "@project-chip/matter.js-general";
33
34
  import { VendorId } from "@project-chip/matter.js/datatype";
34
35
  import { Aggregator, DeviceTypes, OnOffLightDevice, OnOffPluginUnitDevice } from "@project-chip/matter.js/device";
35
36
  import { QrCode } from "@project-chip/matter.js/schema";
@@ -27,11 +27,12 @@ import {
27
27
  getParameter,
28
28
  hasParameter,
29
29
  requireMinNodeVersion,
30
- StorageBackendDisk,
31
- } from "@project-chip/matter.js-nodejs";
30
+ Time,
31
+ } from "@project-chip/matter-node.js/util";
32
32
 
33
+ import { LogFormat, Logger, LogLevel } from "@project-chip/matter-node.js/log";
34
+ import { StorageBackendDisk, StorageManager } from "@project-chip/matter-node.js/storage";
33
35
  import { CommissioningServer, MatterServer } from "@project-chip/matter.js";
34
- import { LogFormat, Logger, LogLevel, StorageManager, Time } from "@project-chip/matter.js-general";
35
36
  import { VendorId } from "@project-chip/matter.js/datatype";
36
37
  import { DeviceTypes, OnOffLightDevice, OnOffPluginUnitDevice } from "@project-chip/matter.js/device";
37
38
  import { QrCode } from "@project-chip/matter.js/schema";
@@ -16,16 +16,17 @@
16
16
  */
17
17
  // Include this first to auto-register Crypto, Network and Time Node.js implementations
18
18
  import {
19
- StorageBackendDisk,
20
19
  getIntParameter,
21
20
  getParameter,
22
21
  hasParameter,
23
22
  requireMinNodeVersion,
24
- } from "@project-chip/matter.js-nodejs";
23
+ singleton,
24
+ } from "@project-chip/matter-node.js/util";
25
25
 
26
- import { BleNode } from "@project-chip/matter-node-ble.js/ble";
26
+ import { NodeJsBle } from "@project-chip/matter-node-ble.js/ble";
27
+ import { LogFormat, LogLevel, Logger } from "@project-chip/matter-node.js/log";
28
+ import { StorageBackendDisk, StorageManager } from "@project-chip/matter-node.js/storage";
27
29
  import { CommissioningController, MatterServer, NodeCommissioningOptions } from "@project-chip/matter.js";
28
- import { LogFormat, LogLevel, Logger, StorageManager, singleton } from "@project-chip/matter.js-general";
29
30
  import { Ble } from "@project-chip/matter.js/ble";
30
31
  import {
31
32
  BasicInformationCluster,
@@ -73,7 +74,7 @@ if (hasParameter("ble")) {
73
74
  // Initialize Ble
74
75
  Ble.get = singleton(
75
76
  () =>
76
- new BleNode({
77
+ new NodeJsBle({
77
78
  hciId: getIntParameter("ble-hci-id"),
78
79
  }),
79
80
  );
@@ -20,17 +20,19 @@
20
20
  */
21
21
  // Include this first to auto-register Crypto, Network and Time Node.js implementations
22
22
  import {
23
- StorageBackendDisk,
23
+ Time,
24
24
  commandExecutor,
25
25
  getIntParameter,
26
26
  getParameter,
27
27
  hasParameter,
28
28
  requireMinNodeVersion,
29
- } from "@project-chip/matter.js-nodejs";
29
+ singleton,
30
+ } from "@project-chip/matter-node.js/util";
30
31
 
31
- import { BleNode } from "@project-chip/matter-node-ble.js/ble";
32
+ import { NodeJsBle } from "@project-chip/matter-node-ble.js/ble";
33
+ import { LogFormat, LogLevel, Logger } from "@project-chip/matter-node.js/log";
34
+ import { StorageBackendDisk, StorageManager } from "@project-chip/matter-node.js/storage";
32
35
  import { CommissioningServer, MatterServer } from "@project-chip/matter.js";
33
- import { LogFormat, LogLevel, Logger, StorageManager, Time, singleton } from "@project-chip/matter.js-general";
34
36
  import { Ble } from "@project-chip/matter.js/ble";
35
37
  import { DeviceTypeId, VendorId } from "@project-chip/matter.js/datatype";
36
38
  import { OnOffLightDevice, OnOffPluginUnitDevice, logEndpoint } from "@project-chip/matter.js/device";
@@ -72,7 +74,7 @@ if (hasParameter("ble")) {
72
74
  // Initialize Ble
73
75
  Ble.get = singleton(
74
76
  () =>
75
- new BleNode({
77
+ new NodeJsBle({
76
78
  hciId: getIntParameter("ble-hci-id"),
77
79
  }),
78
80
  );
@@ -5,9 +5,9 @@
5
5
  * SPDX-License-Identifier: Apache-2.0
6
6
  */
7
7
 
8
- import { StorageBackendDisk } from "@project-chip/matter.js-nodejs";
8
+ import { StorageBackendDisk } from "@project-chip/matter-node.js/storage";
9
9
 
10
- import { Time } from "@project-chip/matter.js-general";
10
+ import { Time } from "@project-chip/matter-node.js/util";
11
11
  import { Environment, StorageService } from "@project-chip/matter.js/environment";
12
12
  import { LocalStorage } from "node-localstorage";
13
13
 
@@ -22,17 +22,17 @@
22
22
  */
23
23
  // Include this first to auto-register Crypto, Network and Time Node.js implementations
24
24
  import {
25
- StorageBackendDisk,
26
25
  commandExecutor,
27
26
  getIntParameter,
28
27
  getParameter,
29
28
  hasParameter,
30
29
  requireMinNodeVersion,
31
- } from "@project-chip/matter.js-nodejs";
30
+ Time,
31
+ } from "@project-chip/matter-node.js/util";
32
32
 
33
+ import { LogFormat, Logger, LogLevel } from "@project-chip/matter-node.js/log";
34
+ import { StorageBackendDisk, StorageManager } from "@project-chip/matter-node.js/storage";
33
35
  import { CommissioningServer, MatterServer } from "@project-chip/matter.js";
34
-
35
- import { LogFormat, LogLevel, Logger, StorageManager, Time } from "@project-chip/matter.js-general";
36
36
  import { VendorId } from "@project-chip/matter.js/datatype";
37
37
  import { DeviceTypes, OnOffLightDevice, OnOffPluginUnitDevice } from "@project-chip/matter.js/device";
38
38
  import { QrCode } from "@project-chip/matter.js/schema";
@@ -4,14 +4,15 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import { getParameter } from "@project-chip/matter.js-nodejs";
7
+ import { getParameter } from "@project-chip/matter-node.js/util";
8
+ import { MatterDevice } from "@project-chip/matter.js";
8
9
  import {
9
10
  ClusterServer,
10
11
  ClusterServerObj,
11
12
  GeneralCommissioningCluster,
12
13
  NetworkCommissioning,
13
14
  } from "@project-chip/matter.js/cluster";
14
- import { Bytes } from "../../../../general/dist/cjs/index.js";
15
+ import { Bytes } from "@project-chip/matter.js/util";
15
16
 
16
17
  const firstNetworkId = new Uint8Array(32);
17
18
 
@@ -78,7 +79,7 @@ const Server: ClusterServerObj<typeof WifiNetworkCluster> = ClusterServer(
78
79
  `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(ssid)} ${Bytes.toHex(credentials)} ${breadcrumb}`,
79
80
  );
80
81
 
81
- session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
82
+ MatterDevice.of(session).assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
82
83
 
83
84
  // Simulate successful add or update
84
85
  if (breadcrumb !== undefined) {
@@ -105,7 +106,7 @@ const Server: ClusterServerObj<typeof WifiNetworkCluster> = ClusterServer(
105
106
  `---> removeNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,
106
107
  );
107
108
 
108
- session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
109
+ MatterDevice.of(session).assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
109
110
 
110
111
  // Simulate successful add or update
111
112
  if (breadcrumb !== undefined) {
@@ -132,7 +133,7 @@ const Server: ClusterServerObj<typeof WifiNetworkCluster> = ClusterServer(
132
133
  `---> connectNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,
133
134
  );
134
135
 
135
- session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
136
+ MatterDevice.of(session).assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
136
137
 
137
138
  // Simulate successful connection
138
139
  if (breadcrumb !== undefined) {
@@ -150,7 +151,7 @@ const Server: ClusterServerObj<typeof WifiNetworkCluster> = ClusterServer(
150
151
  lastConnectErrorValue?.setLocal(null);
151
152
 
152
153
  // Announce operational in IP network
153
- const device = session.context;
154
+ const device = MatterDevice.of(session);
154
155
  await device.startAnnouncement();
155
156
 
156
157
  return {
package/src/tsconfig.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
- "extends": "../../tools/tsconfig.base.json",
2
+ "extends": "../../../packages/tools/tsc/tsconfig.app.json",
3
3
  "compilerOptions": {
4
- "outDir": "../dist/esm",
5
- "types": ["node"],
6
-
7
- // See https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189
8
- // r.e. error TS2742
9
- // Probably referencing matter.js project directly would also solve but there's no reason for us to emit
10
- // declarations anyway
11
- "declaration": false,
12
- "composite": false,
13
- "declarationMap": false,
4
+ "types": [
5
+ "node"
6
+ ]
14
7
  },
15
- "references": [{ "path": "../../matter-node.js/src" }, { "path": "../../matter-node-ble.js/src" }]
16
- }
8
+ "references": [
9
+ {
10
+ "path": "../../matter-node-ble.js/src"
11
+ },
12
+ {
13
+ "path": "../../../packages/matter.js/src"
14
+ }
15
+ ]
16
+ }