@project-chip/matter-node.js-examples 0.6.1-alpha.0-20231031-f3417b3 → 0.6.1-alpha.0-20231101-4ef32c9

Sign up to get free protection for your applications and to get access to all the features.
package/src/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "extends": "../../../tools/tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "outDir": "../dist/cjs",
4
+ "outDir": "../dist/esm",
5
5
  "types": ["node"]
6
6
  },
7
7
  "references": [{ "path": "../../matter-node.js/src" }, { "path": "../../matter-node-ble.js/src" }]
@@ -1,136 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var import_matter_node = require("@project-chip/matter-node.js");
4
- var import_datatype = require("@project-chip/matter-node.js/datatype");
5
- var import_device = require("@project-chip/matter-node.js/device");
6
- var import_log = require("@project-chip/matter-node.js/log");
7
- var import_schema = require("@project-chip/matter-node.js/schema");
8
- var import_storage = require("@project-chip/matter-node.js/storage");
9
- var import_time = require("@project-chip/matter-node.js/time");
10
- var import_util = require("@project-chip/matter-node.js/util");
11
- /**
12
- * @license
13
- * Copyright 2022 The node-matter Authors
14
- * SPDX-License-Identifier: Apache-2.0
15
- */
16
- const logger = import_log.Logger.get("Device");
17
- (0, import_util.requireMinNodeVersion)(16);
18
- switch ((0, import_util.getParameter)("loglevel")) {
19
- case "fatal":
20
- import_log.Logger.defaultLogLevel = import_log.Level.FATAL;
21
- break;
22
- case "error":
23
- import_log.Logger.defaultLogLevel = import_log.Level.ERROR;
24
- break;
25
- case "warn":
26
- import_log.Logger.defaultLogLevel = import_log.Level.WARN;
27
- break;
28
- case "info":
29
- import_log.Logger.defaultLogLevel = import_log.Level.INFO;
30
- break;
31
- }
32
- switch ((0, import_util.getParameter)("logformat")) {
33
- case "plain":
34
- import_log.Logger.format = import_log.Format.PLAIN;
35
- break;
36
- case "html":
37
- import_log.Logger.format = import_log.Format.HTML;
38
- break;
39
- default:
40
- if (process.stdin?.isTTY)
41
- import_log.Logger.format = import_log.Format.ANSI;
42
- }
43
- const storageLocation = (0, import_util.getParameter)("store") ?? ".device-node";
44
- const storage = new import_storage.StorageBackendDisk(storageLocation, (0, import_util.hasParameter)("clearstorage"));
45
- logger.info(`Storage location: ${storageLocation} (Directory)`);
46
- logger.info(
47
- 'Use the parameter "-store NAME" to specify a different storage location, use -clearstorage to start with an empty storage.'
48
- );
49
- class BridgedDevice {
50
- async start() {
51
- logger.info(`node-matter`);
52
- const storageManager = new import_storage.StorageManager(storage);
53
- await storageManager.initialize();
54
- const deviceStorage = storageManager.createContext("Device");
55
- const deviceName = "Matter Bridge device";
56
- const deviceType = import_device.DeviceTypes.AGGREGATOR.code;
57
- const vendorName = "matter-node.js";
58
- const passcode = (0, import_util.getIntParameter)("passcode") ?? deviceStorage.get("passcode", 20202021);
59
- const discriminator = (0, import_util.getIntParameter)("discriminator") ?? deviceStorage.get("discriminator", 3840);
60
- const vendorId = (0, import_util.getIntParameter)("vendorid") ?? deviceStorage.get("vendorid", 65521);
61
- const productName = `node-matter OnOff-Bridge`;
62
- const productId = (0, import_util.getIntParameter)("productid") ?? deviceStorage.get("productid", 32768);
63
- const netAnnounceInterface = (0, import_util.getParameter)("announceinterface");
64
- const port = (0, import_util.getIntParameter)("port") ?? 5540;
65
- const uniqueId = (0, import_util.getIntParameter)("uniqueid") ?? deviceStorage.get("uniqueid", import_time.Time.nowMs());
66
- deviceStorage.set("passcode", passcode);
67
- deviceStorage.set("discriminator", discriminator);
68
- deviceStorage.set("vendorid", vendorId);
69
- deviceStorage.set("productid", productId);
70
- deviceStorage.set("uniqueid", uniqueId);
71
- this.matterServer = new import_matter_node.MatterServer(storageManager, { mdnsAnnounceInterface: netAnnounceInterface });
72
- const commissioningServer = new import_matter_node.CommissioningServer({
73
- port,
74
- deviceName,
75
- deviceType,
76
- passcode,
77
- discriminator,
78
- basicInformation: {
79
- vendorName,
80
- vendorId: (0, import_datatype.VendorId)(vendorId),
81
- nodeLabel: productName,
82
- productName,
83
- productLabel: productName,
84
- productId,
85
- serialNumber: `node-matter-${uniqueId}`
86
- }
87
- });
88
- const aggregator = new import_device.Aggregator();
89
- const numDevices = (0, import_util.getIntParameter)("num") || 2;
90
- for (let i = 1; i <= numDevices; i++) {
91
- const onOffDevice = (0, import_util.getParameter)(`type${i}`) === "socket" ? new import_device.OnOffPluginUnitDevice() : new import_device.OnOffLightDevice();
92
- onOffDevice.addOnOffListener((on) => (0, import_util.commandExecutor)(on ? `on${i}` : `off${i}`)?.());
93
- onOffDevice.addCommandHandler(
94
- "identify",
95
- async ({ request: { identifyTime } }) => console.log(
96
- `Identify called for OnOffDevice ${onOffDevice.name} with id: ${i} and identifyTime: ${identifyTime}`
97
- )
98
- );
99
- const name = `OnOff ${onOffDevice instanceof import_device.OnOffPluginUnitDevice ? "Socket" : "Light"} ${i}`;
100
- aggregator.addBridgedDevice(onOffDevice, {
101
- nodeLabel: name,
102
- productName: name,
103
- productLabel: name,
104
- serialNumber: `node-matter-${uniqueId}-${i}`,
105
- reachable: true
106
- });
107
- }
108
- commissioningServer.addDevice(aggregator);
109
- this.matterServer.addCommissioningServer(commissioningServer);
110
- await this.matterServer.start();
111
- logger.info("Listening");
112
- if (!commissioningServer.isCommissioned()) {
113
- const pairingData = commissioningServer.getPairingCode();
114
- const { qrPairingCode, manualPairingCode } = pairingData;
115
- console.log(import_schema.QrCode.get(qrPairingCode));
116
- console.log(
117
- `QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`
118
- );
119
- console.log(`Manual pairing code: ${manualPairingCode}`);
120
- } else {
121
- console.log("Device is already commissioned. Waiting for controllers to connect ...");
122
- }
123
- }
124
- async stop() {
125
- await this.matterServer?.close();
126
- }
127
- }
128
- const device = new BridgedDevice();
129
- device.start().then(() => {
130
- }).catch((err) => console.error(err));
131
- process.on("SIGINT", () => {
132
- device.stop().then(() => {
133
- storage.close().then(() => process.exit(0)).catch((err) => console.error(err));
134
- }).catch((err) => console.error(err));
135
- });
136
- //# sourceMappingURL=BridgedDevicesNode.js.map
@@ -1,133 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var import_matter_node = require("@project-chip/matter-node.js");
4
- var import_datatype = require("@project-chip/matter-node.js/datatype");
5
- var import_device = require("@project-chip/matter-node.js/device");
6
- var import_log = require("@project-chip/matter-node.js/log");
7
- var import_schema = require("@project-chip/matter-node.js/schema");
8
- var import_storage = require("@project-chip/matter-node.js/storage");
9
- var import_time = require("@project-chip/matter-node.js/time");
10
- var import_util = require("@project-chip/matter-node.js/util");
11
- /**
12
- * @license
13
- * Copyright 2022 The node-matter Authors
14
- * SPDX-License-Identifier: Apache-2.0
15
- */
16
- const logger = import_log.Logger.get("Device");
17
- (0, import_util.requireMinNodeVersion)(16);
18
- switch ((0, import_util.getParameter)("loglevel")) {
19
- case "fatal":
20
- import_log.Logger.defaultLogLevel = import_log.Level.FATAL;
21
- break;
22
- case "error":
23
- import_log.Logger.defaultLogLevel = import_log.Level.ERROR;
24
- break;
25
- case "warn":
26
- import_log.Logger.defaultLogLevel = import_log.Level.WARN;
27
- break;
28
- case "info":
29
- import_log.Logger.defaultLogLevel = import_log.Level.INFO;
30
- break;
31
- }
32
- switch ((0, import_util.getParameter)("logformat")) {
33
- case "plain":
34
- import_log.Logger.format = import_log.Format.PLAIN;
35
- break;
36
- case "html":
37
- import_log.Logger.format = import_log.Format.HTML;
38
- break;
39
- default:
40
- if (process.stdin?.isTTY)
41
- import_log.Logger.format = import_log.Format.ANSI;
42
- }
43
- const storageLocation = (0, import_util.getParameter)("store") ?? ".device-node";
44
- const storage = new import_storage.StorageBackendDisk(storageLocation, (0, import_util.hasParameter)("clearstorage"));
45
- logger.info(`Storage location: ${storageLocation} (Directory)`);
46
- logger.info(
47
- 'Use the parameter "-store NAME" to specify a different storage location, use -clearstorage to start with an empty storage.'
48
- );
49
- class ComposedDevice {
50
- async start() {
51
- logger.info(`node-matter`);
52
- const storageManager = new import_storage.StorageManager(storage);
53
- await storageManager.initialize();
54
- const deviceStorage = storageManager.createContext("Device");
55
- if (deviceStorage.has("isSocket")) {
56
- logger.info("Device type found in storage. -type parameter is ignored.");
57
- }
58
- const isSocket = deviceStorage.get("isSocket", (0, import_util.getParameter)("type") === "socket");
59
- const deviceName = "Matter composed device";
60
- const deviceType = (0, import_util.getParameter)("type") === "socket" ? import_device.DeviceTypes.ON_OFF_PLUGIN_UNIT.code : import_device.DeviceTypes.ON_OFF_LIGHT.code;
61
- const vendorName = "matter-node.js";
62
- const passcode = (0, import_util.getIntParameter)("passcode") ?? deviceStorage.get("passcode", 20202021);
63
- const discriminator = (0, import_util.getIntParameter)("discriminator") ?? deviceStorage.get("discriminator", 3840);
64
- const vendorId = (0, import_util.getIntParameter)("vendorid") ?? deviceStorage.get("vendorid", 65521);
65
- const productName = `node-matter OnOff-Bridge`;
66
- const productId = (0, import_util.getIntParameter)("productid") ?? deviceStorage.get("productid", 32768);
67
- const netAnnounceInterface = (0, import_util.getParameter)("announceinterface");
68
- const port = (0, import_util.getIntParameter)("port") ?? 5540;
69
- const uniqueId = (0, import_util.getIntParameter)("uniqueid") ?? deviceStorage.get("uniqueid", import_time.Time.nowMs());
70
- deviceStorage.set("passcode", passcode);
71
- deviceStorage.set("discriminator", discriminator);
72
- deviceStorage.set("vendorid", vendorId);
73
- deviceStorage.set("productid", productId);
74
- deviceStorage.set("isSocket", isSocket);
75
- deviceStorage.set("uniqueid", uniqueId);
76
- this.matterServer = new import_matter_node.MatterServer(storageManager, { mdnsAnnounceInterface: netAnnounceInterface });
77
- const commissioningServer = new import_matter_node.CommissioningServer({
78
- port,
79
- deviceName,
80
- deviceType,
81
- passcode,
82
- discriminator,
83
- basicInformation: {
84
- vendorName,
85
- vendorId: (0, import_datatype.VendorId)(vendorId),
86
- nodeLabel: productName,
87
- productName,
88
- productLabel: productName,
89
- productId,
90
- serialNumber: `node-matter-${uniqueId}`
91
- }
92
- });
93
- const numDevices = (0, import_util.getIntParameter)("num") || 2;
94
- for (let i = 1; i <= numDevices; i++) {
95
- const onOffDevice = (0, import_util.getParameter)(`type${i}`) === "socket" ? new import_device.OnOffPluginUnitDevice() : new import_device.OnOffLightDevice();
96
- onOffDevice.addFixedLabel("orientation", (0, import_util.getParameter)(`orientation${i}`) ?? `orientation ${i}`);
97
- onOffDevice.addOnOffListener((on) => (0, import_util.commandExecutor)(on ? `on${i}` : `off${i}`)?.());
98
- onOffDevice.addCommandHandler(
99
- "identify",
100
- async ({ request: { identifyTime } }) => console.log(
101
- `Identify called for OnOffDevice ${onOffDevice.name} with id: ${i} and identifyTime: ${identifyTime}`
102
- )
103
- );
104
- commissioningServer.addDevice(onOffDevice);
105
- }
106
- this.matterServer.addCommissioningServer(commissioningServer);
107
- await this.matterServer.start();
108
- logger.info("Listening");
109
- if (!commissioningServer.isCommissioned()) {
110
- const pairingData = commissioningServer.getPairingCode();
111
- const { qrPairingCode, manualPairingCode } = pairingData;
112
- console.log(import_schema.QrCode.get(qrPairingCode));
113
- console.log(
114
- `QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`
115
- );
116
- console.log(`Manual pairing code: ${manualPairingCode}`);
117
- } else {
118
- console.log("Device is already commissioned. Waiting for controllers to connect ...");
119
- }
120
- }
121
- async stop() {
122
- await this.matterServer?.close();
123
- }
124
- }
125
- const device = new ComposedDevice();
126
- device.start().then(() => {
127
- }).catch((err) => console.error(err));
128
- process.on("SIGINT", () => {
129
- device.stop().then(() => {
130
- storage.close().then(() => process.exit(0)).catch((err) => console.error(err));
131
- }).catch((err) => console.error(err));
132
- });
133
- //# sourceMappingURL=ComposedDeviceNode.js.map
@@ -1,175 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
25
- var import_matter_node = require("@project-chip/matter-node.js");
26
- var import_ble = require("@project-chip/matter-node-ble.js/ble");
27
- var import_ble2 = require("@project-chip/matter-node.js/ble");
28
- var import_device = require("@project-chip/matter-node.js/device");
29
- var import_log = require("@project-chip/matter-node.js/log");
30
- var import_schema = require("@project-chip/matter-node.js/schema");
31
- var import_storage = require("@project-chip/matter-node.js/storage");
32
- var import_time = require("@project-chip/matter-node.js/time");
33
- var import_util = require("@project-chip/matter-node.js/util");
34
- var import_datatype = require("@project-chip/matter.js/datatype");
35
- var import_DummyWifiNetworkCommissioningClusterServer = __toESM(require("./cluster/DummyWifiNetworkCommissioningClusterServer.js"));
36
- /**
37
- * @license
38
- * Copyright 2022 The node-matter Authors
39
- * SPDX-License-Identifier: Apache-2.0
40
- */
41
- const logger = import_log.Logger.get("Device");
42
- (0, import_util.requireMinNodeVersion)(16);
43
- switch ((0, import_util.getParameter)("loglevel")) {
44
- case "fatal":
45
- import_log.Logger.defaultLogLevel = import_log.Level.FATAL;
46
- break;
47
- case "error":
48
- import_log.Logger.defaultLogLevel = import_log.Level.ERROR;
49
- break;
50
- case "warn":
51
- import_log.Logger.defaultLogLevel = import_log.Level.WARN;
52
- break;
53
- case "info":
54
- import_log.Logger.defaultLogLevel = import_log.Level.INFO;
55
- break;
56
- }
57
- switch ((0, import_util.getParameter)("logformat")) {
58
- case "plain":
59
- import_log.Logger.format = import_log.Format.PLAIN;
60
- break;
61
- case "html":
62
- import_log.Logger.format = import_log.Format.HTML;
63
- break;
64
- default:
65
- if (process.stdin?.isTTY)
66
- import_log.Logger.format = import_log.Format.ANSI;
67
- }
68
- if ((0, import_util.hasParameter)("ble")) {
69
- import_ble2.Ble.get = (0, import_util.singleton)(
70
- () => new import_ble.BleNode({
71
- hciId: (0, import_util.getIntParameter)("ble-hci-id")
72
- })
73
- );
74
- }
75
- const storageLocation = (0, import_util.getParameter)("store") ?? ".device-node";
76
- const storage = new import_storage.StorageBackendDisk(storageLocation, (0, import_util.hasParameter)("clearstorage"));
77
- logger.info(`Storage location: ${storageLocation} (Directory)`);
78
- logger.info(
79
- 'Use the parameter "-store NAME" to specify a different storage location, use -clearstorage to start with an empty storage.'
80
- );
81
- class Device {
82
- async start() {
83
- logger.info(`node-matter`);
84
- const storageManager = new import_storage.StorageManager(storage);
85
- await storageManager.initialize();
86
- const deviceStorage = storageManager.createContext("Device");
87
- if (deviceStorage.has("isSocket")) {
88
- logger.info("Device type found in storage. -type parameter is ignored.");
89
- }
90
- const isSocket = deviceStorage.get("isSocket", (0, import_util.getParameter)("type") === "socket");
91
- const deviceName = "Matter test device";
92
- const vendorName = "matter-node.js";
93
- const passcode = (0, import_util.getIntParameter)("passcode") ?? deviceStorage.get("passcode", 20202021);
94
- const discriminator = (0, import_util.getIntParameter)("discriminator") ?? deviceStorage.get("discriminator", 3840);
95
- const vendorId = (0, import_util.getIntParameter)("vendorid") ?? deviceStorage.get("vendorid", 65521);
96
- const productName = `node-matter OnOff ${isSocket ? "Socket" : "Light"}`;
97
- const productId = (0, import_util.getIntParameter)("productid") ?? deviceStorage.get("productid", 32768);
98
- const netAnnounceInterface = (0, import_util.getParameter)("announceinterface");
99
- const port = (0, import_util.getIntParameter)("port") ?? 5540;
100
- const uniqueId = (0, import_util.getIntParameter)("uniqueid") ?? deviceStorage.get("uniqueid", import_time.Time.nowMs());
101
- deviceStorage.set("passcode", passcode);
102
- deviceStorage.set("discriminator", discriminator);
103
- deviceStorage.set("vendorid", vendorId);
104
- deviceStorage.set("productid", productId);
105
- deviceStorage.set("isSocket", isSocket);
106
- deviceStorage.set("uniqueid", uniqueId);
107
- const onOffDevice = isSocket ? new import_device.OnOffPluginUnitDevice() : new import_device.OnOffLightDevice();
108
- onOffDevice.addOnOffListener((on) => (0, import_util.commandExecutor)(on ? "on" : "off")?.());
109
- onOffDevice.addCommandHandler(
110
- "identify",
111
- async ({ request: { identifyTime } }) => logger.info(`Identify called for OnOffDevice: ${identifyTime}`)
112
- );
113
- this.matterServer = new import_matter_node.MatterServer(storageManager, { mdnsAnnounceInterface: netAnnounceInterface });
114
- const commissioningServer = new import_matter_node.CommissioningServer({
115
- port,
116
- deviceName,
117
- deviceType: (0, import_datatype.DeviceTypeId)(onOffDevice.deviceType),
118
- passcode,
119
- discriminator,
120
- basicInformation: {
121
- vendorName,
122
- vendorId: (0, import_datatype.VendorId)(vendorId),
123
- nodeLabel: productName,
124
- productName,
125
- productLabel: productName,
126
- productId,
127
- serialNumber: `node-matter-${uniqueId}`
128
- },
129
- delayedAnnouncement: (0, import_util.hasParameter)("ble")
130
- // Delay announcement when BLE is used to show how limited advertisement works
131
- });
132
- commissioningServer.addCommandHandler(
133
- "testEventTrigger",
134
- async ({ request: { enableKey, eventTrigger } }) => logger.info(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`)
135
- );
136
- if ((0, import_util.hasParameter)("ble")) {
137
- commissioningServer.addRootClusterServer(import_DummyWifiNetworkCommissioningClusterServer.default);
138
- }
139
- commissioningServer.addDevice(onOffDevice);
140
- this.matterServer.addCommissioningServer(commissioningServer);
141
- await this.matterServer.start();
142
- (0, import_device.logEndpoint)(commissioningServer.getRootEndpoint());
143
- if ((0, import_util.hasParameter)("ble")) {
144
- await commissioningServer.advertise({ ble: true });
145
- }
146
- logger.info("Listening");
147
- if (!commissioningServer.isCommissioned()) {
148
- const pairingData = commissioningServer.getPairingCode({
149
- ble: (0, import_util.hasParameter)("ble"),
150
- softAccessPoint: false,
151
- onIpNetwork: false
152
- });
153
- const { qrPairingCode, manualPairingCode } = pairingData;
154
- console.log(import_schema.QrCode.get(qrPairingCode));
155
- logger.info(
156
- `QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`
157
- );
158
- logger.info(`Manual pairing code: ${manualPairingCode}`);
159
- } else {
160
- logger.info("Device is already commissioned. Waiting for controllers to connect ...");
161
- }
162
- }
163
- async stop() {
164
- await this.matterServer?.close();
165
- }
166
- }
167
- const device = new Device();
168
- device.start().then(() => {
169
- }).catch((err) => console.error(err));
170
- process.on("SIGINT", () => {
171
- device.stop().then(() => {
172
- storage.close().then(() => process.exit(0)).catch((err) => console.error(err));
173
- }).catch((err) => console.error(err));
174
- });
175
- //# sourceMappingURL=DeviceNode.js.map
@@ -1,141 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var import_matter_node = require("@project-chip/matter-node.js");
4
- var import_device = require("@project-chip/matter-node.js/device");
5
- var import_log = require("@project-chip/matter-node.js/log");
6
- var import_schema = require("@project-chip/matter-node.js/schema");
7
- var import_storage = require("@project-chip/matter-node.js/storage");
8
- var import_time = require("@project-chip/matter-node.js/time");
9
- var import_util = require("@project-chip/matter-node.js/util");
10
- var import_datatype = require("@project-chip/matter.js/datatype");
11
- /**
12
- * @license
13
- * Copyright 2022 The node-matter Authors
14
- * SPDX-License-Identifier: Apache-2.0
15
- */
16
- const logger = import_log.Logger.get("MultiDevice");
17
- (0, import_util.requireMinNodeVersion)(16);
18
- switch ((0, import_util.getParameter)("loglevel")) {
19
- case "fatal":
20
- import_log.Logger.defaultLogLevel = import_log.Level.FATAL;
21
- break;
22
- case "error":
23
- import_log.Logger.defaultLogLevel = import_log.Level.ERROR;
24
- break;
25
- case "warn":
26
- import_log.Logger.defaultLogLevel = import_log.Level.WARN;
27
- break;
28
- case "info":
29
- import_log.Logger.defaultLogLevel = import_log.Level.INFO;
30
- break;
31
- }
32
- switch ((0, import_util.getParameter)("logformat")) {
33
- case "plain":
34
- import_log.Logger.format = import_log.Format.PLAIN;
35
- break;
36
- case "html":
37
- import_log.Logger.format = import_log.Format.HTML;
38
- break;
39
- default:
40
- if (process.stdin?.isTTY)
41
- import_log.Logger.format = import_log.Format.ANSI;
42
- }
43
- const storageLocation = (0, import_util.getParameter)("store") ?? ".device-node";
44
- const storage = new import_storage.StorageBackendDisk(storageLocation, (0, import_util.hasParameter)("clearstorage"));
45
- logger.info(`Storage location: ${storageLocation} (Directory)`);
46
- logger.info(
47
- 'Use the parameter "-store NAME" to specify a different storage location, use -clearstorage to start with an empty storage.'
48
- );
49
- class Device {
50
- async start() {
51
- logger.info(`node-matter`);
52
- const storageManager = new import_storage.StorageManager(storage);
53
- await storageManager.initialize();
54
- const netAnnounceInterface = (0, import_util.getParameter)("announceinterface");
55
- const deviceStorage = storageManager.createContext("Device");
56
- this.matterServer = new import_matter_node.MatterServer(storageManager, { mdnsAnnounceInterface: netAnnounceInterface });
57
- const commissioningServers = new Array();
58
- let defaultPasscode = 20202021;
59
- let defaultDiscriminator = 3840;
60
- let defaultPort = 5550;
61
- const numDevices = (0, import_util.getIntParameter)("num") || 2;
62
- for (let i = 1; i <= numDevices; i++) {
63
- if (deviceStorage.has(`isSocket${i}`)) {
64
- logger.info("Device type found in storage. -type parameter is ignored.");
65
- }
66
- const isSocket = deviceStorage.get(`isSocket${i}`, (0, import_util.getParameter)(`type${i}`) === "socket");
67
- const deviceName = `Matter ${(0, import_util.getParameter)(`type${i}`) ?? "light"} device ${i}`;
68
- const deviceType = (0, import_util.getParameter)(`type${i}`) === "socket" ? import_device.DeviceTypes.ON_OFF_PLUGIN_UNIT.code : import_device.DeviceTypes.ON_OFF_LIGHT.code;
69
- const vendorName = "matter-node.js";
70
- const passcode = (0, import_util.getIntParameter)(`passcode${i}`) ?? deviceStorage.get(`passcode${i}`, defaultPasscode++);
71
- const discriminator = (0, import_util.getIntParameter)(`discriminator${i}`) ?? deviceStorage.get(`discriminator${i}`, defaultDiscriminator++);
72
- const vendorId = (0, import_util.getIntParameter)(`vendorid${i}`) ?? deviceStorage.get(`vendorid${i}`, 65521);
73
- const productName = `node-matter OnOff-Device ${i}`;
74
- const productId = (0, import_util.getIntParameter)(`productid${i}`) ?? deviceStorage.get(`productid${i}`, 32768);
75
- const port = (0, import_util.getIntParameter)(`port${i}`) ?? defaultPort++;
76
- const uniqueId = (0, import_util.getIntParameter)(`uniqueid${i}`) ?? deviceStorage.get(`uniqueid${i}`, `${i}-${import_time.Time.nowMs()}`);
77
- deviceStorage.set(`passcode${i}`, passcode);
78
- deviceStorage.set(`discriminator${i}`, discriminator);
79
- deviceStorage.set(`vendorid${i}`, vendorId);
80
- deviceStorage.set(`productid${i}`, productId);
81
- deviceStorage.set(`isSocket${i}`, isSocket);
82
- deviceStorage.set(`uniqueid${i}`, uniqueId);
83
- const commissioningServer = new import_matter_node.CommissioningServer({
84
- port,
85
- deviceName,
86
- deviceType,
87
- passcode,
88
- discriminator,
89
- basicInformation: {
90
- vendorName,
91
- vendorId: (0, import_datatype.VendorId)(vendorId),
92
- nodeLabel: productName,
93
- productName,
94
- productLabel: productName,
95
- productId,
96
- serialNumber: `node-matter-${uniqueId}`
97
- }
98
- });
99
- console.log(
100
- `Added device ${i} on port ${port} and unique id ${uniqueId}: Passcode: ${passcode}, Discriminator: ${discriminator}`
101
- );
102
- const onOffDevice = (0, import_util.getParameter)(`type${i}`) === "socket" ? new import_device.OnOffPluginUnitDevice() : new import_device.OnOffLightDevice();
103
- onOffDevice.addFixedLabel("orientation", (0, import_util.getParameter)(`orientation${i}`) ?? `orientation ${i}`);
104
- onOffDevice.addOnOffListener((on) => (0, import_util.commandExecutor)(on ? `on${i}` : `off${i}`)?.());
105
- commissioningServer.addDevice(onOffDevice);
106
- this.matterServer.addCommissioningServer(commissioningServer);
107
- commissioningServers.push(commissioningServer);
108
- }
109
- await this.matterServer.start();
110
- logger.info("Listening");
111
- console.log();
112
- commissioningServers.forEach((commissioningServer, index) => {
113
- console.log("----------------------------");
114
- console.log(`Device ${index + 1}:`);
115
- if (!commissioningServer.isCommissioned()) {
116
- const pairingData = commissioningServer.getPairingCode();
117
- const { qrPairingCode, manualPairingCode } = pairingData;
118
- console.log(import_schema.QrCode.get(qrPairingCode));
119
- console.log(
120
- `QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`
121
- );
122
- console.log(`Manual pairing code: ${manualPairingCode}`);
123
- } else {
124
- console.log("Device is already commissioned. Waiting for controllers to connect ...");
125
- }
126
- console.log();
127
- });
128
- }
129
- async stop() {
130
- await this.matterServer?.close();
131
- }
132
- }
133
- const device = new Device();
134
- device.start().then(() => {
135
- }).catch((err) => console.error(err));
136
- process.on("SIGINT", () => {
137
- device.stop().then(() => {
138
- storage.close().then(() => process.exit(0)).catch((err) => console.error(err));
139
- }).catch((err) => console.error(err));
140
- });
141
- //# sourceMappingURL=MultiDeviceNode.js.map
@@ -1 +0,0 @@
1
- { "type": "commonjs" }