@project-chip/matter-node.js-examples 0.5.0 → 0.5.1-alpha.0-20231005-d8f807e
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +7 -1
- package/dist/cjs/examples/BridgedDevicesNode.d.ts +8 -0
- package/dist/cjs/examples/BridgedDevicesNode.d.ts.map +1 -0
- package/dist/cjs/examples/BridgedDevicesNode.js +135 -0
- package/dist/cjs/examples/BridgedDevicesNode.js.map +7 -0
- package/dist/cjs/examples/ComposedDeviceNode.d.ts +8 -0
- package/dist/cjs/examples/ComposedDeviceNode.d.ts.map +1 -0
- package/dist/cjs/examples/ComposedDeviceNode.js +132 -0
- package/dist/cjs/examples/ComposedDeviceNode.js.map +7 -0
- package/dist/cjs/examples/ControllerNode.d.ts +8 -0
- package/dist/cjs/examples/ControllerNode.d.ts.map +1 -0
- package/dist/cjs/examples/ControllerNode.js +172 -0
- package/dist/cjs/examples/ControllerNode.js.map +7 -0
- package/dist/cjs/examples/DeviceNode.d.ts +8 -0
- package/dist/cjs/examples/DeviceNode.d.ts.map +1 -0
- package/dist/cjs/examples/DeviceNode.js +174 -0
- package/dist/cjs/examples/DeviceNode.js.map +7 -0
- package/dist/cjs/examples/MultiDeviceNode.d.ts +8 -0
- package/dist/cjs/examples/MultiDeviceNode.d.ts.map +1 -0
- package/dist/cjs/examples/MultiDeviceNode.js +140 -0
- package/dist/cjs/examples/MultiDeviceNode.js.map +7 -0
- package/dist/cjs/examples/cluster/DummyWifiNetworkCommissioningClusterServer.d.ts +18 -0
- package/dist/cjs/examples/cluster/DummyWifiNetworkCommissioningClusterServer.d.ts.map +1 -0
- package/dist/cjs/examples/cluster/DummyWifiNetworkCommissioningClusterServer.js +166 -0
- package/dist/cjs/examples/cluster/DummyWifiNetworkCommissioningClusterServer.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/package.json +21 -25
- package/src/examples/BridgedDevicesNode.ts +247 -0
- package/src/examples/ComposedDeviceNode.ts +245 -0
- package/src/examples/ControllerNode.ts +294 -0
- package/src/examples/DeviceNode.ts +288 -0
- package/src/examples/MultiDeviceNode.ts +260 -0
- package/src/examples/cluster/DummyWifiNetworkCommissioningClusterServer.ts +181 -0
- package/dist/examples/BridgedDevicesNode.js +0 -218
- package/dist/examples/BridgedDevicesNode.js.map +0 -1
- package/dist/examples/ComposedDeviceNode.js +0 -217
- package/dist/examples/ComposedDeviceNode.js.map +0 -1
- package/dist/examples/ControllerNode.js +0 -261
- package/dist/examples/ControllerNode.js.map +0 -1
- package/dist/examples/DeviceNode.js +0 -358
- package/dist/examples/DeviceNode.js.map +0 -1
- package/dist/examples/MultiDeviceNode.js +0 -228
- package/dist/examples/MultiDeviceNode.js.map +0 -1
package/README.md
CHANGED
@@ -68,6 +68,8 @@ npm run matter-device -- -type socket -on "echo 255 > /sys/class/leds/led1/brigh
|
|
68
68
|
```
|
69
69
|
(Please note the "--" to separate commandline parameters between the npm run and the executed script.
|
70
70
|
|
71
|
+
**If you want to start multiple parallel processes please make sure to use different storage locations, different network port and ideally also different passcodes for each process!**
|
72
|
+
|
71
73
|
The following parameters are available:
|
72
74
|
* -passcode: the passcode to use for pairing (default: 20202021)
|
73
75
|
* -discriminator: the discriminator to use for pairing (default: 3840, value between 0 and 4095)
|
@@ -93,7 +95,9 @@ Additionally, there are some Testing parameters:
|
|
93
95
|
|
94
96
|
A Bridge is used to expose multiple devices at once.
|
95
97
|
|
96
|
-
The usage and parameter are comparable to above
|
98
|
+
The usage and parameter are comparable to above, but the bridge adds support for multiple types and on/off commands:
|
99
|
+
|
100
|
+
**If you want to start multiple parallel processes please make sure to use different storage locations, different network port and ideally also different passcodes for each process!**
|
97
101
|
|
98
102
|
The usage is as above but with modified parameters:
|
99
103
|
* -num X: number of devices to expose (default 2)
|
@@ -158,6 +162,8 @@ npm run matter-multidevice -- -type socket -num 2 -on1 "echo 255 > /sys/class/le
|
|
158
162
|
|
159
163
|
The above command exposes two single light devices (one socket and on light) and executes the respective commands when the devices are turned on or off.
|
160
164
|
|
165
|
+
**If you want to start multiple parallel processes please make sure to use different storage locations, different network port and ideally also different passcodes for each process!**
|
166
|
+
|
161
167
|
### Start a Matter Controller
|
162
168
|
|
163
169
|
> The code for this example is in [src/examples/ControllerNode.ts](./src/examples/ControllerNode.ts).
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"BridgedDevicesNode.d.ts","sourceRoot":"","sources":["../../../src/examples/BridgedDevicesNode.ts"],"names":[],"mappings":";AACA;;;;GAIG"}
|
@@ -0,0 +1,135 @@
|
|
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_storage = require("@project-chip/matter-node.js/storage");
|
7
|
+
var import_time = require("@project-chip/matter-node.js/time");
|
8
|
+
var import_util = require("@project-chip/matter-node.js/util");
|
9
|
+
var import_datatype = require("@project-chip/matter.js/datatype");
|
10
|
+
/**
|
11
|
+
* @license
|
12
|
+
* Copyright 2022 The node-matter Authors
|
13
|
+
* SPDX-License-Identifier: Apache-2.0
|
14
|
+
*/
|
15
|
+
const logger = import_log.Logger.get("Device");
|
16
|
+
(0, import_util.requireMinNodeVersion)(16);
|
17
|
+
switch ((0, import_util.getParameter)("loglevel")) {
|
18
|
+
case "fatal":
|
19
|
+
import_log.Logger.defaultLogLevel = import_log.Level.FATAL;
|
20
|
+
break;
|
21
|
+
case "error":
|
22
|
+
import_log.Logger.defaultLogLevel = import_log.Level.ERROR;
|
23
|
+
break;
|
24
|
+
case "warn":
|
25
|
+
import_log.Logger.defaultLogLevel = import_log.Level.WARN;
|
26
|
+
break;
|
27
|
+
case "info":
|
28
|
+
import_log.Logger.defaultLogLevel = import_log.Level.INFO;
|
29
|
+
break;
|
30
|
+
}
|
31
|
+
switch ((0, import_util.getParameter)("logformat")) {
|
32
|
+
case "plain":
|
33
|
+
import_log.Logger.format = import_log.Format.PLAIN;
|
34
|
+
break;
|
35
|
+
case "html":
|
36
|
+
import_log.Logger.format = import_log.Format.HTML;
|
37
|
+
break;
|
38
|
+
default:
|
39
|
+
if (process.stdin?.isTTY)
|
40
|
+
import_log.Logger.format = import_log.Format.ANSI;
|
41
|
+
}
|
42
|
+
const storageLocation = (0, import_util.getParameter)("store") ?? ".device-node";
|
43
|
+
const storage = new import_storage.StorageBackendDisk(storageLocation, (0, import_util.hasParameter)("clearstorage"));
|
44
|
+
logger.info(`Storage location: ${storageLocation} (Directory)`);
|
45
|
+
logger.info(
|
46
|
+
'Use the parameter "-store NAME" to specify a different storage location, use -clearstorage to start with an empty storage.'
|
47
|
+
);
|
48
|
+
class BridgedDevice {
|
49
|
+
async start() {
|
50
|
+
logger.info(`node-matter`);
|
51
|
+
const storageManager = new import_storage.StorageManager(storage);
|
52
|
+
await storageManager.initialize();
|
53
|
+
const deviceStorage = storageManager.createContext("Device");
|
54
|
+
const deviceName = "Matter Bridge device";
|
55
|
+
const deviceType = import_device.DeviceTypes.AGGREGATOR.code;
|
56
|
+
const vendorName = "matter-node.js";
|
57
|
+
const passcode = (0, import_util.getIntParameter)("passcode") ?? deviceStorage.get("passcode", 20202021);
|
58
|
+
const discriminator = (0, import_util.getIntParameter)("discriminator") ?? deviceStorage.get("discriminator", 3840);
|
59
|
+
const vendorId = (0, import_util.getIntParameter)("vendorid") ?? deviceStorage.get("vendorid", 65521);
|
60
|
+
const productName = `node-matter OnOff-Bridge`;
|
61
|
+
const productId = (0, import_util.getIntParameter)("productid") ?? deviceStorage.get("productid", 32768);
|
62
|
+
const netAnnounceInterface = (0, import_util.getParameter)("announceinterface");
|
63
|
+
const port = (0, import_util.getIntParameter)("port") ?? 5540;
|
64
|
+
const uniqueId = (0, import_util.getIntParameter)("uniqueid") ?? deviceStorage.get("uniqueid", import_time.Time.nowMs());
|
65
|
+
deviceStorage.set("passcode", passcode);
|
66
|
+
deviceStorage.set("discriminator", discriminator);
|
67
|
+
deviceStorage.set("vendorid", vendorId);
|
68
|
+
deviceStorage.set("productid", productId);
|
69
|
+
deviceStorage.set("uniqueid", uniqueId);
|
70
|
+
this.matterServer = new import_matter_node.MatterServer(storageManager, { mdnsAnnounceInterface: netAnnounceInterface });
|
71
|
+
const commissioningServer = new import_matter_node.CommissioningServer({
|
72
|
+
port,
|
73
|
+
deviceName,
|
74
|
+
deviceType,
|
75
|
+
passcode,
|
76
|
+
discriminator,
|
77
|
+
basicInformation: {
|
78
|
+
vendorName,
|
79
|
+
vendorId: (0, import_datatype.VendorId)(vendorId),
|
80
|
+
nodeLabel: productName,
|
81
|
+
productName,
|
82
|
+
productLabel: productName,
|
83
|
+
productId,
|
84
|
+
serialNumber: `node-matter-${uniqueId}`
|
85
|
+
}
|
86
|
+
});
|
87
|
+
const aggregator = new import_device.Aggregator();
|
88
|
+
const numDevices = (0, import_util.getIntParameter)("num") || 2;
|
89
|
+
for (let i = 1; i <= numDevices; i++) {
|
90
|
+
const onOffDevice = (0, import_util.getParameter)(`type${i}`) === "socket" ? new import_device.OnOffPluginUnitDevice() : new import_device.OnOffLightDevice();
|
91
|
+
onOffDevice.addOnOffListener((on) => (0, import_util.commandExecutor)(on ? `on${i}` : `off${i}`)?.());
|
92
|
+
onOffDevice.addCommandHandler(
|
93
|
+
"identify",
|
94
|
+
async ({ request: { identifyTime } }) => console.log(
|
95
|
+
`Identify called for OnOffDevice ${onOffDevice.name} with id: ${i} and identifyTime: ${identifyTime}`
|
96
|
+
)
|
97
|
+
);
|
98
|
+
const name = `OnOff ${onOffDevice instanceof import_device.OnOffPluginUnitDevice ? "Socket" : "Light"} ${i}`;
|
99
|
+
aggregator.addBridgedDevice(onOffDevice, {
|
100
|
+
nodeLabel: name,
|
101
|
+
productName: name,
|
102
|
+
productLabel: name,
|
103
|
+
serialNumber: `node-matter-${uniqueId}-${i}`,
|
104
|
+
reachable: true
|
105
|
+
});
|
106
|
+
}
|
107
|
+
commissioningServer.addDevice(aggregator);
|
108
|
+
this.matterServer.addCommissioningServer(commissioningServer);
|
109
|
+
await this.matterServer.start();
|
110
|
+
logger.info("Listening");
|
111
|
+
if (!commissioningServer.isCommissioned()) {
|
112
|
+
const pairingData = commissioningServer.getPairingCode();
|
113
|
+
const { qrCode, qrPairingCode, manualPairingCode } = pairingData;
|
114
|
+
console.log(qrCode);
|
115
|
+
console.log(
|
116
|
+
`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`
|
117
|
+
);
|
118
|
+
console.log(`Manual pairing code: ${manualPairingCode}`);
|
119
|
+
} else {
|
120
|
+
console.log("Device is already commissioned. Waiting for controllers to connect ...");
|
121
|
+
}
|
122
|
+
}
|
123
|
+
async stop() {
|
124
|
+
await this.matterServer?.close();
|
125
|
+
}
|
126
|
+
}
|
127
|
+
const device = new BridgedDevice();
|
128
|
+
device.start().then(() => {
|
129
|
+
}).catch((err) => console.error(err));
|
130
|
+
process.on("SIGINT", () => {
|
131
|
+
device.stop().then(() => {
|
132
|
+
storage.close().then(() => process.exit(0)).catch((err) => console.error(err));
|
133
|
+
}).catch((err) => console.error(err));
|
134
|
+
});
|
135
|
+
//# sourceMappingURL=BridgedDevicesNode.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["../../../src/examples/BridgedDevicesNode.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 device bridge that exposed multiple devices.\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 { Aggregator, DeviceTypes, OnOffLightDevice, OnOffPluginUnitDevice } from \"@project-chip/matter-node.js/device\";\nimport { Format, Level, Logger } from \"@project-chip/matter-node.js/log\";\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} from \"@project-chip/matter-node.js/util\";\nimport { VendorId } from \"@project-chip/matter.js/datatype\";\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\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 BridgedDevice {\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 const deviceName = \"Matter Bridge device\";\n const deviceType = DeviceTypes.AGGREGATOR.code;\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-Bridge`;\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(\"uniqueid\", uniqueId);\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,\n passcode,\n discriminator,\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `node-matter-${uniqueId}`,\n },\n });\n\n /**\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 aggregator = new Aggregator();\n\n const numDevices = getIntParameter(\"num\") || 2;\n for (let i = 1; i <= numDevices; i++) {\n const onOffDevice =\n getParameter(`type${i}`) === \"socket\" ? new OnOffPluginUnitDevice() : new OnOffLightDevice();\n\n onOffDevice.addOnOffListener(on => commandExecutor(on ? `on${i}` : `off${i}`)?.());\n onOffDevice.addCommandHandler(\"identify\", async ({ request: { identifyTime } }) =>\n console.log(\n `Identify called for OnOffDevice ${onOffDevice.name} with id: ${i} and identifyTime: ${identifyTime}`,\n ),\n );\n\n const name = `OnOff ${onOffDevice instanceof OnOffPluginUnitDevice ? \"Socket\" : \"Light\"} ${i}`;\n aggregator.addBridgedDevice(onOffDevice, {\n nodeLabel: name,\n productName: name,\n productLabel: name,\n serialNumber: `node-matter-${uniqueId}-${i}`,\n reachable: true,\n });\n }\n\n commissioningServer.addDevice(aggregator);\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 /**\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 const { qrCode, qrPairingCode, manualPairingCode } = pairingData;\n\n console.log(qrCode);\n console.log(\n `QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`,\n );\n console.log(`Manual pairing code: ${manualPairingCode}`);\n } else {\n console.log(\"Device is already commissioned. Waiting for controllers to connect ...\");\n }\n }\n\n async stop() {\n await this.matterServer?.close();\n }\n}\n\nconst device = new BridgedDevice();\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": ";;AAgBA,yBAAkD;AAElD,oBAAiF;AACjF,iBAAsC;AACtC,qBAAmD;AACnD,kBAAqB;AACrB,kBAMO;AACP,sBAAyB;AA5BzB;AAAA;AAAA;AAAA;AAAA;AA8BA,MAAM,SAAS,kBAAO,IAAI,QAAQ;AAAA,IAElC,mCAAsB,EAAE;AAGxB,YAAQ,0BAAa,UAAU,GAAG;AAAA,EAC9B,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AAAA,EACJ,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AAAA,EACJ,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AAAA,EACJ,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AACR;AAEA,YAAQ,0BAAa,WAAW,GAAG;AAAA,EAC/B,KAAK;AACD,sBAAO,SAAS,kBAAO;AACvB;AAAA,EACJ,KAAK;AACD,sBAAO,SAAS,kBAAO;AACvB;AAAA,EACJ;AACI,QAAI,QAAQ,OAAO;AAAO,wBAAO,SAAS,kBAAO;AACzD;AAEA,MAAM,sBAAkB,0BAAa,OAAO,KAAK;AACjD,MAAM,UAAU,IAAI,kCAAmB,qBAAiB,0BAAa,cAAc,CAAC;AACpF,OAAO,KAAK,qBAAqB,eAAe,cAAc;AAC9D,OAAO;AAAA,EACH;AACJ;AAEA,MAAM,cAAc;AAAA,EAGhB,MAAM,QAAQ;AACV,WAAO,KAAK,aAAa;AASzB,UAAM,iBAAiB,IAAI,8BAAe,OAAO;AACjD,UAAM,eAAe,WAAW;AAahC,UAAM,gBAAgB,eAAe,cAAc,QAAQ;AAE3D,UAAM,aAAa;AACnB,UAAM,aAAa,0BAAY,WAAW;AAC1C,UAA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,MAAM,GAAG,CAAC;AACxC,CAAC;",
|
6
|
+
"names": []
|
7
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ComposedDeviceNode.d.ts","sourceRoot":"","sources":["../../../src/examples/ComposedDeviceNode.ts"],"names":[],"mappings":";AACA;;;;GAIG"}
|
@@ -0,0 +1,132 @@
|
|
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_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
|
+
/**
|
11
|
+
* @license
|
12
|
+
* Copyright 2022 The node-matter Authors
|
13
|
+
* SPDX-License-Identifier: Apache-2.0
|
14
|
+
*/
|
15
|
+
const logger = import_log.Logger.get("Device");
|
16
|
+
(0, import_util.requireMinNodeVersion)(16);
|
17
|
+
switch ((0, import_util.getParameter)("loglevel")) {
|
18
|
+
case "fatal":
|
19
|
+
import_log.Logger.defaultLogLevel = import_log.Level.FATAL;
|
20
|
+
break;
|
21
|
+
case "error":
|
22
|
+
import_log.Logger.defaultLogLevel = import_log.Level.ERROR;
|
23
|
+
break;
|
24
|
+
case "warn":
|
25
|
+
import_log.Logger.defaultLogLevel = import_log.Level.WARN;
|
26
|
+
break;
|
27
|
+
case "info":
|
28
|
+
import_log.Logger.defaultLogLevel = import_log.Level.INFO;
|
29
|
+
break;
|
30
|
+
}
|
31
|
+
switch ((0, import_util.getParameter)("logformat")) {
|
32
|
+
case "plain":
|
33
|
+
import_log.Logger.format = import_log.Format.PLAIN;
|
34
|
+
break;
|
35
|
+
case "html":
|
36
|
+
import_log.Logger.format = import_log.Format.HTML;
|
37
|
+
break;
|
38
|
+
default:
|
39
|
+
if (process.stdin?.isTTY)
|
40
|
+
import_log.Logger.format = import_log.Format.ANSI;
|
41
|
+
}
|
42
|
+
const storageLocation = (0, import_util.getParameter)("store") ?? ".device-node";
|
43
|
+
const storage = new import_storage.StorageBackendDisk(storageLocation, (0, import_util.hasParameter)("clearstorage"));
|
44
|
+
logger.info(`Storage location: ${storageLocation} (Directory)`);
|
45
|
+
logger.info(
|
46
|
+
'Use the parameter "-store NAME" to specify a different storage location, use -clearstorage to start with an empty storage.'
|
47
|
+
);
|
48
|
+
class ComposedDevice {
|
49
|
+
async start() {
|
50
|
+
logger.info(`node-matter`);
|
51
|
+
const storageManager = new import_storage.StorageManager(storage);
|
52
|
+
await storageManager.initialize();
|
53
|
+
const deviceStorage = storageManager.createContext("Device");
|
54
|
+
if (deviceStorage.has("isSocket")) {
|
55
|
+
logger.info("Device type found in storage. -type parameter is ignored.");
|
56
|
+
}
|
57
|
+
const isSocket = deviceStorage.get("isSocket", (0, import_util.getParameter)("type") === "socket");
|
58
|
+
const deviceName = "Matter composed device";
|
59
|
+
const deviceType = (0, import_util.getParameter)("type") === "socket" ? import_device.DeviceTypes.ON_OFF_PLUGIN_UNIT.code : import_device.DeviceTypes.ON_OFF_LIGHT.code;
|
60
|
+
const vendorName = "matter-node.js";
|
61
|
+
const passcode = (0, import_util.getIntParameter)("passcode") ?? deviceStorage.get("passcode", 20202021);
|
62
|
+
const discriminator = (0, import_util.getIntParameter)("discriminator") ?? deviceStorage.get("discriminator", 3840);
|
63
|
+
const vendorId = (0, import_util.getIntParameter)("vendorid") ?? deviceStorage.get("vendorid", 65521);
|
64
|
+
const productName = `node-matter OnOff-Bridge`;
|
65
|
+
const productId = (0, import_util.getIntParameter)("productid") ?? deviceStorage.get("productid", 32768);
|
66
|
+
const netAnnounceInterface = (0, import_util.getParameter)("announceinterface");
|
67
|
+
const port = (0, import_util.getIntParameter)("port") ?? 5540;
|
68
|
+
const uniqueId = (0, import_util.getIntParameter)("uniqueid") ?? deviceStorage.get("uniqueid", import_time.Time.nowMs());
|
69
|
+
deviceStorage.set("passcode", passcode);
|
70
|
+
deviceStorage.set("discriminator", discriminator);
|
71
|
+
deviceStorage.set("vendorid", vendorId);
|
72
|
+
deviceStorage.set("productid", productId);
|
73
|
+
deviceStorage.set("isSocket", isSocket);
|
74
|
+
deviceStorage.set("uniqueid", uniqueId);
|
75
|
+
this.matterServer = new import_matter_node.MatterServer(storageManager, { mdnsAnnounceInterface: netAnnounceInterface });
|
76
|
+
const commissioningServer = new import_matter_node.CommissioningServer({
|
77
|
+
port,
|
78
|
+
deviceName,
|
79
|
+
deviceType,
|
80
|
+
passcode,
|
81
|
+
discriminator,
|
82
|
+
basicInformation: {
|
83
|
+
vendorName,
|
84
|
+
vendorId: (0, import_datatype.VendorId)(vendorId),
|
85
|
+
nodeLabel: productName,
|
86
|
+
productName,
|
87
|
+
productLabel: productName,
|
88
|
+
productId,
|
89
|
+
serialNumber: `node-matter-${uniqueId}`
|
90
|
+
}
|
91
|
+
});
|
92
|
+
const numDevices = (0, import_util.getIntParameter)("num") || 2;
|
93
|
+
for (let i = 1; i <= numDevices; i++) {
|
94
|
+
const onOffDevice = (0, import_util.getParameter)(`type${i}`) === "socket" ? new import_device.OnOffPluginUnitDevice() : new import_device.OnOffLightDevice();
|
95
|
+
onOffDevice.addFixedLabel("orientation", (0, import_util.getParameter)(`orientation${i}`) ?? `orientation ${i}`);
|
96
|
+
onOffDevice.addOnOffListener((on) => (0, import_util.commandExecutor)(on ? `on${i}` : `off${i}`)?.());
|
97
|
+
onOffDevice.addCommandHandler(
|
98
|
+
"identify",
|
99
|
+
async ({ request: { identifyTime } }) => console.log(
|
100
|
+
`Identify called for OnOffDevice ${onOffDevice.name} with id: ${i} and identifyTime: ${identifyTime}`
|
101
|
+
)
|
102
|
+
);
|
103
|
+
commissioningServer.addDevice(onOffDevice);
|
104
|
+
}
|
105
|
+
this.matterServer.addCommissioningServer(commissioningServer);
|
106
|
+
await this.matterServer.start();
|
107
|
+
logger.info("Listening");
|
108
|
+
if (!commissioningServer.isCommissioned()) {
|
109
|
+
const pairingData = commissioningServer.getPairingCode();
|
110
|
+
const { qrCode, qrPairingCode, manualPairingCode } = pairingData;
|
111
|
+
console.log(qrCode);
|
112
|
+
console.log(
|
113
|
+
`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`
|
114
|
+
);
|
115
|
+
console.log(`Manual pairing code: ${manualPairingCode}`);
|
116
|
+
} else {
|
117
|
+
console.log("Device is already commissioned. Waiting for controllers to connect ...");
|
118
|
+
}
|
119
|
+
}
|
120
|
+
async stop() {
|
121
|
+
await this.matterServer?.close();
|
122
|
+
}
|
123
|
+
}
|
124
|
+
const device = new ComposedDevice();
|
125
|
+
device.start().then(() => {
|
126
|
+
}).catch((err) => console.error(err));
|
127
|
+
process.on("SIGINT", () => {
|
128
|
+
device.stop().then(() => {
|
129
|
+
storage.close().then(() => process.exit(0)).catch((err) => console.error(err));
|
130
|
+
}).catch((err) => console.error(err));
|
131
|
+
});
|
132
|
+
//# sourceMappingURL=ComposedDeviceNode.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["../../../src/examples/ComposedDeviceNode.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 new device node that is composed of multiple devices.\n * It creates multiple endpoints on the server. When you want to add a composed devices to a Aggregator you need to\n * add all endpoints of the composed device to an \"ComposedDevice\" instance! (not shown in this example).\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport { CommissioningServer, MatterServer } from \"@project-chip/matter-node.js\";\n\nimport { VendorId } from \"@project-chip/matter-node.js/datatype\";\nimport { DeviceTypes, OnOffLightDevice, OnOffPluginUnitDevice } from \"@project-chip/matter-node.js/device\";\nimport { Format, Level, Logger } from \"@project-chip/matter-node.js/log\";\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} from \"@project-chip/matter-node.js/util\";\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\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 ComposedDevice {\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 composed device\";\n const deviceType =\n getParameter(\"type\") === \"socket\" ? DeviceTypes.ON_OFF_PLUGIN_UNIT.code : DeviceTypes.ON_OFF_LIGHT.code;\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-Bridge`;\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 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,\n passcode,\n discriminator,\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `node-matter-${uniqueId}`,\n },\n });\n\n /**\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 numDevices = getIntParameter(\"num\") || 2;\n for (let i = 1; i <= numDevices; i++) {\n const onOffDevice =\n getParameter(`type${i}`) === \"socket\" ? new OnOffPluginUnitDevice() : new OnOffLightDevice();\n onOffDevice.addFixedLabel(\"orientation\", getParameter(`orientation${i}`) ?? `orientation ${i}`);\n\n onOffDevice.addOnOffListener(on => commandExecutor(on ? `on${i}` : `off${i}`)?.());\n onOffDevice.addCommandHandler(\"identify\", async ({ request: { identifyTime } }) =>\n console.log(\n `Identify called for OnOffDevice ${onOffDevice.name} with id: ${i} and identifyTime: ${identifyTime}`,\n ),\n );\n\n commissioningServer.addDevice(onOffDevice);\n }\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 /**\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 const { qrCode, qrPairingCode, manualPairingCode } = pairingData;\n\n console.log(qrCode);\n console.log(\n `QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`,\n );\n console.log(`Manual pairing code: ${manualPairingCode}`);\n } else {\n console.log(\"Device is already commissioned. Waiting for controllers to connect ...\");\n }\n }\n\n async stop() {\n await this.matterServer?.close();\n }\n}\n\nconst device = new ComposedDevice();\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": ";;AAkBA,yBAAkD;AAElD,sBAAyB;AACzB,oBAAqE;AACrE,iBAAsC;AACtC,qBAAmD;AACnD,kBAAqB;AACrB,kBAMO;AA9BP;AAAA;AAAA;AAAA;AAAA;AAgCA,MAAM,SAAS,kBAAO,IAAI,QAAQ;AAAA,IAElC,mCAAsB,EAAE;AAGxB,YAAQ,0BAAa,UAAU,GAAG;AAAA,EAC9B,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AAAA,EACJ,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AAAA,EACJ,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AAAA,EACJ,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AACR;AAEA,YAAQ,0BAAa,WAAW,GAAG;AAAA,EAC/B,KAAK;AACD,sBAAO,SAAS,kBAAO;AACvB;AAAA,EACJ,KAAK;AACD,sBAAO,SAAS,kBAAO;AACvB;AAAA,EACJ;AACI,QAAI,QAAQ,OAAO;AAAO,wBAAO,SAAS,kBAAO;AACzD;AAEA,MAAM,sBAAkB,0BAAa,OAAO,KAAK;AACjD,MAAM,UAAU,IAAI,kCAAmB,qBAAiB,0BAAa,cAAc,CAAC;AACpF,OAAO,KAAK,qBAAqB,eAAe,cAAc;AAC9D,OAAO;AAAA,EACH;AACJ;AAEA,MAAM,eAAe;AAAA,EAGjB,MAAM,QAAQ;AACV,WAAO,KAAK,aAAa;AASzB,UAAM,iBAAiB,IAAI,8BAAe,O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,SACK,KAAK,EACL,KAAK,MAAM;AAER,YACK,MAAM,EACN,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC,EAC1B,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AAAA,EACxC,CAAC,EACA,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AACxC,CAAC;",
|
6
|
+
"names": []
|
7
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ControllerNode.d.ts","sourceRoot":"","sources":["../../../src/examples/ControllerNode.ts"],"names":[],"mappings":";AAEA;;;;GAIG"}
|
@@ -0,0 +1,172 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
var import_matter_node = require("@project-chip/matter-node.js");
|
4
|
+
var import_ble = require("@project-chip/matter-node-ble.js/ble");
|
5
|
+
var import_ble2 = require("@project-chip/matter-node.js/ble");
|
6
|
+
var import_cluster = require("@project-chip/matter-node.js/cluster");
|
7
|
+
var import_device = require("@project-chip/matter-node.js/device");
|
8
|
+
var import_log = require("@project-chip/matter-node.js/log");
|
9
|
+
var import_schema = require("@project-chip/matter-node.js/schema");
|
10
|
+
var import_storage = require("@project-chip/matter-node.js/storage");
|
11
|
+
var import_util = require("@project-chip/matter-node.js/util");
|
12
|
+
/**
|
13
|
+
* @license
|
14
|
+
* Copyright 2022-2023 Project CHIP Authors
|
15
|
+
* SPDX-License-Identifier: Apache-2.0
|
16
|
+
*/
|
17
|
+
const logger = import_log.Logger.get("Controller");
|
18
|
+
(0, import_util.requireMinNodeVersion)(16);
|
19
|
+
switch ((0, import_util.getParameter)("loglevel")) {
|
20
|
+
case "fatal":
|
21
|
+
import_log.Logger.defaultLogLevel = import_log.Level.FATAL;
|
22
|
+
break;
|
23
|
+
case "error":
|
24
|
+
import_log.Logger.defaultLogLevel = import_log.Level.ERROR;
|
25
|
+
break;
|
26
|
+
case "warn":
|
27
|
+
import_log.Logger.defaultLogLevel = import_log.Level.WARN;
|
28
|
+
break;
|
29
|
+
case "info":
|
30
|
+
import_log.Logger.defaultLogLevel = import_log.Level.INFO;
|
31
|
+
break;
|
32
|
+
}
|
33
|
+
switch ((0, import_util.getParameter)("logformat")) {
|
34
|
+
case "plain":
|
35
|
+
import_log.Logger.format = import_log.Format.PLAIN;
|
36
|
+
break;
|
37
|
+
case "html":
|
38
|
+
import_log.Logger.format = import_log.Format.HTML;
|
39
|
+
break;
|
40
|
+
default:
|
41
|
+
if (process.stdin?.isTTY)
|
42
|
+
import_log.Logger.format = import_log.Format.ANSI;
|
43
|
+
}
|
44
|
+
if ((0, import_util.hasParameter)("ble")) {
|
45
|
+
import_ble2.Ble.get = (0, import_util.singleton)(
|
46
|
+
() => new import_ble.BleNode({
|
47
|
+
hciId: (0, import_util.getIntParameter)("ble-hci-id")
|
48
|
+
})
|
49
|
+
);
|
50
|
+
}
|
51
|
+
const storageLocation = (0, import_util.getParameter)("store") ?? ".controller-node";
|
52
|
+
const storage = new import_storage.StorageBackendDisk(storageLocation, (0, import_util.hasParameter)("clearstorage"));
|
53
|
+
logger.info(`Storage location: ${storageLocation} (Directory)`);
|
54
|
+
logger.info(
|
55
|
+
'Use the parameter "-store NAME" to specify a different storage location, use -clearstorage to start with an empty storage.'
|
56
|
+
);
|
57
|
+
class ControllerNode {
|
58
|
+
async start() {
|
59
|
+
logger.info(`node-matter Controller started`);
|
60
|
+
const storageManager = new import_storage.StorageManager(storage);
|
61
|
+
await storageManager.initialize();
|
62
|
+
const controllerStorage = storageManager.createContext("Controller");
|
63
|
+
const ip = controllerStorage.has("ip") ? controllerStorage.get("ip") : (0, import_util.getParameter)("ip");
|
64
|
+
const port = controllerStorage.has("port") ? controllerStorage.get("port") : (0, import_util.getIntParameter)("port");
|
65
|
+
const pairingCode = (0, import_util.getParameter)("pairingcode");
|
66
|
+
let longDiscriminator, setupPin, shortDiscriminator;
|
67
|
+
if (pairingCode !== void 0) {
|
68
|
+
const pairingCodeCodec = import_schema.ManualPairingCodeCodec.decode(pairingCode);
|
69
|
+
shortDiscriminator = pairingCodeCodec.shortDiscriminator;
|
70
|
+
longDiscriminator = void 0;
|
71
|
+
setupPin = pairingCodeCodec.passcode;
|
72
|
+
logger.debug(`Data extracted from pairing code: ${import_log.Logger.toJSON(pairingCodeCodec)}`);
|
73
|
+
} else {
|
74
|
+
longDiscriminator = (0, import_util.getIntParameter)("longDiscriminator") ?? controllerStorage.get("longDiscriminator", 3840);
|
75
|
+
if (longDiscriminator > 4095)
|
76
|
+
throw new Error("Discriminator value must be less than 4096");
|
77
|
+
setupPin = (0, import_util.getIntParameter)("pin") ?? controllerStorage.get("pin", 20202021);
|
78
|
+
}
|
79
|
+
if (shortDiscriminator === void 0 && longDiscriminator === void 0 || setupPin === void 0) {
|
80
|
+
throw new Error(
|
81
|
+
"Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode"
|
82
|
+
);
|
83
|
+
}
|
84
|
+
const commissioningOptions = {
|
85
|
+
regulatoryLocation: import_cluster.GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,
|
86
|
+
regulatoryCountryCode: "XX"
|
87
|
+
};
|
88
|
+
if ((0, import_util.hasParameter)("ble")) {
|
89
|
+
const wifiSsid = (0, import_util.getParameter)("ble-wifi-ssid");
|
90
|
+
const wifiCredentials = (0, import_util.getParameter)("ble-wifi-credentials");
|
91
|
+
const threadNetworkName = (0, import_util.getParameter)("ble-thread-networkname");
|
92
|
+
const threadOperationalDataset = (0, import_util.getParameter)("ble-thread-operationaldataset");
|
93
|
+
if (wifiSsid !== void 0 && wifiCredentials !== void 0) {
|
94
|
+
logger.info(`Registering Commissioning over BLE with WiFi: ${wifiSsid}`);
|
95
|
+
commissioningOptions.wifiNetwork = {
|
96
|
+
wifiSsid,
|
97
|
+
wifiCredentials
|
98
|
+
};
|
99
|
+
}
|
100
|
+
if (threadNetworkName !== void 0 && threadOperationalDataset !== void 0) {
|
101
|
+
logger.info(`Registering Commissioning over BLE with Thread: ${threadNetworkName}`);
|
102
|
+
commissioningOptions.threadNetwork = {
|
103
|
+
networkName: threadNetworkName,
|
104
|
+
operationalDataset: threadOperationalDataset
|
105
|
+
};
|
106
|
+
}
|
107
|
+
}
|
108
|
+
const matterServer = new import_matter_node.MatterServer(storageManager);
|
109
|
+
const commissioningController = new import_matter_node.CommissioningController({
|
110
|
+
serverAddress: ip !== void 0 && port !== void 0 ? { ip, port, type: "udp" } : void 0,
|
111
|
+
longDiscriminator,
|
112
|
+
shortDiscriminator,
|
113
|
+
passcode: setupPin,
|
114
|
+
delayedPairing: true,
|
115
|
+
commissioningOptions,
|
116
|
+
subscribeAllAttributes: true
|
117
|
+
});
|
118
|
+
matterServer.addCommissioningController(commissioningController);
|
119
|
+
await matterServer.start();
|
120
|
+
try {
|
121
|
+
await commissioningController.connect();
|
122
|
+
if (commissioningController.serverAddress !== void 0) {
|
123
|
+
const { ip: ip2, port: port2 } = commissioningController.serverAddress;
|
124
|
+
controllerStorage.set("ip", ip2);
|
125
|
+
controllerStorage.set("port", port2);
|
126
|
+
}
|
127
|
+
if (longDiscriminator !== void 0) {
|
128
|
+
controllerStorage.set("longDiscriminator", longDiscriminator);
|
129
|
+
}
|
130
|
+
controllerStorage.set("pin", setupPin);
|
131
|
+
(0, import_device.logEndpoint)(commissioningController.getRootEndpoint());
|
132
|
+
const descriptor = commissioningController.getRootClusterClient(import_cluster.DescriptorCluster);
|
133
|
+
if (descriptor !== void 0) {
|
134
|
+
console.log(await descriptor.attributes.deviceTypeList.get());
|
135
|
+
console.log(await descriptor.getServerListAttribute());
|
136
|
+
} else {
|
137
|
+
console.log("No Descriptor Cluster found. This should never happen!");
|
138
|
+
}
|
139
|
+
const info = commissioningController.getRootClusterClient(import_cluster.BasicInformationCluster);
|
140
|
+
if (info !== void 0) {
|
141
|
+
console.log(await info.getProductNameAttribute());
|
142
|
+
} else {
|
143
|
+
console.log("No BasicInformation Cluster found. This should never happen!");
|
144
|
+
}
|
145
|
+
const devices = commissioningController.getDevices();
|
146
|
+
if (devices[0] && devices[0].id === 1) {
|
147
|
+
const onOff = devices[0].getClusterClient(import_cluster.OnOffCluster);
|
148
|
+
if (onOff !== void 0) {
|
149
|
+
let onOffStatus = await onOff.getOnOffAttribute();
|
150
|
+
console.log("initial onOffStatus", onOffStatus);
|
151
|
+
onOff.addOnOffAttributeListener((value) => {
|
152
|
+
console.log("subscription onOffStatus", value);
|
153
|
+
onOffStatus = value;
|
154
|
+
});
|
155
|
+
setInterval(() => {
|
156
|
+
onOff.toggle().then(() => {
|
157
|
+
onOffStatus = !onOffStatus;
|
158
|
+
console.log("onOffStatus", onOffStatus);
|
159
|
+
}).catch((error) => logger.error(error));
|
160
|
+
}, 6e4);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
} finally {
|
164
|
+
setTimeout(() => process.exit(0), 1e6);
|
165
|
+
}
|
166
|
+
}
|
167
|
+
}
|
168
|
+
new ControllerNode().start().catch((error) => logger.error(error));
|
169
|
+
process.on("SIGINT", () => {
|
170
|
+
storage.close().then(() => process.exit(0)).catch(() => process.exit(1));
|
171
|
+
});
|
172
|
+
//# sourceMappingURL=ControllerNode.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["../../../src/examples/ControllerNode.ts"],
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\n\n/**\n * @license\n * Copyright 2022-2023 Project CHIP Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a Matter controller to pair with a device and interfact with it.\n * It can be used as CLI script, but is more thought as a starting point for your own controller implementation\n * because you need to adjust the code in any way depending on your use case.\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 { CommissioningController, 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 {\n BasicInformationCluster,\n DescriptorCluster,\n GeneralCommissioning,\n OnOffCluster,\n} from \"@project-chip/matter-node.js/cluster\";\nimport { logEndpoint } from \"@project-chip/matter-node.js/device\";\nimport { Format, Level, Logger } from \"@project-chip/matter-node.js/log\";\nimport { CommissioningOptions } from \"@project-chip/matter-node.js/protocol\";\nimport { ManualPairingCodeCodec } from \"@project-chip/matter-node.js/schema\";\nimport { StorageBackendDisk, StorageManager } from \"@project-chip/matter-node.js/storage\";\nimport {\n getIntParameter,\n getParameter,\n hasParameter,\n requireMinNodeVersion,\n singleton,\n} from \"@project-chip/matter-node.js/util\";\n\nconst logger = Logger.get(\"Controller\");\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\") ?? \".controller-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 ControllerNode {\n async start() {\n logger.info(`node-matter Controller started`);\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 controllerStorage = storageManager.createContext(\"Controller\");\n const ip = controllerStorage.has(\"ip\") ? controllerStorage.get<string>(\"ip\") : getParameter(\"ip\");\n const port = controllerStorage.has(\"port\") ? controllerStorage.get<number>(\"port\") : getIntParameter(\"port\");\n\n const pairingCode = getParameter(\"pairingcode\");\n let longDiscriminator, setupPin, shortDiscriminator;\n if (pairingCode !== undefined) {\n const pairingCodeCodec = ManualPairingCodeCodec.decode(pairingCode);\n shortDiscriminator = pairingCodeCodec.shortDiscriminator;\n longDiscriminator = undefined;\n setupPin = pairingCodeCodec.passcode;\n logger.debug(`Data extracted from pairing code: ${Logger.toJSON(pairingCodeCodec)}`);\n } else {\n longDiscriminator =\n getIntParameter(\"longDiscriminator\") ?? controllerStorage.get(\"longDiscriminator\", 3840);\n if (longDiscriminator > 4095) throw new Error(\"Discriminator value must be less than 4096\");\n setupPin = getIntParameter(\"pin\") ?? controllerStorage.get(\"pin\", 20202021);\n }\n if ((shortDiscriminator === undefined && longDiscriminator === undefined) || setupPin === undefined) {\n throw new Error(\n \"Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode\",\n );\n }\n\n // Collect commissioning options from commandline parameters\n const commissioningOptions: CommissioningOptions = {\n regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,\n regulatoryCountryCode: \"XX\",\n };\n if (hasParameter(\"ble\")) {\n const wifiSsid = getParameter(\"ble-wifi-ssid\");\n const wifiCredentials = getParameter(\"ble-wifi-credentials\");\n const threadNetworkName = getParameter(\"ble-thread-networkname\");\n const threadOperationalDataset = getParameter(\"ble-thread-operationaldataset\");\n if (wifiSsid !== undefined && wifiCredentials !== undefined) {\n logger.info(`Registering Commissioning over BLE with WiFi: ${wifiSsid}`);\n commissioningOptions.wifiNetwork = {\n wifiSsid: wifiSsid,\n wifiCredentials: wifiCredentials,\n };\n }\n if (threadNetworkName !== undefined && threadOperationalDataset !== undefined) {\n logger.info(`Registering Commissioning over BLE with Thread: ${threadNetworkName}`);\n commissioningOptions.threadNetwork = {\n networkName: threadNetworkName,\n operationalDataset: threadOperationalDataset,\n };\n }\n }\n\n /**\n * Create Matter Server and Controller Node\n *\n * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a\n * CommissioningController to it and add the just created device instance to it.\n * The Controller 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 const matterServer = new MatterServer(storageManager);\n const commissioningController = new CommissioningController({\n serverAddress: ip !== undefined && port !== undefined ? { ip, port, type: \"udp\" } : undefined,\n longDiscriminator,\n shortDiscriminator,\n passcode: setupPin,\n delayedPairing: true,\n commissioningOptions,\n subscribeAllAttributes: true,\n });\n matterServer.addCommissioningController(commissioningController);\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 matterServer.start();\n\n /**\n * TBD\n */\n try {\n await commissioningController.connect();\n\n if (commissioningController.serverAddress !== undefined) {\n const { ip, port } = commissioningController.serverAddress;\n controllerStorage.set(\"ip\", ip);\n controllerStorage.set(\"port\", port);\n }\n if (longDiscriminator !== undefined) {\n controllerStorage.set(\"longDiscriminator\", longDiscriminator);\n }\n controllerStorage.set(\"pin\", setupPin);\n\n // Important: This is a temporary API to proof the methods working and this will change soon and is NOT stable!\n // It is provided to proof the concept\n\n logEndpoint(commissioningController.getRootEndpoint());\n\n // Example to initialize a ClusterClient and access concrete fields as API methods\n const descriptor = commissioningController.getRootClusterClient(DescriptorCluster);\n if (descriptor !== undefined) {\n console.log(await descriptor.attributes.deviceTypeList.get()); // you can call that way\n console.log(await descriptor.getServerListAttribute()); // or more convenient that way\n } else {\n console.log(\"No Descriptor Cluster found. This should never happen!\");\n }\n\n // Example to subscribe to a field and get the value\n const info = commissioningController.getRootClusterClient(BasicInformationCluster);\n if (info !== undefined) {\n console.log(await info.getProductNameAttribute()); // This call is executed remotely\n //console.log(await info.subscribeProductNameAttribute(value => console.log(\"productName\", value), 5, 30));\n //console.log(await info.getProductNameAttribute()); // This call is resolved locally because we have subscribed to the value!\n } else {\n console.log(\"No BasicInformation Cluster found. This should never happen!\");\n }\n\n // Example to get all Attributes of the commissioned node: */*/*\n //const attributesAll = await interactionClient.getAllAttributes();\n //console.log(\"Attributes-All:\", Logger.toJSON(attributesAll));\n\n // Example to get all Attributes of all Descriptor Clusters of the commissioned node: */DescriptorCluster/*\n //const attributesAllDescriptor = await interactionClient.getMultipleAttributes([{ clusterId: DescriptorCluster.id} ]);\n //console.log(\"Attributes-Descriptor:\", JSON.stringify(attributesAllDescriptor, null, 2));\n\n // Example to get all Attributes of the Basic Information Cluster of endpoint 0 of the commissioned node: 0/BasicInformationCluster/*\n //const attributesBasicInformation = await interactionClient.getMultipleAttributes([{ endpointId: 0, clusterId: BasicInformationCluster.id} ]);\n //console.log(\"Attributes-BasicInformation:\", JSON.stringify(attributesBasicInformation, null, 2));\n\n const devices = commissioningController.getDevices();\n if (devices[0] && devices[0].id === 1) {\n // Example to subscribe to all Attributes of endpoint 1 of the commissioned node: */*/*\n //await interactionClient.subscribeMultipleAttributes([{ endpointId: 1, /* subscribe anything from endpoint 1 */ }], 0, 180, data => {\n // console.log(\"Subscribe-All Data:\", Logger.toJSON(data));\n //});\n\n const onOff = devices[0].getClusterClient(OnOffCluster);\n if (onOff !== undefined) {\n let onOffStatus = await onOff.getOnOffAttribute();\n console.log(\"initial onOffStatus\", onOffStatus);\n\n onOff.addOnOffAttributeListener(value => {\n console.log(\"subscription onOffStatus\", value);\n onOffStatus = value;\n });\n // read data every minute to keep up the connection to show the subscription is working\n setInterval(() => {\n onOff\n .toggle()\n .then(() => {\n onOffStatus = !onOffStatus;\n console.log(\"onOffStatus\", onOffStatus);\n })\n .catch(error => logger.error(error));\n }, 60000);\n }\n }\n } finally {\n //await matterServer.close(); // Comment out when subscribes are used, else the connection will be closed\n setTimeout(() => process.exit(0), 1000000);\n }\n }\n}\n\nnew ControllerNode().start().catch(error => logger.error(error));\n\nprocess.on(\"SIGINT\", () => {\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(() => process.exit(1));\n});\n"],
|
5
|
+
"mappings": ";;AAkBA,yBAAsD;AAEtD,iBAAwB;AACxB,IAAAA,cAAoB;AACpB,qBAKO;AACP,oBAA4B;AAC5B,iBAAsC;AAEtC,oBAAuC;AACvC,qBAAmD;AACnD,kBAMO;AArCP;AAAA;AAAA;AAAA;AAAA;AAuCA,MAAM,SAAS,kBAAO,IAAI,YAAY;AAAA,IAEtC,mCAAsB,EAAE;AAGxB,YAAQ,0BAAa,UAAU,GAAG;AAAA,EAC9B,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AAAA,EACJ,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AAAA,EACJ,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AAAA,EACJ,KAAK;AACD,sBAAO,kBAAkB,iBAAM;AAC/B;AACR;AAEA,YAAQ,0BAAa,WAAW,GAAG;AAAA,EAC/B,KAAK;AACD,sBAAO,SAAS,kBAAO;AACvB;AAAA,EACJ,KAAK;AACD,sBAAO,SAAS,kBAAO;AACvB;AAAA,EACJ;AACI,QAAI,QAAQ,OAAO;AAAO,wBAAO,SAAS,kBAAO;AACzD;AAEA,QAAI,0BAAa,KAAK,GAAG;AAErB,kBAAI,UAAM;AAAA,IACN,MACI,IAAI,mBAAQ;AAAA,MACR,WAAO,6BAAgB,YAAY;AAAA,IACvC,CAAC;AAAA,EACT;AACJ;AA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