@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,140 +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
- const devices = await getConfiguration();
19
- for (let idx = 1; idx < devices.length; idx++) {
20
- const {
21
- isSocket,
22
- deviceName,
23
- vendorName,
24
- passcode,
25
- discriminator,
26
- vendorId,
27
- productName,
28
- productId,
29
- port,
30
- uniqueId
31
- } = devices[idx];
32
- const i = idx + 1;
33
- const server = await ServerNode.create({
34
- // Required: Give the Node a unique ID which is used to store the state of this node
35
- id: uniqueId,
36
- // Provide Network relevant configuration like the port
37
- // Optional when operating only one device on a host, Default port is 5540
38
- network: {
39
- port
40
- },
41
- // Provide Commissioning relevant settings
42
- // Optional for development/testing purposes
43
- commissioning: {
44
- passcode,
45
- discriminator
46
- },
47
- // Provide Node announcement settings
48
- // Optional: If Ommitted some development defaults are used
49
- productDescription: {
50
- name: deviceName,
51
- deviceType: DeviceTypeId(isSocket ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType)
52
- },
53
- // Provide defaults for the BasicInformation cluster on the Root endpoint
54
- // Optional: If Omitted some development defaults are used
55
- basicInformation: {
56
- vendorName,
57
- vendorId: VendorId(vendorId),
58
- nodeLabel: productName,
59
- productName,
60
- productLabel: productName,
61
- productId,
62
- serialNumber: `matterjs-${uniqueId}`,
63
- uniqueId
64
- }
65
- });
66
- console.log(
67
- `Added device ${i} on port ${port} and unique id ${uniqueId}: Passcode: ${passcode}, Discriminator: ${discriminator}`
68
- );
69
- const endpoint = new Endpoint(isSocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: "onoff" });
70
- await server.add(endpoint);
71
- endpoint.events.identify.startIdentifying.on(() => {
72
- console.log(`Run identify logic for device ${i}, ideally blink a light every 0.5s ...`);
73
- });
74
- endpoint.events.identify.stopIdentifying.on(() => {
75
- console.log(`Stop identify logic for device ${i}...`);
76
- });
77
- endpoint.events.onOff.onOff$Changed.on((value) => {
78
- executeCommand(value ? `on${i}` : `off${i}`);
79
- console.log(`OnOff ${i} is now ${value ? "ON" : "OFF"}`);
80
- });
81
- logEndpoint(EndpointServer.forEndpoint(server));
82
- console.log("----------------------------");
83
- console.log(`QR Code for Device ${i} on port ${port}:`);
84
- console.log("----------------------------");
85
- await server.start();
86
- }
87
- function executeCommand(scriptParamName) {
88
- const script = Environment.default.vars.string(scriptParamName);
89
- if (script === void 0) return void 0;
90
- console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);
91
- }
92
- async function getConfiguration() {
93
- const environment = Environment.default;
94
- const storageService = environment.get(StorageService);
95
- console.log(`Storage location: ${storageService.location} (Directory)`);
96
- console.log(
97
- '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.'
98
- );
99
- const deviceStorage = (await storageService.open("device")).createContext("data");
100
- let defaultPasscode = 20202021;
101
- let defaultDiscriminator = 3840;
102
- let defaultPort = 5550;
103
- const devices2 = [];
104
- const numDevices = environment.vars.number("num") ?? 2;
105
- for (let i = 1; i <= numDevices; i++) {
106
- const isSocket = await deviceStorage.get(`isSocket${i}`, environment.vars.string(`type${i}`) === "socket");
107
- if (await deviceStorage.has(`isSocket${i}`)) {
108
- console.log(`Device type ${isSocket ? "socket" : "light"} found in storage. --type parameter is ignored.`);
109
- }
110
- const deviceName = `Matter ${environment.vars.string(`type${i}`) ?? "light"} device ${i}`;
111
- const vendorName = "matter-node.js";
112
- const passcode = environment.vars.number(`passcode${i}`) ?? await deviceStorage.get(`passcode${i}`, defaultPasscode++);
113
- const discriminator = environment.vars.number(`discriminator${i}`) ?? await deviceStorage.get(`discriminator${i}`, defaultDiscriminator++);
114
- const vendorId = environment.vars.number(`vendorid${i}`) ?? await deviceStorage.get(`vendorid${i}`, 65521);
115
- const productName = `node-matter OnOff-Device ${i}`;
116
- const productId = environment.vars.number(`productid${i}`) ?? await deviceStorage.get(`productid${i}`, 32768);
117
- const port = environment.vars.number(`port${i}`) ?? defaultPort++;
118
- const uniqueId = environment.vars.string(`uniqueid${i}`) ?? await deviceStorage.get(`uniqueid${i}`, `${i}-${Time.nowMs()}`);
119
- await deviceStorage.set(`passcode${i}`, passcode);
120
- await deviceStorage.set(`discriminator${i}`, discriminator);
121
- await deviceStorage.set(`vendorid${i}`, vendorId);
122
- await deviceStorage.set(`productid${i}`, productId);
123
- await deviceStorage.set(`isSocket${i}`, isSocket);
124
- await deviceStorage.set(`uniqueid${i}`, uniqueId);
125
- devices2.push({
126
- isSocket,
127
- deviceName,
128
- vendorName,
129
- passcode,
130
- discriminator,
131
- vendorId,
132
- productName,
133
- productId,
134
- port,
135
- uniqueId
136
- });
137
- }
138
- return devices2;
139
- }
140
- //# sourceMappingURL=MultiDeviceNode.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/examples/MultiDeviceNode.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 new device node that is composed of multiple devices.\n * It creates multiple endpoints on the server. For information on how to add a composed device to a bridge please\n * refer to the bridge example!\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport { 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\nconst devices = await getConfiguration();\nfor (let idx = 1; idx < devices.length; idx++) {\n const {\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n } = devices[idx];\n const i = idx + 1;\n\n /**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\n const server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(isSocket ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType),\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n });\n\n console.log(\n `Added device ${i} on port ${port} and unique id ${uniqueId}: Passcode: ${passcode}, Discriminator: ${discriminator}`,\n );\n\n const endpoint = new Endpoint(isSocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: \"onoff\" });\n await server.add(endpoint);\n\n /**\n * Register state change handlers of the node for identify and onoff states to react to the commands.\n * If the code in these change handlers fail then the change is also rolled back and not executed and an error is\n * reported back to the controller.\n */\n endpoint.events.identify.startIdentifying.on(() => {\n console.log(`Run identify logic for device ${i}, ideally blink a light every 0.5s ...`);\n });\n\n endpoint.events.identify.stopIdentifying.on(() => {\n console.log(`Stop identify logic for device ${i}...`);\n });\n\n endpoint.events.onOff.onOff$Changed.on(value => {\n executeCommand(value ? `on${i}` : `off${i}`);\n console.log(`OnOff ${i} is now ${value ? \"ON\" : \"OFF\"}`);\n });\n\n /**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\n logEndpoint(EndpointServer.forEndpoint(server));\n\n console.log(\"----------------------------\");\n console.log(`QR Code for Device ${i} on port ${port}:`);\n console.log(\"----------------------------\");\n\n /**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\n await server.start();\n}\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/**\n * Defines a shell command from an environment variable and execute it and log the response\n */\nfunction executeCommand(scriptParamName: string) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) return undefined;\n console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);\n}\n\nasync function getConfiguration() {\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n let defaultPasscode = 20202021;\n let defaultDiscriminator = 3840;\n let defaultPort = 5550;\n\n const devices = [];\n const numDevices = environment.vars.number(\"num\") ?? 2;\n for (let i = 1; i <= numDevices; i++) {\n const isSocket = await deviceStorage.get(`isSocket${i}`, environment.vars.string(`type${i}`) === \"socket\");\n if (await deviceStorage.has(`isSocket${i}`)) {\n console.log(`Device type ${isSocket ? \"socket\" : \"light\"} found in storage. --type parameter is ignored.`);\n }\n const deviceName = `Matter ${environment.vars.string(`type${i}`) ?? \"light\"} device ${i}`;\n const vendorName = \"matter-node.js\";\n const passcode =\n environment.vars.number(`passcode${i}`) ?? (await deviceStorage.get(`passcode${i}`, defaultPasscode++));\n const discriminator =\n environment.vars.number(`discriminator${i}`) ??\n (await deviceStorage.get(`discriminator${i}`, defaultDiscriminator++));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(`vendorid${i}`) ?? (await deviceStorage.get(`vendorid${i}`, 0xfff1));\n const productName = `node-matter OnOff-Device ${i}`;\n const productId =\n environment.vars.number(`productid${i}`) ?? (await deviceStorage.get(`productid${i}`, 0x8000));\n\n const port = environment.vars.number(`port${i}`) ?? defaultPort++;\n\n const uniqueId =\n environment.vars.string(`uniqueid${i}`) ??\n (await deviceStorage.get(`uniqueid${i}`, `${i}-${Time.nowMs()}`));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set(`passcode${i}`, passcode);\n await deviceStorage.set(`discriminator${i}`, discriminator);\n await deviceStorage.set(`vendorid${i}`, vendorId);\n await deviceStorage.set(`productid${i}`, productId);\n await deviceStorage.set(`isSocket${i}`, isSocket);\n await deviceStorage.set(`uniqueid${i}`, uniqueId);\n\n devices.push({\n isSocket,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n });\n }\n\n return devices;\n}\n"],
5
- "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAiBA,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,MAAM,UAAU,MAAM,iBAAiB;AACvC,SAAS,MAAM,GAAG,MAAM,QAAQ,QAAQ,OAAO;AAC3C,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI,QAAQ,GAAG;AACf,QAAM,IAAI,MAAM;AAKhB,QAAM,SAAS,MAAM,WAAW,OAAO;AAAA;AAAA,IAEnC,IAAI;AAAA;AAAA;AAAA,IAIJ,SAAS;AAAA,MACL;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,eAAe;AAAA,MACX;AAAA,MACA;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,oBAAoB;AAAA,MAChB,MAAM;AAAA,MACN,YAAY,aAAa,WAAW,sBAAsB,aAAa,iBAAiB,UAAU;AAAA,IACtG;AAAA;AAAA;AAA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WAAW,CAAC,EAAE,KACrC,MAAM,cAAc,IAAI,WAAW,CAAC,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,EAAE;AAGnE,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAChD,UAAM,cAAc,IAAI,gBAAgB,CAAC,IAAI,aAAa;AAC1D,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAChD,UAAM,cAAc,IAAI,YAAY,CAAC,IAAI,SAAS;AAClD,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAChD,UAAM,cAAc,IAAI,WAAW,CAAC,IAAI,QAAQ;AAEhD,IAAAA,SAAQ,KAAK;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAOA;AACX;",
6
- "names": ["devices"]
7
- }
@@ -1,175 +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 { HumiditySensorDevice } from "@project-chip/matter.js/devices/HumiditySensorDevice";
12
- import { TemperatureSensorDevice } from "@project-chip/matter.js/devices/TemperatureSensorDevice";
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
- isTemperature,
21
- interval,
22
- deviceName,
23
- vendorName,
24
- passcode,
25
- discriminator,
26
- vendorId,
27
- productName,
28
- productId,
29
- port,
30
- uniqueId
31
- } = await getConfiguration();
32
- const server = await ServerNode.create({
33
- // Required: Give the Node a unique ID which is used to store the state of this node
34
- id: uniqueId,
35
- // Provide Network relevant configuration like the port
36
- // Optional when operating only one device on a host, Default port is 5540
37
- network: {
38
- port
39
- },
40
- // Provide Commissioning relevant settings
41
- // Optional for development/testing purposes
42
- commissioning: {
43
- passcode,
44
- discriminator
45
- },
46
- // Provide Node announcement settings
47
- // Optional: If Ommitted some development defaults are used
48
- productDescription: {
49
- name: deviceName,
50
- deviceType: DeviceTypeId(
51
- isTemperature ? TemperatureSensorDevice.deviceType : HumiditySensorDevice.deviceType
52
- )
53
- },
54
- // Provide defaults for the BasicInformation cluster on the Root endpoint
55
- // Optional: If Omitted some development defaults are used
56
- basicInformation: {
57
- vendorName,
58
- vendorId: VendorId(vendorId),
59
- nodeLabel: productName,
60
- productName,
61
- productLabel: productName,
62
- productId,
63
- serialNumber: `matterjs-${uniqueId}`,
64
- uniqueId
65
- }
66
- });
67
- let endpoint;
68
- if (isTemperature) {
69
- endpoint = new Endpoint(TemperatureSensorDevice, {
70
- id: "tempsensor",
71
- temperatureMeasurement: {
72
- // Use this to initialize the measuredValue with the most uptodate value.
73
- // If you do not know the value and also cannot request it, best use "null" (if allowed by the cluster).
74
- measuredValue: getIntValueFromCommandOrRandom("value")
75
- }
76
- });
77
- } else {
78
- endpoint = new Endpoint(HumiditySensorDevice, {
79
- id: "humsensor",
80
- relativeHumidityMeasurement: {
81
- // Use this to initialize the measuredValue with the most uptodate value.
82
- // If you do not know the value and also cannot request it, best use "null" (if allowed by the cluster).
83
- measuredValue: getIntValueFromCommandOrRandom("value", false)
84
- }
85
- });
86
- }
87
- await server.add(endpoint);
88
- logEndpoint(EndpointServer.forEndpoint(server));
89
- const updateInterval = setInterval(() => {
90
- let setter;
91
- if (isTemperature) {
92
- setter = endpoint.set({
93
- temperatureMeasurement: {
94
- measuredValue: getIntValueFromCommandOrRandom("value")
95
- }
96
- });
97
- } else {
98
- setter = endpoint.set({
99
- relativeHumidityMeasurement: {
100
- measuredValue: getIntValueFromCommandOrRandom("value", false)
101
- }
102
- });
103
- }
104
- setter.catch((error) => console.error("Error updating measured value:", error));
105
- }, interval * 1e3);
106
- server.lifecycle.offline.on(() => clearTimeout(updateInterval));
107
- await server.run();
108
- }
109
- main().catch((error) => console.error(error));
110
- function getIntValueFromCommandOrRandom(scriptParamName, allowNegativeValues = true) {
111
- const script = Environment.default.vars.string(scriptParamName);
112
- if (script === void 0) {
113
- if (!allowNegativeValues) return Math.round(Math.random() * 100);
114
- return (Math.round(Math.random() * 100) - 50) * 100;
115
- }
116
- let result = execSync(script).toString().trim();
117
- if (result.startsWith("'") && result.endsWith("'") || result.startsWith('"') && result.endsWith('"'))
118
- result = result.slice(1, -1);
119
- console.log(`Command result: ${result}`);
120
- let value = Math.round(parseFloat(result));
121
- if (!allowNegativeValues && value < 0) value = 0;
122
- return value;
123
- }
124
- async function getConfiguration() {
125
- const environment = Environment.default;
126
- const storageService = environment.get(StorageService);
127
- console.log(`Storage location: ${storageService.location} (Directory)`);
128
- console.log(
129
- '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.'
130
- );
131
- const deviceStorage = (await storageService.open("device")).createContext("data");
132
- const isTemperature = await deviceStorage.get("isTemperature", environment.vars.get("type") !== "humidity");
133
- if (await deviceStorage.has("isTemperature")) {
134
- console.log(
135
- `Device type ${isTemperature ? "temperature" : "humidity"} found in storage. --type parameter is ignored.`
136
- );
137
- }
138
- let interval = environment.vars.number("interval") ?? await deviceStorage.get("interval", 60);
139
- if (interval < 1) {
140
- console.log(`Invalid Interval ${interval}, set to 60s`);
141
- interval = 60;
142
- }
143
- const deviceName = "Matter test device";
144
- const vendorName = "matter-node.js";
145
- const passcode = environment.vars.number("passcode") ?? await deviceStorage.get("passcode", 20202021);
146
- const discriminator = environment.vars.number("discriminator") ?? await deviceStorage.get("discriminator", 3840);
147
- const vendorId = environment.vars.number("vendorid") ?? await deviceStorage.get("vendorid", 65521);
148
- const productName = `node-matter OnOff ${isTemperature ? "Temperature" : "Humidity"}`;
149
- const productId = environment.vars.number("productid") ?? await deviceStorage.get("productid", 32768);
150
- const port = environment.vars.number("port") ?? 5540;
151
- const uniqueId = environment.vars.string("uniqueid") ?? await deviceStorage.get("uniqueid", Time.nowMs().toString());
152
- await deviceStorage.set({
153
- passcode,
154
- discriminator,
155
- vendorid: vendorId,
156
- productid: productId,
157
- interval,
158
- isTemperature,
159
- uniqueid: uniqueId
160
- });
161
- return {
162
- isTemperature,
163
- interval,
164
- deviceName,
165
- vendorName,
166
- passcode,
167
- discriminator,
168
- vendorId,
169
- productName,
170
- productId,
171
- port,
172
- uniqueId
173
- };
174
- }
175
- //# sourceMappingURL=SensorDeviceNode.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/examples/SensorDeviceNode.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 Sensor Matter device as temperature or humidity device.\n * It can be used as CLI script and starting point for your own device node implementation.\n * This example is CJS conform and do not use top level await's.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport { 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 { HumiditySensorDevice } from \"@project-chip/matter.js/devices/HumiditySensorDevice\";\nimport { TemperatureSensorDevice } from \"@project-chip/matter.js/devices/TemperatureSensorDevice\";\nimport { Endpoint, EndpointServer } from \"@project-chip/matter.js/endpoint\";\nimport { Environment, StorageService } from \"@project-chip/matter.js/environment\";\nimport { ServerNode } from \"@project-chip/matter.js/node\";\nimport { execSync } from \"child_process\";\n\nrequireMinNodeVersion(16);\n\nasync function main() {\n /** Initialize configuration values */\n const {\n isTemperature,\n interval,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n uniqueId,\n } = await getConfiguration();\n\n /**\n * Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration\n */\n const server = await ServerNode.create({\n // Required: Give the Node a unique ID which is used to store the state of this node\n id: uniqueId,\n\n // Provide Network relevant configuration like the port\n // Optional when operating only one device on a host, Default port is 5540\n network: {\n port,\n },\n\n // Provide Commissioning relevant settings\n // Optional for development/testing purposes\n commissioning: {\n passcode,\n discriminator,\n },\n\n // Provide Node announcement settings\n // Optional: If Ommitted some development defaults are used\n productDescription: {\n name: deviceName,\n deviceType: DeviceTypeId(\n isTemperature ? TemperatureSensorDevice.deviceType : HumiditySensorDevice.deviceType,\n ),\n },\n\n // Provide defaults for the BasicInformation cluster on the Root endpoint\n // Optional: If Omitted some development defaults are used\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `matterjs-${uniqueId}`,\n uniqueId,\n },\n });\n\n /**\n * Matter Nodes are a composition of endpoints. Create and add a single endpoint to the node. This example uses the\n * OnOffLightDevice or OnOffPlugInUnitDevice depending on the value of the type parameter. It also assigns this Part a\n * unique ID to store the endpoint number for it in the storage to restore the device on restart.\n * In this case we directly use the default command implementation from matter.js. Check out the DeviceNodeFull example\n * to see how to customize the command handlers.\n */\n let endpoint: Endpoint<TemperatureSensorDevice | HumiditySensorDevice>;\n if (isTemperature) {\n endpoint = new Endpoint(TemperatureSensorDevice, {\n id: \"tempsensor\",\n temperatureMeasurement: {\n // Use this to initialize the measuredValue with the most uptodate value.\n // If you do not know the value and also cannot request it, best use \"null\" (if allowed by the cluster).\n measuredValue: getIntValueFromCommandOrRandom(\"value\"),\n },\n });\n } else {\n endpoint = new Endpoint(HumiditySensorDevice, {\n id: \"humsensor\",\n relativeHumidityMeasurement: {\n // Use this to initialize the measuredValue with the most uptodate value.\n // If you do not know the value and also cannot request it, best use \"null\" (if allowed by the cluster).\n measuredValue: getIntValueFromCommandOrRandom(\"value\", false),\n },\n });\n }\n\n await server.add(endpoint);\n\n /**\n * Log the endpoint structure for debugging reasons and to allow to verify anything is correct\n */\n logEndpoint(EndpointServer.forEndpoint(server));\n\n const updateInterval = setInterval(() => {\n let setter: Promise<void>;\n if (isTemperature) {\n setter = endpoint.set({\n temperatureMeasurement: {\n measuredValue: getIntValueFromCommandOrRandom(\"value\"),\n },\n });\n } else {\n setter = endpoint.set({\n relativeHumidityMeasurement: {\n measuredValue: getIntValueFromCommandOrRandom(\"value\", false),\n },\n });\n }\n setter.catch(error => console.error(\"Error updating measured value:\", error));\n }, interval * 1000);\n\n // Cleanup our update interval when node goes offline\n server.lifecycle.offline.on(() => clearTimeout(updateInterval));\n\n /**\n * In order to start the node and announce it into the network we use the run method which resolves when the node goes\n * offline again because we do not need anything more here. See the Full example for other starting options.\n * The QR Code is printed automatically.\n */\n await server.run();\n}\n\nmain().catch(error => console.error(error));\n\n/*********************************************************************************************************\n * Convenience Methods\n *********************************************************************************************************/\n\n/** Defined a shell command from an environment variable and execute it and log the response. */\n\nfunction getIntValueFromCommandOrRandom(scriptParamName: string, allowNegativeValues = true) {\n const script = Environment.default.vars.string(scriptParamName);\n if (script === undefined) {\n if (!allowNegativeValues) return Math.round(Math.random() * 100);\n return (Math.round(Math.random() * 100) - 50) * 100;\n }\n let result = execSync(script).toString().trim();\n if ((result.startsWith(\"'\") && result.endsWith(\"'\")) || (result.startsWith('\"') && result.endsWith('\"')))\n result = result.slice(1, -1);\n console.log(`Command result: ${result}`);\n let value = Math.round(parseFloat(result));\n if (!allowNegativeValues && value < 0) value = 0;\n return value;\n}\n\nasync function getConfiguration() {\n /**\n * Collect all needed data\n *\n * This block collects all needed data from cli, environment or storage. Replace this with where ever your data come from.\n *\n * Note: This example uses the matter.js process storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own storage contexts\n * (so maybe better not do it ;-)).\n */\n const environment = Environment.default;\n\n const storageService = environment.get(StorageService);\n console.log(`Storage location: ${storageService.location} (Directory)`);\n console.log(\n 'Use the parameter \"--storage-path=NAME-OR-PATH\" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.',\n );\n const deviceStorage = (await storageService.open(\"device\")).createContext(\"data\");\n\n const isTemperature = await deviceStorage.get(\"isTemperature\", environment.vars.get(\"type\") !== \"humidity\");\n if (await deviceStorage.has(\"isTemperature\")) {\n console.log(\n `Device type ${isTemperature ? \"temperature\" : \"humidity\"} found in storage. --type parameter is ignored.`,\n );\n }\n let interval = environment.vars.number(\"interval\") ?? (await deviceStorage.get(\"interval\", 60));\n if (interval < 1) {\n console.log(`Invalid Interval ${interval}, set to 60s`);\n interval = 60;\n }\n\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = environment.vars.number(\"passcode\") ?? (await deviceStorage.get(\"passcode\", 20202021));\n const discriminator = environment.vars.number(\"discriminator\") ?? (await deviceStorage.get(\"discriminator\", 3840));\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = environment.vars.number(\"vendorid\") ?? (await deviceStorage.get(\"vendorid\", 0xfff1));\n const productName = `node-matter OnOff ${isTemperature ? \"Temperature\" : \"Humidity\"}`;\n const productId = environment.vars.number(\"productid\") ?? (await deviceStorage.get(\"productid\", 0x8000));\n\n const port = environment.vars.number(\"port\") ?? 5540;\n\n const uniqueId =\n environment.vars.string(\"uniqueid\") ?? (await deviceStorage.get(\"uniqueid\", Time.nowMs().toString()));\n\n // Persist basic data to keep them also on restart\n await deviceStorage.set({\n passcode,\n discriminator,\n vendorid: vendorId,\n productid: productId,\n interval,\n isTemperature,\n uniqueid: uniqueId,\n });\n\n return {\n isTemperature,\n interval,\n deviceName,\n vendorName,\n passcode,\n discriminator,\n vendorId,\n productName,\n productId,\n port,\n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M,cAAc,IAAI,YAAY,KAAK,MAAM,EAAE,SAAS,CAAC;AAGvG,QAAM,cAAc,IAAI;AAAA,IACpB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;",
6
- "names": []
7
- }
@@ -1,121 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2022-2024 Matter.js Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { Bytes, Logger } from "@project-chip/matter.js-general";
7
- import { GeneralCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/general-commissioning";
8
- import { NetworkCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
9
- import { NetworkCommissioning } from "@project-chip/matter.js/cluster";
10
- const firstNetworkId = new Uint8Array(32);
11
- class DummyThreadNetworkCommissioningServer extends NetworkCommissioningBehavior.with(
12
- NetworkCommissioning.Feature.ThreadNetworkInterface
13
- ) {
14
- scanNetworks({
15
- breadcrumb
16
- }) {
17
- console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${breadcrumb}`);
18
- if (breadcrumb !== void 0) {
19
- const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
20
- generalCommissioningCluster.state.breadcrumb = breadcrumb;
21
- }
22
- const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
23
- this.state.lastNetworkingStatus = networkingStatus;
24
- const threadScanResults = [
25
- {
26
- panId: this.endpoint.env.vars.number("ble.thread.panId"),
27
- extendedPanId: BigInt(this.endpoint.env.vars.string("ble.thread.extendedPanId")),
28
- networkName: this.endpoint.env.vars.string("ble.thread.networkName"),
29
- channel: this.endpoint.env.vars.number("ble.thread.channel"),
30
- version: 130,
31
- extendedAddress: Bytes.fromString(
32
- (this.endpoint.env.vars.string("ble.thread.address") ?? "000000000000").toLowerCase()
33
- ),
34
- rssi: -50,
35
- lqi: 50
36
- }
37
- ];
38
- console.log(Logger.toJSON(threadScanResults));
39
- return {
40
- networkingStatus,
41
- threadScanResults
42
- };
43
- }
44
- addOrUpdateThreadNetwork({
45
- operationalDataset,
46
- breadcrumb
47
- }) {
48
- console.log(
49
- `---> addOrUpdateThreadNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(operationalDataset)} ${breadcrumb}`
50
- );
51
- this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
52
- if (breadcrumb !== void 0) {
53
- const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
54
- generalCommissioningCluster.state.breadcrumb = breadcrumb;
55
- }
56
- const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
57
- this.state.lastNetworkingStatus = networkingStatus;
58
- this.state.lastNetworkId = firstNetworkId;
59
- return {
60
- networkingStatus,
61
- networkIndex: 0
62
- };
63
- }
64
- removeNetwork({ networkId, breadcrumb }) {
65
- console.log(
66
- `---> removeNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`
67
- );
68
- this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
69
- if (breadcrumb !== void 0) {
70
- const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
71
- generalCommissioningCluster.state.breadcrumb = breadcrumb;
72
- }
73
- const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
74
- this.state.lastNetworkingStatus = networkingStatus;
75
- this.state.lastNetworkId = firstNetworkId;
76
- return {
77
- networkingStatus,
78
- networkIndex: 0
79
- };
80
- }
81
- async connectNetwork({ networkId, breadcrumb }) {
82
- console.log(
83
- `---> connectNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`
84
- );
85
- this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
86
- if (breadcrumb !== void 0) {
87
- const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
88
- generalCommissioningCluster.state.breadcrumb = breadcrumb;
89
- }
90
- this.state.networks[0].connected = true;
91
- const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
92
- this.state.lastNetworkingStatus = networkingStatus;
93
- this.state.lastNetworkId = firstNetworkId;
94
- this.state.lastConnectErrorValue = null;
95
- const device = this.session.context;
96
- await device.startAnnouncement();
97
- return {
98
- networkingStatus,
99
- errorValue: null
100
- };
101
- }
102
- reorderNetwork({ networkId, networkIndex, breadcrumb }) {
103
- console.log(
104
- `---> reorderNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${networkIndex} ${breadcrumb}`
105
- );
106
- if (breadcrumb !== void 0) {
107
- const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
108
- generalCommissioningCluster.state.breadcrumb = breadcrumb;
109
- }
110
- const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
111
- this.state.lastNetworkingStatus = networkingStatus;
112
- return {
113
- networkingStatus,
114
- networkIndex: 0
115
- };
116
- }
117
- }
118
- export {
119
- DummyThreadNetworkCommissioningServer
120
- };
121
- //# sourceMappingURL=DummyThreadNetworkCommissioningServer.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/examples/cluster/DummyThreadNetworkCommissioningServer.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022-2024 Matter.js Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Bytes, Logger } from \"@project-chip/matter.js-general\";\nimport { GeneralCommissioningBehavior } from \"@project-chip/matter.js/behavior/definitions/general-commissioning\";\nimport { NetworkCommissioningBehavior } from \"@project-chip/matter.js/behavior/definitions/network-commissioning\";\nimport { NetworkCommissioning } from \"@project-chip/matter.js/cluster\";\n\nconst firstNetworkId = new Uint8Array(32);\n\n/**\n * This represents a Dummy version of a Thread Network Commissioning Cluster Server without real thread 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 */\nexport class DummyThreadNetworkCommissioningServer extends NetworkCommissioningBehavior.with(\n NetworkCommissioning.Feature.ThreadNetworkInterface,\n) {\n override scanNetworks({\n breadcrumb,\n }: NetworkCommissioning.ScanNetworksRequest): NetworkCommissioning.ScanNetworksResponse {\n console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${breadcrumb}`);\n\n // Simulate successful scan\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);\n generalCommissioningCluster.state.breadcrumb = breadcrumb;\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n this.state.lastNetworkingStatus = networkingStatus;\n\n const threadScanResults = [\n {\n panId: this.endpoint.env.vars.number(\"ble.thread.panId\"),\n extendedPanId: BigInt(this.endpoint.env.vars.string(\"ble.thread.extendedPanId\")),\n networkName: this.endpoint.env.vars.string(\"ble.thread.networkName\"),\n channel: this.endpoint.env.vars.number(\"ble.thread.channel\"),\n version: 130,\n extendedAddress: Bytes.fromString(\n (this.endpoint.env.vars.string(\"ble.thread.address\") ?? \"000000000000\").toLowerCase(),\n ),\n rssi: -50,\n lqi: 50,\n },\n ];\n console.log(Logger.toJSON(threadScanResults));\n\n return {\n networkingStatus,\n threadScanResults,\n };\n }\n\n override addOrUpdateThreadNetwork({\n operationalDataset,\n breadcrumb,\n }: NetworkCommissioning.AddOrUpdateThreadNetworkRequest) {\n console.log(\n `---> addOrUpdateThreadNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(operationalDataset)} ${breadcrumb}`,\n );\n\n this.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 = this.agent.get(GeneralCommissioningBehavior);\n generalCommissioningCluster.state.breadcrumb = breadcrumb;\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n this.state.lastNetworkingStatus = networkingStatus;\n this.state.lastNetworkId = firstNetworkId;\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n }\n\n override removeNetwork({ networkId, breadcrumb }: NetworkCommissioning.RemoveNetworkRequest) {\n console.log(\n `---> removeNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,\n );\n\n this.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 = this.agent.get(GeneralCommissioningBehavior);\n generalCommissioningCluster.state.breadcrumb = breadcrumb;\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n this.state.lastNetworkingStatus = networkingStatus;\n this.state.lastNetworkId = firstNetworkId;\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n }\n\n override async connectNetwork({ networkId, breadcrumb }: NetworkCommissioning.ConnectNetworkRequest) {\n console.log(\n `---> connectNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`,\n );\n\n this.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 = this.agent.get(GeneralCommissioningBehavior);\n generalCommissioningCluster.state.breadcrumb = breadcrumb;\n }\n\n this.state.networks[0].connected = true;\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n this.state.lastNetworkingStatus = networkingStatus;\n this.state.lastNetworkId = firstNetworkId;\n this.state.lastConnectErrorValue = null;\n\n // Announce operational in IP network\n const device = this.session.context;\n await device.startAnnouncement();\n\n return {\n networkingStatus,\n errorValue: null,\n };\n }\n\n override reorderNetwork({ networkId, networkIndex, breadcrumb }: NetworkCommissioning.ReorderNetworkRequest) {\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 = this.agent.get(GeneralCommissioningBehavior);\n generalCommissioningCluster.state.breadcrumb = breadcrumb;\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n this.state.lastNetworkingStatus = networkingStatus;\n\n return {\n networkingStatus,\n networkIndex: 0,\n };\n }\n}\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,OAAO,cAAc;AAC9B,SAAS,oCAAoC;AAC7C,SAAS,oCAAoC;AAC7C,SAAS,4BAA4B;AAErC,MAAM,iBAAiB,IAAI,WAAW,EAAE;AAOjC,MAAM,8CAA8C,6BAA6B;AAAA,EACpF,qBAAqB,QAAQ;AACjC,EAAE;AAAA,EACW,aAAa;AAAA,IAClB;AAAA,EACJ,GAAwF;AACpF,YAAQ,IAAI,6DAA6D,UAAU,EAAE;AAGrF,QAAI,eAAe,QAAW;AAC1B,YAAM,8BAA8B,KAAK,MAAM,IAAI,4BAA4B;AAC/E,kCAA4B,MAAM,aAAa;AAAA,IACnD;AAEA,UAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,SAAK,MAAM,uBAAuB;AAElC,UAAM,oBAAoB;AAAA,MACtB;AAAA,QACI,OAAO,KAAK,SAAS,IAAI,KAAK,OAAO,kBAAkB;AAAA,QACvD,eAAe,OAAO,KAAK,SAAS,IAAI,KAAK,OAAO,0BAA0B,CAAC;AAAA,QAC/E,aAAa,KAAK,SAAS,IAAI,KAAK,OAAO,wBAAwB;AAAA,QACnE,SAAS,KAAK,SAAS,IAAI,KAAK,OAAO,oBAAoB;AAAA,QAC3D,SAAS;AAAA,QACT,iBAAiB,MAAM;AAAA,WAClB,KAAK,SAAS,IAAI,KAAK,OAAO,oBAAoB,KAAK,gBAAgB,YAAY;AAAA,QACxF;AAAA,QACA,MAAM;AAAA,QACN,KAAK;AAAA,MACT;AAAA,IACJ;AACA,Y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4BAA4B;AAC/E,kCAA4B,MAAM,aAAa;AAAA,IACnD;AAEA,SAAK,MAAM,SAAS,CAAC,EAAE,YAAY;AAEnC,UAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,SAAK,MAAM,uBAAuB;AAClC,SAAK,MAAM,gBAAgB;AAC3B,SAAK,MAAM,wBAAwB;AAGnC,UAAM,SAAS,KAAK,QAAQ;AAC5B,UAAM,OAAO,kBAAkB;AAE/B,WAAO;AAAA,MACH;AAAA,MACA,YAAY;AAAA,IAChB;AAAA,EACJ;AAAA,EAES,eAAe,EAAE,WAAW,cAAc,WAAW,GAA+C;AACzG,YAAQ;AAAA,MACJ,+DAA+D,MAAM,MAAM,SAAS,CAAC,IAAI,YAAY,IAAI,UAAU;AAAA,IACvH;AAGA,QAAI,eAAe,QAAW;AAC1B,YAAM,8BAA8B,KAAK,MAAM,IAAI,4BAA4B;AAC/E,kCAA4B,MAAM,aAAa;AAAA,IACnD;AAEA,UAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,SAAK,MAAM,uBAAuB;AAElC,WAAO;AAAA,MACH;AAAA,MACA,cAAc;AAAA,IAClB;AAAA,EACJ;AACJ;",
6
- "names": []
7
- }
@@ -1,121 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2022-2024 Matter.js Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { Bytes } from "@project-chip/matter.js-general";
7
- import { GeneralCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/general-commissioning";
8
- import { NetworkCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
9
- import { NetworkCommissioning } from "@project-chip/matter.js/cluster";
10
- const firstNetworkId = new Uint8Array(32);
11
- class DummyWifiNetworkCommissioningServer extends NetworkCommissioningBehavior.with(
12
- NetworkCommissioning.Feature.WiFiNetworkInterface
13
- ) {
14
- scanNetworks({ ssid, breadcrumb }) {
15
- console.log(
16
- `---> scanNetworks called on NetworkCommissioning cluster: ${ssid ? Bytes.toHex(ssid) : void 0} ${breadcrumb}`
17
- );
18
- if (breadcrumb !== void 0) {
19
- const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
20
- generalCommissioningCluster.state.breadcrumb = breadcrumb;
21
- }
22
- const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
23
- this.state.lastNetworkingStatus = networkingStatus;
24
- return {
25
- networkingStatus,
26
- wiFiScanResults: [
27
- {
28
- security: {
29
- unencrypted: false,
30
- wep: false,
31
- wpaPersonal: false,
32
- wpa2Personal: true,
33
- wpa3Personal: true
34
- },
35
- ssid: ssid || Bytes.fromString(this.endpoint.env.vars.get("ble.wifi.scanSsid") ?? "TestSSID"),
36
- // Set a valid existing local Wi-Fi SSID here
37
- bssid: Bytes.fromString(this.endpoint.env.vars.get("ble.wifi.scanBssid") ?? "00:00:00:00:00:00"),
38
- channel: 1
39
- }
40
- ]
41
- };
42
- }
43
- addOrUpdateWiFiNetwork({
44
- ssid,
45
- credentials,
46
- breadcrumb
47
- }) {
48
- console.log(
49
- `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(ssid)} ${Bytes.toHex(credentials)} ${breadcrumb}`
50
- );
51
- this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
52
- if (breadcrumb !== void 0) {
53
- const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
54
- generalCommissioningCluster.state.breadcrumb = breadcrumb;
55
- }
56
- const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
57
- this.state.lastNetworkingStatus = networkingStatus;
58
- this.state.lastNetworkId = firstNetworkId;
59
- return {
60
- networkingStatus,
61
- networkIndex: 0
62
- };
63
- }
64
- removeNetwork({ networkId, breadcrumb }) {
65
- console.log(
66
- `---> removeNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`
67
- );
68
- this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
69
- if (breadcrumb !== void 0) {
70
- const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
71
- generalCommissioningCluster.state.breadcrumb = breadcrumb;
72
- }
73
- const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
74
- this.state.lastNetworkingStatus = networkingStatus;
75
- this.state.lastNetworkId = firstNetworkId;
76
- return {
77
- networkingStatus,
78
- networkIndex: 0
79
- };
80
- }
81
- async connectNetwork({ networkId, breadcrumb }) {
82
- console.log(
83
- `---> connectNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${breadcrumb}`
84
- );
85
- this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
86
- if (breadcrumb !== void 0) {
87
- const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
88
- generalCommissioningCluster.state.breadcrumb = breadcrumb;
89
- }
90
- this.state.networks[0].connected = true;
91
- const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
92
- this.state.lastNetworkingStatus = networkingStatus;
93
- this.state.lastNetworkId = firstNetworkId;
94
- this.state.lastConnectErrorValue = null;
95
- const device = this.session.context;
96
- await device.startAnnouncement();
97
- return {
98
- networkingStatus,
99
- errorValue: null
100
- };
101
- }
102
- reorderNetwork({ networkId, networkIndex, breadcrumb }) {
103
- console.log(
104
- `---> reorderNetwork called on NetworkCommissioning cluster: ${Bytes.toHex(networkId)} ${networkIndex} ${breadcrumb}`
105
- );
106
- if (breadcrumb !== void 0) {
107
- const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
108
- generalCommissioningCluster.state.breadcrumb = breadcrumb;
109
- }
110
- const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
111
- this.state.lastNetworkingStatus = networkingStatus;
112
- return {
113
- networkingStatus,
114
- networkIndex: 0
115
- };
116
- }
117
- }
118
- export {
119
- DummyWifiNetworkCommissioningServer
120
- };
121
- //# sourceMappingURL=DummyWifiNetworkCommissioningServer.js.map