@project-chip/matter-node.js-examples 0.6.1-alpha.0-20231031-f3417b3 → 0.6.1-alpha.0-20231102-e09231e
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/esm/examples/BridgedDevicesNode.js +141 -0
- package/dist/{cjs → esm}/examples/BridgedDevicesNode.js.map +1 -1
- package/dist/esm/examples/ComposedDeviceNode.js +138 -0
- package/dist/{cjs → esm}/examples/ComposedDeviceNode.js.map +1 -1
- package/dist/{cjs → esm}/examples/ControllerNode.js +58 -48
- package/dist/{cjs → esm}/examples/ControllerNode.js.map +2 -2
- package/dist/esm/examples/DeviceNode.js +171 -0
- package/dist/esm/examples/DeviceNode.js.map +7 -0
- package/dist/esm/examples/MultiDeviceNode.js +146 -0
- package/dist/{cjs → esm}/examples/MultiDeviceNode.js.map +1 -1
- package/dist/{cjs → esm}/examples/cluster/DummyWifiNetworkCommissioningClusterServer.js +29 -45
- package/dist/{cjs → esm}/examples/cluster/DummyWifiNetworkCommissioningClusterServer.js.map +1 -1
- package/package.json +6 -5
- package/src/examples/DeviceNode.ts +12 -0
- package/src/tsconfig.json +1 -1
- package/dist/cjs/examples/BridgedDevicesNode.js +0 -136
- package/dist/cjs/examples/ComposedDeviceNode.js +0 -133
- package/dist/cjs/examples/DeviceNode.js +0 -175
- package/dist/cjs/examples/DeviceNode.js.map +0 -7
- package/dist/cjs/examples/MultiDeviceNode.js +0 -141
- package/dist/cjs/package.json +0 -1
@@ -186,6 +186,18 @@ class Device {
|
|
186
186
|
serialNumber: `node-matter-${uniqueId}`,
|
187
187
|
},
|
188
188
|
delayedAnnouncement: hasParameter("ble"), // Delay announcement when BLE is used to show how limited advertisement works
|
189
|
+
activeSessionsChangedCallback: fabricIndex => {
|
190
|
+
console.log(
|
191
|
+
`activeSessionsChangedCallback: Active sessions changed on Fabric ${fabricIndex}`,
|
192
|
+
commissioningServer.getActiveSessionInformation(fabricIndex),
|
193
|
+
);
|
194
|
+
},
|
195
|
+
commissioningChangedCallback: fabricIndex => {
|
196
|
+
console.log(
|
197
|
+
`commissioningChangedCallback: Commissioning changed on Fabric ${fabricIndex}`,
|
198
|
+
commissioningServer.getCommissionedFabricInformation(fabricIndex)[0],
|
199
|
+
);
|
200
|
+
},
|
189
201
|
});
|
190
202
|
|
191
203
|
// optionally add a listener for the testEventTrigger command from the GeneralDiagnostics cluster
|
package/src/tsconfig.json
CHANGED
@@ -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,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 The node-matter Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a simple on-off Matter device.\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 { CommissioningServer, MatterServer } from \"@project-chip/matter-node.js\";\n\nimport { BleNode } from \"@project-chip/matter-node-ble.js/ble\";\nimport { Ble } from \"@project-chip/matter-node.js/ble\";\nimport { OnOffLightDevice, OnOffPluginUnitDevice, logEndpoint } from \"@project-chip/matter-node.js/device\";\nimport { Format, Level, Logger } from \"@project-chip/matter-node.js/log\";\nimport { QrCode } from \"@project-chip/matter-node.js/schema\";\nimport { StorageBackendDisk, StorageManager } from \"@project-chip/matter-node.js/storage\";\nimport { Time } from \"@project-chip/matter-node.js/time\";\nimport {\n commandExecutor,\n getIntParameter,\n getParameter,\n hasParameter,\n requireMinNodeVersion,\n singleton,\n} from \"@project-chip/matter-node.js/util\";\nimport { DeviceTypeId, VendorId } from \"@project-chip/matter.js/datatype\";\nimport DummyWifiNetworkCommissioningClusterServer from \"./cluster/DummyWifiNetworkCommissioningClusterServer.js\";\n\nconst logger = Logger.get(\"Device\");\n\nrequireMinNodeVersion(16);\n\n/** Configure logging */\nswitch (getParameter(\"loglevel\")) {\n case \"fatal\":\n Logger.defaultLogLevel = Level.FATAL;\n break;\n case \"error\":\n Logger.defaultLogLevel = Level.ERROR;\n break;\n case \"warn\":\n Logger.defaultLogLevel = Level.WARN;\n break;\n case \"info\":\n Logger.defaultLogLevel = Level.INFO;\n break;\n}\n\nswitch (getParameter(\"logformat\")) {\n case \"plain\":\n Logger.format = Format.PLAIN;\n break;\n case \"html\":\n Logger.format = Format.HTML;\n break;\n default:\n if (process.stdin?.isTTY) Logger.format = Format.ANSI;\n}\n\nif (hasParameter(\"ble\")) {\n // Initialize Ble\n Ble.get = singleton(\n () =>\n new BleNode({\n hciId: getIntParameter(\"ble-hci-id\"),\n }),\n );\n}\n\nconst storageLocation = getParameter(\"store\") ?? \".device-node\";\nconst storage = new StorageBackendDisk(storageLocation, hasParameter(\"clearstorage\"));\nlogger.info(`Storage location: ${storageLocation} (Directory)`);\nlogger.info(\n 'Use the parameter \"-store NAME\" to specify a different storage location, use -clearstorage to start with an empty storage.',\n);\n\nclass Device {\n private matterServer: MatterServer | undefined;\n\n async start() {\n logger.info(`node-matter`);\n\n /**\n * Initialize the storage system.\n *\n * The storage manager is then also used by the Matter server, so this code block in general is required,\n * but you can choose a different storage backend as long as it implements the required API.\n */\n\n const storageManager = new StorageManager(storage);\n await storageManager.initialize();\n\n /**\n * Collect all needed data\n *\n * This block makes sure to collect all needed data from cli or storage. Replace this with where ever your data\n * come from.\n *\n * Note: This example also uses the initialized storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own contexts\n * (so maybe better not ;-)).\n */\n\n const deviceStorage = storageManager.createContext(\"Device\");\n\n if (deviceStorage.has(\"isSocket\")) {\n logger.info(\"Device type found in storage. -type parameter is ignored.\");\n }\n const isSocket = deviceStorage.get(\"isSocket\", getParameter(\"type\") === \"socket\");\n const deviceName = \"Matter test device\";\n const vendorName = \"matter-node.js\";\n const passcode = getIntParameter(\"passcode\") ?? deviceStorage.get(\"passcode\", 20202021);\n const discriminator = getIntParameter(\"discriminator\") ?? deviceStorage.get(\"discriminator\", 3840);\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = getIntParameter(\"vendorid\") ?? deviceStorage.get(\"vendorid\", 0xfff1);\n const productName = `node-matter OnOff ${isSocket ? \"Socket\" : \"Light\"}`;\n const productId = getIntParameter(\"productid\") ?? deviceStorage.get(\"productid\", 0x8000);\n\n const netAnnounceInterface = getParameter(\"announceinterface\");\n const port = getIntParameter(\"port\") ?? 5540;\n\n const uniqueId = getIntParameter(\"uniqueid\") ?? deviceStorage.get(\"uniqueid\", Time.nowMs());\n\n deviceStorage.set(\"passcode\", passcode);\n deviceStorage.set(\"discriminator\", discriminator);\n deviceStorage.set(\"vendorid\", vendorId);\n deviceStorage.set(\"productid\", productId);\n deviceStorage.set(\"isSocket\", isSocket);\n deviceStorage.set(\"uniqueid\", uniqueId);\n\n /**\n * Create Device instance and add needed Listener\n *\n * Create an instance of the matter device class you want to use.\n * This example uses the OnOffLightDevice or OnOffPluginUnitDevice depending on the value of the type parameter.\n * To execute the on/off scripts defined as parameters a listener for the onOff attribute is registered via the\n * device specific API.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled device internally\n * like identify that can be implemented with the logic when these commands are called.\n */\n\n const onOffDevice = isSocket ? new OnOffPluginUnitDevice() : new OnOffLightDevice();\n onOffDevice.addOnOffListener(on => commandExecutor(on ? \"on\" : \"off\")?.());\n\n onOffDevice.addCommandHandler(\"identify\", async ({ request: { identifyTime } }) =>\n logger.info(`Identify called for OnOffDevice: ${identifyTime}`),\n );\n\n /**\n * Create Matter Server and CommissioningServer Node\n *\n * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a\n * commissioningServer to it and add the just created device instance to it.\n * The CommissioningServer node defines the port where the server listens for the UDP packages of the Matter protocol\n * and initializes deice specific certificates and such.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled internally\n * like testEventTrigger (General Diagnostic Cluster) that can be implemented with the logic when these commands\n * are called.\n */\n\n this.matterServer = new MatterServer(storageManager, { mdnsAnnounceInterface: netAnnounceInterface });\n\n const commissioningServer = new CommissioningServer({\n port,\n deviceName,\n deviceType: DeviceTypeId(onOffDevice.deviceType),\n passcode,\n discriminator,\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `node-matter-${uniqueId}`,\n },\n delayedAnnouncement: hasParameter(\"ble\"), // Delay announcement when BLE is used to show how limited advertisement works\n });\n\n // optionally add a listener for the testEventTrigger command from the GeneralDiagnostics cluster\n commissioningServer.addCommandHandler(\"testEventTrigger\", async ({ request: { enableKey, eventTrigger } }) =>\n logger.info(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`),\n );\n\n /**\n * Modify automatically added clusters of the Root endpoint if needed\n * In this example we change the networkCommissioning cluster into one for \"Wifi only\" devices when BLE is used\n * for commissioning, to demonstrate how to do this.\n * If you want to implement Ethernet only devices that get connected to the network via LAN/Ethernet cable,\n * then all this is not needed.\n * The same as shown here for Wi-Fi is also possible theoretical for Thread only or combined devices.\n */\n\n if (hasParameter(\"ble\")) {\n // matter.js will create a Ethernet-only device by default when ut comes to Network Commissioning Features.\n // To offer e.g. a \"Wi-Fi only device\" (or any other combination) we need to override the Network Commissioning\n // cluster and implement all the need handling here. This is a \"static implementation\" for pure demonstration\n // purposes and just \"simulates\" the actions to be done. In a real world implementation this would be done by\n // the device implementor based on the relevant networking stack.\n // The NetworkCommissioningCluster and all logics are described in Matter Core Specifications section 11.8\n commissioningServer.addRootClusterServer(DummyWifiNetworkCommissioningClusterServer);\n }\n\n commissioningServer.addDevice(onOffDevice);\n\n this.matterServer.addCommissioningServer(commissioningServer);\n\n /**\n * Start the Matter Server\n *\n * After everything was plugged together we can start the server. When not delayed announcement is set for the\n * CommissioningServer node then this command also starts the announcement of the device into the network.\n */\n\n await this.matterServer.start();\n\n logEndpoint(commissioningServer.getRootEndpoint());\n\n // When we want to limit the initial announcement to one medium (e.g. BLE) then we need to delay the\n // announcement and provide the limiting information.\n // Without delaying the announcement is directly triggered with the above \"start()\" call.\n if (hasParameter(\"ble\")) {\n // Announce operational in BLE network only if we have ble enabled, else everywhere\n await commissioningServer.advertise({ ble: true });\n }\n\n /**\n * Print Pairing Information\n *\n * If the device is not already commissioned (this info is stored in the storage system) then get and print the\n * pairing details. This includes the QR code that can be scanned by the Matter app to pair the device.\n */\n\n logger.info(\"Listening\");\n if (!commissioningServer.isCommissioned()) {\n const pairingData = commissioningServer.getPairingCode({\n ble: hasParameter(\"ble\"),\n softAccessPoint: false,\n onIpNetwork: false,\n });\n\n const { qrPairingCode, manualPairingCode } = pairingData;\n\n console.log(QrCode.get(qrPairingCode));\n logger.info(\n `QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`,\n );\n logger.info(`Manual pairing code: ${manualPairingCode}`);\n } else {\n logger.info(\"Device is already commissioned. Waiting for controllers to connect ...\");\n }\n }\n\n async stop() {\n await this.matterServer?.close();\n }\n}\n\nconst device = new Device();\ndevice\n .start()\n .then(() => {\n /* done */\n })\n .catch(err => console.error(err));\n\nprocess.on(\"SIGINT\", () => {\n device\n .stop()\n .then(() => {\n // Pragmatic way to make sure the storage is correctly closed before the process ends.\n storage\n .close()\n .then(() => process.exit(0))\n .catch(err => console.error(err));\n })\n .catch(err => console.error(err));\n});\n"],
|
5
|
-
"mappings": "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",
|
6
|
-
"names": ["import_ble", "DummyWifiNetworkCommissioningClusterServer"]
|
7
|
-
}
|
@@ -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
|
package/dist/cjs/package.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{ "type": "commonjs" }
|