@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,127 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * @license
4
- * Copyright 2022-2024 Matter.js Authors
5
- * SPDX-License-Identifier: Apache-2.0
6
- */
7
- import { requireMinNodeVersion } from "@project-chip/matter.js-nodejs";
8
- import { Time } from "@project-chip/matter.js-general";
9
- import { DeviceTypeId, VendorId } from "@project-chip/matter.js/datatype";
10
- import { logEndpoint } from "@project-chip/matter.js/device";
11
- import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
12
- import { OnOffPlugInUnitDevice } from "@project-chip/matter.js/devices/OnOffPlugInUnitDevice";
13
- import { Endpoint, EndpointServer } from "@project-chip/matter.js/endpoint";
14
- import { Environment, StorageService } from "@project-chip/matter.js/environment";
15
- import { ServerNode } from "@project-chip/matter.js/node";
16
- import { execSync } from "child_process";
17
- requireMinNodeVersion(16);
18
- async function main() {
19
- const {
20
- isSocket,
21
- deviceName,
22
- vendorName,
23
- passcode,
24
- discriminator,
25
- vendorId,
26
- productName,
27
- productId,
28
- port,
29
- uniqueId
30
- } = await getConfiguration();
31
- const server = await ServerNode.create({
32
- // Required: Give the Node a unique ID which is used to store the state of this node
33
- id: uniqueId,
34
- // Provide Network relevant configuration like the port
35
- // Optional when operating only one device on a host, Default port is 5540
36
- network: {
37
- port
38
- },
39
- // Provide Commissioning relevant settings
40
- // Optional for development/testing purposes
41
- commissioning: {
42
- passcode,
43
- discriminator
44
- },
45
- // Provide Node announcement settings
46
- // Optional: If Ommitted some development defaults are used
47
- productDescription: {
48
- name: deviceName,
49
- deviceType: DeviceTypeId(isSocket ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType)
50
- },
51
- // Provide defaults for the BasicInformation cluster on the Root endpoint
52
- // Optional: If Omitted some development defaults are used
53
- basicInformation: {
54
- vendorName,
55
- vendorId: VendorId(vendorId),
56
- nodeLabel: productName,
57
- productName,
58
- productLabel: productName,
59
- productId,
60
- serialNumber: `matterjs-${uniqueId}`,
61
- uniqueId
62
- }
63
- });
64
- const endpoint = new Endpoint(isSocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: "onoff" });
65
- await server.add(endpoint);
66
- endpoint.events.identify.startIdentifying.on(() => {
67
- console.log(`Run identify logic, ideally blink a light every 0.5s ...`);
68
- });
69
- endpoint.events.identify.stopIdentifying.on(() => {
70
- console.log(`Stop identify logic ...`);
71
- });
72
- endpoint.events.onOff.onOff$Changed.on((value) => {
73
- executeCommand(value ? "on" : "off");
74
- console.log(`OnOff is now ${value ? "ON" : "OFF"}`);
75
- });
76
- logEndpoint(EndpointServer.forEndpoint(server));
77
- await server.run();
78
- }
79
- main().catch((error) => console.error(error));
80
- function executeCommand(scriptParamName) {
81
- const script = Environment.default.vars.string(scriptParamName);
82
- if (script === void 0) return void 0;
83
- console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);
84
- }
85
- async function getConfiguration() {
86
- const environment = Environment.default;
87
- const storageService = environment.get(StorageService);
88
- console.log(`Storage location: ${storageService.location} (Directory)`);
89
- console.log(
90
- '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.'
91
- );
92
- const deviceStorage = (await storageService.open("device")).createContext("data");
93
- const isSocket = await deviceStorage.get("isSocket", environment.vars.get("type") === "socket");
94
- if (await deviceStorage.has("isSocket")) {
95
- console.log(`Device type ${isSocket ? "socket" : "light"} found in storage. --type parameter is ignored.`);
96
- }
97
- const deviceName = "Matter test device";
98
- const vendorName = "matter-node.js";
99
- const passcode = environment.vars.number("passcode") ?? await deviceStorage.get("passcode", 20202021);
100
- const discriminator = environment.vars.number("discriminator") ?? await deviceStorage.get("discriminator", 3840);
101
- const vendorId = environment.vars.number("vendorid") ?? await deviceStorage.get("vendorid", 65521);
102
- const productName = `node-matter OnOff ${isSocket ? "Socket" : "Light"}`;
103
- const productId = environment.vars.number("productid") ?? await deviceStorage.get("productid", 32768);
104
- const port = environment.vars.number("port") ?? 5540;
105
- const uniqueId = environment.vars.string("uniqueid") ?? (await deviceStorage.get("uniqueid", Time.nowMs())).toString();
106
- await deviceStorage.set({
107
- passcode,
108
- discriminator,
109
- vendorid: vendorId,
110
- productid: productId,
111
- isSocket,
112
- uniqueid: uniqueId
113
- });
114
- return {
115
- isSocket,
116
- deviceName,
117
- vendorName,
118
- passcode,
119
- discriminator,
120
- vendorId,
121
- productName,
122
- productId,
123
- port,
124
- uniqueId
125
- };
126
- }
127
- //# sourceMappingURL=DeviceNode.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/examples/DeviceNode.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 * 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 { requireMinNodeVersion } from \"@project-chip/matter.js-nodejs\";\n\nimport { Time } from \"@project-chip/matter.js-general\";\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 { 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,SAAS,6BAA6B;AAEtC,SAAS,YAAY;AACrB,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,gBAAgB;AAEzB,sBAAsB,EAAE;AAExB,eAAe,OAAO;AAElB,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,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ACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;",
6
- "names": []
7
- }
@@ -1,253 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * @license
4
- * Copyright 2022-2024 Matter.js Authors
5
- * SPDX-License-Identifier: Apache-2.0
6
- */
7
- import { createFileLogger, requireMinNodeVersion } from "@project-chip/matter.js-nodejs";
8
- import { BleNode } from "@project-chip/matter-node-ble.js/ble";
9
- import { LogLevel, Logger, Time, logLevelFromString, singleton } from "@project-chip/matter.js-general";
10
- import { NetworkCommissioningServer } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
11
- import { OnOffServer } from "@project-chip/matter.js/behavior/definitions/on-off";
12
- import { Ble } from "@project-chip/matter.js/ble";
13
- import { NetworkCommissioning } from "@project-chip/matter.js/cluster";
14
- import { DeviceTypeId, VendorId } from "@project-chip/matter.js/datatype";
15
- import { logEndpoint } from "@project-chip/matter.js/device";
16
- import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
17
- import { OnOffPlugInUnitDevice } from "@project-chip/matter.js/devices/OnOffPlugInUnitDevice";
18
- import { Endpoint, EndpointServer } from "@project-chip/matter.js/endpoint";
19
- import { RootRequirements } from "@project-chip/matter.js/endpoint/definitions";
20
- import { Environment, StorageService } from "@project-chip/matter.js/environment";
21
- import { FabricAction } from "@project-chip/matter.js/fabric";
22
- import { ServerNode } from "@project-chip/matter.js/node";
23
- import { QrCode } from "@project-chip/matter.js/schema";
24
- import { execSync } from "child_process";
25
- import { DummyThreadNetworkCommissioningServer } from "./cluster/DummyThreadNetworkCommissioningServer.js";
26
- import { DummyWifiNetworkCommissioningServer } from "./cluster/DummyWifiNetworkCommissioningServer.js";
27
- import {
28
- MyFancyOwnFunctionalityBehavior
29
- } from "./cluster/MyFancyOwnFunctionality.js";
30
- requireMinNodeVersion(16);
31
- const environment = Environment.default;
32
- if (environment.vars.get("ble.enable")) {
33
- Ble.get = singleton(
34
- () => new BleNode({
35
- hciId: environment.vars.number("ble.hciId")
36
- })
37
- );
38
- }
39
- function executeCommand(scriptParamName) {
40
- const script = environment.vars.string(scriptParamName);
41
- if (script === void 0) return void 0;
42
- console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);
43
- }
44
- const logFile = environment.vars.string("logfile.filename");
45
- if (logFile !== void 0) {
46
- Logger.addLogger("filelogger", await createFileLogger(logFile), {
47
- defaultLogLevel: logLevelFromString(environment.vars.string("logfile.loglevel")) ?? LogLevel.DEBUG
48
- });
49
- }
50
- const storageService = environment.get(StorageService);
51
- console.log(`Storage location: ${storageService.location} (Directory)`);
52
- console.log(
53
- '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.'
54
- );
55
- const deviceStorage = (await storageService.open("device")).createContext("data");
56
- if (await deviceStorage.has("isSocket")) {
57
- console.log("Device type found in storage. --type parameter is ignored.");
58
- }
59
- const isSocket = await deviceStorage.get("isSocket", environment.vars.string("type") === "socket");
60
- const deviceName = "Matter test device";
61
- const vendorName = "matter-node.js";
62
- const passcode = environment.vars.number("passcode") ?? await deviceStorage.get("passcode", 20202021);
63
- const discriminator = environment.vars.number("discriminator") ?? await deviceStorage.get("discriminator", 3840);
64
- const vendorId = environment.vars.number("vendorid") ?? await deviceStorage.get("vendorid", 65521);
65
- const productName = `node-matter OnOff ${isSocket ? "Socket" : "Light"}`;
66
- const productId = environment.vars.number("productid") ?? await deviceStorage.get("productid", 32768);
67
- const port = environment.vars.number("port") ?? 5540;
68
- const uniqueId = environment.vars.string("uniqueid") ?? await deviceStorage.get("uniqueid", Time.nowMs().toString());
69
- await deviceStorage.set({
70
- passcode,
71
- discriminator,
72
- vendorid: vendorId,
73
- productid: productId,
74
- isSocket,
75
- uniqueid: uniqueId
76
- });
77
- class OnOffShellExecServer extends OnOffServer {
78
- // Intercept the "on" command to the Matter On/Off cluster to print a log message.
79
- async on() {
80
- executeCommand("on");
81
- await super.on();
82
- }
83
- // This is the functional inverse of on() above.
84
- //
85
- // For demonstration purposes we update state ourselves rather than deferring to matter.js's default "off" handler
86
- // via super.off().
87
- async off() {
88
- executeCommand("off");
89
- this.state.onOff = false;
90
- }
91
- // Use event handlers to log on/off state reactively, after it changes.
92
- initialize() {
93
- this.events.onOff$Changed.on((value) => {
94
- console.log(`Light is now ${value ? "ON" : "OFF"}`);
95
- });
96
- }
97
- }
98
- class TestGeneralDiagnosticsServer extends RootRequirements.GeneralDiagnosticsServer {
99
- initialize() {
100
- this.state.testEventTriggersEnabled = true;
101
- super.initialize();
102
- }
103
- testEventTrigger({ enableKey, eventTrigger }) {
104
- console.log(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`);
105
- }
106
- }
107
- class MyFancyOwnFunctionalityServer extends MyFancyOwnFunctionalityBehavior {
108
- /** We return the incoming value and store the length of the string in our attribute and send it out as event */
109
- myFancyCommand(request) {
110
- const { value } = request;
111
- this.state.myFancyValue = value.length;
112
- this.events.myFancyEvent.emit({ eventValue: value }, this.context);
113
- return { response: value };
114
- }
115
- initialize() {
116
- this.state.myFancyValue = -1;
117
- }
118
- }
119
- const OnOffDevice = isSocket ? vendorId === 65524 ? OnOffPlugInUnitDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer) : OnOffPlugInUnitDevice.with(OnOffShellExecServer) : vendorId === 65524 ? OnOffLightDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer) : OnOffLightDevice.with(OnOffShellExecServer);
120
- let RootEndpoint = ServerNode.RootEndpoint.with(TestGeneralDiagnosticsServer);
121
- let wifiOrThreadAdded = false;
122
- let threadAdded = false;
123
- if (Ble.enabled) {
124
- if (environment.vars.has("ble.wifi.fake")) {
125
- RootEndpoint = RootEndpoint.with(DummyWifiNetworkCommissioningServer);
126
- wifiOrThreadAdded = true;
127
- } else if (environment.vars.has("ble.thread.fake")) {
128
- RootEndpoint = RootEndpoint.with(DummyThreadNetworkCommissioningServer);
129
- wifiOrThreadAdded = true;
130
- threadAdded = true;
131
- }
132
- } else {
133
- RootEndpoint = RootEndpoint.with(
134
- NetworkCommissioningServer.with(NetworkCommissioning.Feature.EthernetNetworkInterface)
135
- );
136
- }
137
- const networkId = new Uint8Array(32);
138
- const server = await ServerNode.create(RootEndpoint, {
139
- id: uniqueId,
140
- network: {
141
- port,
142
- discoveryCapabilities: {
143
- onIpNetwork: !environment.vars.has("ble.enable"),
144
- ble: environment.vars.has("ble.enable")
145
- },
146
- ble: environment.vars.has("ble.enable")
147
- // TODO remove when state init is fixed
148
- },
149
- commissioning: {
150
- passcode,
151
- discriminator
152
- },
153
- productDescription: {
154
- name: deviceName,
155
- deviceType: DeviceTypeId(OnOffDevice.deviceType)
156
- },
157
- basicInformation: {
158
- vendorName,
159
- vendorId: VendorId(vendorId),
160
- nodeLabel: productName,
161
- productName,
162
- productLabel: productName,
163
- productId,
164
- serialNumber: `node-matter-${uniqueId}`,
165
- uniqueId
166
- },
167
- // @ts-expect-error ... TS do not see the types because both next clusters was added conditionally
168
- networkCommissioning: {
169
- maxNetworks: 1,
170
- interfaceEnabled: true,
171
- lastConnectErrorValue: 0,
172
- lastNetworkId: wifiOrThreadAdded ? null : networkId,
173
- lastNetworkingStatus: wifiOrThreadAdded ? null : NetworkCommissioning.NetworkCommissioningStatus.Success,
174
- networks: [{ networkId, connected: !wifiOrThreadAdded }],
175
- scanMaxTimeSeconds: wifiOrThreadAdded ? 3 : void 0,
176
- connectMaxTimeSeconds: wifiOrThreadAdded ? 3 : void 0,
177
- supportedWifiBands: wifiOrThreadAdded && !threadAdded ? [NetworkCommissioning.WiFiBand["2G4"]] : void 0,
178
- supportedThreadFeatures: wifiOrThreadAdded && threadAdded ? { isFullThreadDevice: true } : void 0,
179
- threadVersion: wifiOrThreadAdded && threadAdded ? 4 : void 0
180
- // means: Thread 1.3
181
- },
182
- myFancyFunctionality: {
183
- myFancyValue: 0
184
- }
185
- });
186
- const endpoint = new Endpoint(OnOffDevice, { id: "onoff" });
187
- await server.add(endpoint);
188
- server.lifecycle.commissioned.on(() => console.log("Server was initially commissioned successfully!"));
189
- server.lifecycle.decommissioned.on(() => console.log("Server was fully decommissioned successfully!"));
190
- server.lifecycle.online.on(() => console.log("Server is online"));
191
- server.lifecycle.offline.on(() => console.log("Server is offline"));
192
- server.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {
193
- let action = "";
194
- switch (fabricAction) {
195
- case FabricAction.Added:
196
- action = "added";
197
- break;
198
- case FabricAction.Removed:
199
- action = "removed";
200
- break;
201
- case FabricAction.Updated:
202
- action = "updated";
203
- break;
204
- }
205
- console.log(`Commissioned Fabrics changed event (${action}) for ${fabricIndex} triggered`);
206
- console.log(server.state.commissioning.fabrics[fabricIndex]);
207
- });
208
- server.events.sessions.opened.on((session) => console.log(`Session opened`, session));
209
- server.events.sessions.closed.on((session) => console.log(`Session closed`, session));
210
- server.events.sessions.subscriptionsChanged.on((session) => {
211
- console.log(`Session subscriptions changed`, session);
212
- console.log(`Status of all sessions`, server.state.sessions.sessions);
213
- });
214
- endpoint.events.identify.startIdentifying.on(() => {
215
- console.log(`Run identify logic, ideally blink a light every 0.5s ...`);
216
- });
217
- endpoint.events.identify.stopIdentifying.on(() => {
218
- console.log(`Stop identify logic ...`);
219
- });
220
- logEndpoint(EndpointServer.forEndpoint(server));
221
- await server.start();
222
- console.log("Initial Fabrics", server.state.operationalCredentials.fabrics);
223
- if (!server.lifecycle.isCommissioned) {
224
- const { qrPairingCode, manualPairingCode } = server.state.commissioning.pairingCodes;
225
- console.log(QrCode.get(qrPairingCode));
226
- console.log(`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`);
227
- console.log(`Manual pairing code: ${manualPairingCode}`);
228
- } else {
229
- console.log("Device is already commissioned. Waiting for controllers to connect ...");
230
- const onOffValue = endpoint.state.onOff.onOff;
231
- console.log(`current OnOff attribute: ${onOffValue}`);
232
- if (vendorId === 65524) {
233
- await endpoint.set({
234
- onOff: {
235
- onOff: !onOffValue
236
- },
237
- // @ts-expect-error Needed because the Fancy cluster is added conditionally, so TS do not get that it's there.
238
- myFancyOwnFunctionality: {
239
- myFancyValue: 36
240
- }
241
- });
242
- } else {
243
- await endpoint.set({
244
- onOff: {
245
- onOff: !onOffValue
246
- }
247
- });
248
- }
249
- }
250
- process.on("SIGINT", () => {
251
- server.close().then(() => process.exit(0)).catch((err) => console.error(err));
252
- });
253
- //# sourceMappingURL=DeviceNodeFull.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/examples/DeviceNodeFull.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 * 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 { createFileLogger, requireMinNodeVersion } from \"@project-chip/matter.js-nodejs\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { LogLevel, Logger, Time, logLevelFromString, singleton } from \"@project-chip/matter.js-general\";\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 { GeneralDiagnostics, 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 { ServerNode } from \"@project-chip/matter.js/node\";\nimport { QrCode } from \"@project-chip/matter.js/schema\";\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: logLevelFromString(environment.vars.string(\"logfile.loglevel\")) ?? LogLevel.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;\nlet threadAdded = 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 threadAdded = true;\n }\n} else {\n RootEndpoint = RootEndpoint.with(\n NetworkCommissioningServer.with(NetworkCommissioning.Feature.EthernetNetworkInterface),\n );\n}\n\nconst networkId = new Uint8Array(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 supportedWifiBands: wifiOrThreadAdded && !threadAdded ? [NetworkCommissioning.WiFiBand[\"2G4\"]] : undefined,\n supportedThreadFeatures: wifiOrThreadAdded && threadAdded ? { isFullThreadDevice: true } : undefined,\n threadVersion: wifiOrThreadAdded && threadAdded ? 4 : undefined, // means: Thread 1.3\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.start();\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 server we can use server.close().\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,SAAS,kBAAkB,6BAA6B;AAExD,SAAS,eAAe;AACxB,SAAS,UAAU,QAAQ,MAAM,oBAAoB,iBAAiB;AACtE,SAAS,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,WAAW;AACpB,SAA6B,4BAA4B;AACzD,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,kBAAkB;AAC3B,SAAS,cAAc;AACvB,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;AAAA,IAC9C,CAAC;AAAA,EACT;AACJ;AAEA,SAAS,eAAe,iBAAyB;AAC7C,QAAM,SAAS,YAAY,KAAK,OAAO,eAAe;AACtD,MAAI,WAAW,OAAW,QAAO;AACjC,UAAQ,IAAI,GAAG,eAAe,KAAK,SAAS,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC,EAAE;AACjF;AAYA,MAAM,UAAU,YAAY,KAAK,OAAO,kBAAkB;AAC1D,IAAI,YAAY,QAAW;AACvB,SAAO,UAAU,cAAc,MAAM,iBAAiB,OAAO,GAAG;AAAA,IAC5D,iBAAiB,mBAAmB,YAAY,KAAK,OAAO,kBAAkB,CAAC,KAAK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,MAAM;AAEnB,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;",
6
- "names": []
7
- }
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * @license
4
- * Copyright 2022-2024 Matter.js Authors
5
- * SPDX-License-Identifier: Apache-2.0
6
- */
7
- import "@project-chip/matter.js-nodejs";
8
- import {
9
- MovementDirection,
10
- WindowCoveringServer
11
- } from "@project-chip/matter.js/behaviors/window-covering";
12
- import { OnOffLightDevice, OnOffLightRequirements } from "@project-chip/matter.js/devices/OnOffLightDevice";
13
- import { WindowCoveringDevice } from "@project-chip/matter.js/devices/WindowCoveringDevice";
14
- import { ServerNode } from "@project-chip/matter.js/node";
15
- const LiftingWindowCoveringServer = WindowCoveringServer.with("Lift", "AbsolutePosition", "PositionAwareLift");
16
- class RollerShade extends LiftingWindowCoveringServer {
17
- async handleMovement(type, reversed, direction, targetPercent100ths) {
18
- console.log(
19
- "Move window shade",
20
- direction === MovementDirection.Open ? "Open" : "Close",
21
- targetPercent100ths !== void 0 ? `${targetPercent100ths / 100}%` : ""
22
- );
23
- await super.handleMovement(type, reversed, direction, targetPercent100ths);
24
- }
25
- }
26
- class ValanceLight extends OnOffLightRequirements.OnOffServer {
27
- initialize() {
28
- this.reactTo(this.events.onOff$Changed, this.#stateChanged);
29
- }
30
- #stateChanged(value) {
31
- console.log(`Valance is now ${value ? "illuminated" : "dark"}`);
32
- }
33
- }
34
- const node = new ServerNode({
35
- id: "excelsior1000",
36
- productDescription: {},
37
- commissioning: {
38
- passcode: 20202021,
39
- discriminator: 3840
40
- },
41
- basicInformation: {
42
- vendorName: "Acme Corporation",
43
- productName: "Excelsior 1000 EZ-Nite\u2122",
44
- vendorId: 65521,
45
- productId: 32768,
46
- serialNumber: "1234-12345-123"
47
- },
48
- parts: [
49
- {
50
- type: WindowCoveringDevice.with(RollerShade),
51
- id: "shade"
52
- },
53
- {
54
- type: OnOffLightDevice.with(ValanceLight),
55
- id: "valance"
56
- }
57
- ]
58
- });
59
- await node.run();
60
- //# sourceMappingURL=IlluminatedRollerShade.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/examples/IlluminatedRollerShade.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// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport \"@project-chip/matter.js-nodejs\";\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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- */
7
- import "@project-chip/matter.js-nodejs";
8
- import { OnOffLightDevice, OnOffLightRequirements } from "@project-chip/matter.js/devices/OnOffLightDevice";
9
- import { ServerNode } from "@project-chip/matter.js/node";
10
- class ReportingOnOffServer extends OnOffLightRequirements.OnOffServer {
11
- // Intercept the "on" command to the Matter On/Off cluster to print a log message.
12
- async on() {
13
- console.log("Turning light ON");
14
- await super.on();
15
- }
16
- // This is the functional inverse of on() above.
17
- //
18
- // For demonstration purposes we update state ourselves rather than deferring to matter.js's default "off" handler
19
- // via super.off().
20
- off() {
21
- console.log("Turning light OFF");
22
- this.state.onOff = false;
23
- }
24
- // Use event handlers to log on/off state reactively, after it changes.
25
- initialize() {
26
- this.events.onOff$Changed.on((value) => {
27
- console.log(`Light is now ${value ? "ON" : "OFF"}`);
28
- });
29
- }
30
- }
31
- const ExampleLight = OnOffLightDevice.with(ReportingOnOffServer);
32
- const node = await ServerNode.create();
33
- await node.add(ExampleLight);
34
- await node.run();
35
- //# sourceMappingURL=LightDevice.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/examples/LightDevice.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// 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.js-nodejs\";\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
- "names": []
7
- }