@project-chip/matter-node.js-examples 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * @license
5
+ * Copyright 2022 The node-matter Authors
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ var _a, _b;
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ /**
20
+ * This example shows how to create a new device node that is composed of multiple devices.
21
+ * It creates multiple endpoints on the server. When you want to add a composed devices to a Aggregator you need to
22
+ * add all endpoints of the composed device to an "ComposedDevice" instance! (not shown in this example).
23
+ * It can be used as CLI script and starting point for your own device node implementation.
24
+ */
25
+ /**
26
+ * Import needed modules from @project-chip/matter-node.js
27
+ */
28
+ // Include this first to auto-register Crypto, Network and Time Node.js implementations
29
+ const matter_node_js_1 = require("@project-chip/matter-node.js");
30
+ const datatype_1 = require("@project-chip/matter-node.js/datatype");
31
+ const device_1 = require("@project-chip/matter-node.js/device");
32
+ const log_1 = require("@project-chip/matter-node.js/log");
33
+ const storage_1 = require("@project-chip/matter-node.js/storage");
34
+ const time_1 = require("@project-chip/matter-node.js/time");
35
+ const util_1 = require("@project-chip/matter-node.js/util");
36
+ const logger = log_1.Logger.get("Device");
37
+ (0, util_1.requireMinNodeVersion)(16);
38
+ /** Configure logging */
39
+ switch ((0, util_1.getParameter)("loglevel")) {
40
+ case "fatal":
41
+ log_1.Logger.defaultLogLevel = log_1.Level.FATAL;
42
+ break;
43
+ case "error":
44
+ log_1.Logger.defaultLogLevel = log_1.Level.ERROR;
45
+ break;
46
+ case "warn":
47
+ log_1.Logger.defaultLogLevel = log_1.Level.WARN;
48
+ break;
49
+ case "info":
50
+ log_1.Logger.defaultLogLevel = log_1.Level.INFO;
51
+ break;
52
+ }
53
+ switch ((0, util_1.getParameter)("logformat")) {
54
+ case "plain":
55
+ log_1.Logger.format = log_1.Format.PLAIN;
56
+ break;
57
+ case "html":
58
+ log_1.Logger.format = log_1.Format.HTML;
59
+ break;
60
+ default:
61
+ if ((_a = process.stdin) === null || _a === void 0 ? void 0 : _a.isTTY)
62
+ log_1.Logger.format = log_1.Format.ANSI;
63
+ }
64
+ const storageLocation = (_b = (0, util_1.getParameter)("store")) !== null && _b !== void 0 ? _b : ".device-node";
65
+ const storage = new storage_1.StorageBackendDisk(storageLocation, (0, util_1.hasParameter)("clearstorage"));
66
+ logger.info(`Storage location: ${storageLocation} (Directory)`);
67
+ logger.info('Use the parameter "-store NAME" to specify a different storage location, use -clearstorage to start with an empty storage.');
68
+ class ComposedDevice {
69
+ start() {
70
+ var _a, _b, _c, _d, _e, _f, _g;
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ logger.info(`node-matter`);
73
+ /**
74
+ * Initialize the storage system.
75
+ *
76
+ * The storage manager is then also used by the Matter server, so this code block in general is required,
77
+ * but you can choose a different storage backend as long as it implements the required API.
78
+ */
79
+ const storageManager = new storage_1.StorageManager(storage);
80
+ yield storageManager.initialize();
81
+ /**
82
+ * Collect all needed data
83
+ *
84
+ * This block makes sure to collect all needed data from cli or storage. Replace this with where ever your data
85
+ * come from.
86
+ *
87
+ * Note: This example also uses the initialized storage system to store the device parameter data for convenience
88
+ * and easy reuse. When you also do that be careful to not overlap with Matter-Server own contexts
89
+ * (so maybe better not ;-)).
90
+ */
91
+ const deviceStorage = storageManager.createContext("Device");
92
+ if (deviceStorage.has("isSocket")) {
93
+ logger.info("Device type found in storage. -type parameter is ignored.");
94
+ }
95
+ const isSocket = deviceStorage.get("isSocket", (0, util_1.getParameter)("type") === "socket");
96
+ const deviceName = "Matter composed device";
97
+ const deviceType = (0, util_1.getParameter)("type") === "socket" ? device_1.DeviceTypes.ON_OFF_PLUGIN_UNIT.code : device_1.DeviceTypes.ON_OFF_LIGHT.code;
98
+ const vendorName = "matter-node.js";
99
+ const passcode = (_a = (0, util_1.getIntParameter)("passcode")) !== null && _a !== void 0 ? _a : deviceStorage.get("passcode", 20202021);
100
+ const discriminator = (_b = (0, util_1.getIntParameter)("discriminator")) !== null && _b !== void 0 ? _b : deviceStorage.get("discriminator", 3840);
101
+ // product name / id and vendor id should match what is in the device certificate
102
+ const vendorId = (_c = (0, util_1.getIntParameter)("vendorid")) !== null && _c !== void 0 ? _c : deviceStorage.get("vendorid", 0xfff1);
103
+ const productName = `node-matter OnOff-Bridge`;
104
+ const productId = (_d = (0, util_1.getIntParameter)("productid")) !== null && _d !== void 0 ? _d : deviceStorage.get("productid", 0x8000);
105
+ const netAnnounceInterface = (0, util_1.getParameter)("announceinterface");
106
+ const port = (_e = (0, util_1.getIntParameter)("port")) !== null && _e !== void 0 ? _e : 5540;
107
+ const uniqueId = (_f = (0, util_1.getIntParameter)("uniqueid")) !== null && _f !== void 0 ? _f : deviceStorage.get("uniqueid", time_1.Time.nowMs());
108
+ deviceStorage.set("passcode", passcode);
109
+ deviceStorage.set("discriminator", discriminator);
110
+ deviceStorage.set("vendorid", vendorId);
111
+ deviceStorage.set("productid", productId);
112
+ deviceStorage.set("isSocket", isSocket);
113
+ deviceStorage.set("uniqueid", uniqueId);
114
+ /**
115
+ * Create Matter Server and CommissioningServer Node
116
+ *
117
+ * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a
118
+ * commissioningServer to it and add the just created device instance to it.
119
+ * The CommissioningServer node defines the port where the server listens for the UDP packages of the Matter protocol
120
+ * and initializes deice specific certificates and such.
121
+ *
122
+ * The below logic also adds command handlers for commands of clusters that normally are handled internally
123
+ * like testEventTrigger (General Diagnostic Cluster) that can be implemented with the logic when these commands
124
+ * are called.
125
+ */
126
+ this.matterServer = new matter_node_js_1.MatterServer(storageManager, netAnnounceInterface);
127
+ const commissioningServer = new matter_node_js_1.CommissioningServer({
128
+ port,
129
+ deviceName,
130
+ deviceType,
131
+ passcode,
132
+ discriminator,
133
+ basicInformation: {
134
+ vendorName,
135
+ vendorId: (0, datatype_1.VendorId)(vendorId),
136
+ nodeLabel: productName,
137
+ productName,
138
+ productLabel: productName,
139
+ productId,
140
+ serialNumber: `node-matter-${uniqueId}`,
141
+ },
142
+ });
143
+ /**
144
+ * Create Device instance and add needed Listener
145
+ *
146
+ * Create an instance of the matter device class you want to use.
147
+ * This example uses the OnOffLightDevice or OnOffPluginUnitDevice depending on the value of the type parameter.
148
+ * To execute the on/off scripts defined as parameters a listener for the onOff attribute is registered via the
149
+ * device specific API.
150
+ *
151
+ * The below logic also adds command handlers for commands of clusters that normally are handled device internally
152
+ * like identify that can be implemented with the logic when these commands are called.
153
+ */
154
+ const numDevices = (0, util_1.getIntParameter)("num") || 2;
155
+ for (let i = 1; i <= numDevices; i++) {
156
+ const onOffDevice = (0, util_1.getParameter)(`type${i}`) === "socket" ? new device_1.OnOffPluginUnitDevice() : new device_1.OnOffLightDevice();
157
+ onOffDevice.addFixedLabel("orientation", (_g = (0, util_1.getParameter)(`orientation${i}`)) !== null && _g !== void 0 ? _g : `orientation ${i}`);
158
+ onOffDevice.addOnOffListener(on => { var _a; return (_a = (0, util_1.commandExecutor)(on ? `on${i}` : `off${i}`)) === null || _a === void 0 ? void 0 : _a(); });
159
+ onOffDevice.addCommandHandler("identify", ({ request: { identifyTime } }) => __awaiter(this, void 0, void 0, function* () {
160
+ return console.log(`Identify called for OnOffDevice ${onOffDevice.name} with id: ${i} and identifyTime: ${identifyTime}`);
161
+ }));
162
+ commissioningServer.addDevice(onOffDevice);
163
+ }
164
+ this.matterServer.addCommissioningServer(commissioningServer);
165
+ /**
166
+ * Start the Matter Server
167
+ *
168
+ * After everything was plugged together we can start the server. When not delayed announcement is set for the
169
+ * CommissioningServer node then this command also starts the announcement of the device into the network.
170
+ */
171
+ yield this.matterServer.start();
172
+ /**
173
+ * Print Pairing Information
174
+ *
175
+ * If the device is not already commissioned (this info is stored in the storage system) then get and print the
176
+ * pairing details. This includes the QR code that can be scanned by the Matter app to pair the device.
177
+ */
178
+ logger.info("Listening");
179
+ if (!commissioningServer.isCommissioned()) {
180
+ const pairingData = commissioningServer.getPairingCode();
181
+ const { qrCode, qrPairingCode, manualPairingCode } = pairingData;
182
+ console.log(qrCode);
183
+ console.log(`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`);
184
+ console.log(`Manual pairing code: ${manualPairingCode}`);
185
+ }
186
+ else {
187
+ console.log("Device is already commissioned. Waiting for controllers to connect ...");
188
+ }
189
+ });
190
+ }
191
+ stop() {
192
+ var _a;
193
+ return __awaiter(this, void 0, void 0, function* () {
194
+ yield ((_a = this.matterServer) === null || _a === void 0 ? void 0 : _a.close());
195
+ });
196
+ }
197
+ }
198
+ const device = new ComposedDevice();
199
+ device
200
+ .start()
201
+ .then(() => {
202
+ /* done */
203
+ })
204
+ .catch(err => console.error(err));
205
+ process.on("SIGINT", () => {
206
+ device
207
+ .stop()
208
+ .then(() => {
209
+ // Pragmatic way to make sure the storage is correctly closed before the process ends.
210
+ storage
211
+ .close()
212
+ .then(() => process.exit(0))
213
+ .catch(err => console.error(err));
214
+ })
215
+ .catch(err => console.error(err));
216
+ });
217
+ //# sourceMappingURL=ComposedDeviceNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ComposedDeviceNode.js","sourceRoot":"","sources":["../../src/examples/ComposedDeviceNode.ts"],"names":[],"mappings":";;AACA;;;;GAIG;;;;;;;;;;;;AAEH;;;;;GAKG;AAEH;;GAEG;AACH,uFAAuF;AACvF,iEAAiF;AAEjF,oEAAiE;AACjE,gEAA2G;AAC3G,0DAAyE;AACzE,kEAA0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iBAAiB,EAAE,GAAG,WAAW,CAAC;gBAEjE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBACpB,OAAO,CAAC,GAAG,CACP,gFAAgF,aAAa,EAAE,CAClG,CAAC;gBACF,OAAO,CAAC,GAAG,CAAC,wBAAwB,iBAAiB,EAAE,CAAC,CAAC;aAC5D;iBAAM;gBACH,OAAO,CAAC,GAAG,CAAC,wEAAwE,CAAC,CAAC;aACzF;;KACJ;IAEK,IAAI;;;YACN,MAAM,CAAA,MAAA,IAAI,CAAC,YAAY,0CAAE,KAAK,EAAE,CAAA,CAAC;;KACpC;CACJ;AAED,MAAM,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;AACpC,MAAM;KACD,KAAK,EAAE;KACP,IAAI,CAAC,GAAG,EAAE;IACP,UAAU;AACd,CAAC,CAAC;KACD,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAEtC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,MAAM;SACD,IAAI,EAAE;SACN,IAAI,CAAC,GAAG,EAAE;QACP,sFAAsF;QACtF,OAAO;aACF,KAAK,EAAE;aACP,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aAC3B,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC"}
@@ -0,0 +1,261 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * @license
5
+ * Copyright 2022-2023 Project CHIP Authors
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ var _a, _b;
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ /**
20
+ * This example shows how to create a Matter controller to pair with a device and interfact with it.
21
+ * It can be used as CLI script, but is more thought as a starting point for your own controller implementation
22
+ * because you need to adjust the code in any way depending on your use case.
23
+ */
24
+ /**
25
+ * Import needed modules from @project-chip/matter-node.js
26
+ */
27
+ // Include this first to auto-register Crypto, Network and Time Node.js implementations
28
+ const matter_node_js_1 = require("@project-chip/matter-node.js");
29
+ const ble_1 = require("@project-chip/matter-node-ble.js/ble");
30
+ const ble_2 = require("@project-chip/matter-node.js/ble");
31
+ const cluster_1 = require("@project-chip/matter-node.js/cluster");
32
+ const log_1 = require("@project-chip/matter-node.js/log");
33
+ const schema_1 = require("@project-chip/matter-node.js/schema");
34
+ const storage_1 = require("@project-chip/matter-node.js/storage");
35
+ const util_1 = require("@project-chip/matter-node.js/util");
36
+ const logger = log_1.Logger.get("Controller");
37
+ (0, util_1.requireMinNodeVersion)(16);
38
+ /** Configure logging */
39
+ switch ((0, util_1.getParameter)("loglevel")) {
40
+ case "fatal":
41
+ log_1.Logger.defaultLogLevel = log_1.Level.FATAL;
42
+ break;
43
+ case "error":
44
+ log_1.Logger.defaultLogLevel = log_1.Level.ERROR;
45
+ break;
46
+ case "warn":
47
+ log_1.Logger.defaultLogLevel = log_1.Level.WARN;
48
+ break;
49
+ case "info":
50
+ log_1.Logger.defaultLogLevel = log_1.Level.INFO;
51
+ break;
52
+ }
53
+ switch ((0, util_1.getParameter)("logformat")) {
54
+ case "plain":
55
+ log_1.Logger.format = log_1.Format.PLAIN;
56
+ break;
57
+ case "html":
58
+ log_1.Logger.format = log_1.Format.HTML;
59
+ break;
60
+ default:
61
+ if ((_a = process.stdin) === null || _a === void 0 ? void 0 : _a.isTTY)
62
+ log_1.Logger.format = log_1.Format.ANSI;
63
+ }
64
+ if ((0, util_1.hasParameter)("ble")) {
65
+ // Initialize Ble
66
+ ble_2.Ble.get = (0, util_1.singleton)(() => new ble_1.BleNode({
67
+ hciId: (0, util_1.getIntParameter)("ble-hci-id"),
68
+ }));
69
+ }
70
+ const storageLocation = (_b = (0, util_1.getParameter)("store")) !== null && _b !== void 0 ? _b : ".controller-node";
71
+ const storage = new storage_1.StorageBackendDisk(storageLocation, (0, util_1.hasParameter)("clearstorage"));
72
+ logger.info(`Storage location: ${storageLocation} (Directory)`);
73
+ logger.info('Use the parameter "-store NAME" to specify a different storage location, use -clearstorage to start with an empty storage.');
74
+ class ControllerNode {
75
+ start() {
76
+ var _a, _b;
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ logger.info(`node-matter Controller started`);
79
+ /**
80
+ * Initialize the storage system.
81
+ *
82
+ * The storage manager is then also used by the Matter server, so this code block in general is required,
83
+ * but you can choose a different storage backend as long as it implements the required API.
84
+ */
85
+ const storageManager = new storage_1.StorageManager(storage);
86
+ yield storageManager.initialize();
87
+ /**
88
+ * Collect all needed data
89
+ *
90
+ * This block makes sure to collect all needed data from cli or storage. Replace this with where ever your data
91
+ * come from.
92
+ *
93
+ * Note: This example also uses the initialized storage system to store the device parameter data for convenience
94
+ * and easy reuse. When you also do that be careful to not overlap with Matter-Server own contexts
95
+ * (so maybe better not ;-)).
96
+ */
97
+ const controllerStorage = storageManager.createContext("Controller");
98
+ const ip = controllerStorage.has("ip") ? controllerStorage.get("ip") : (0, util_1.getParameter)("ip");
99
+ const port = controllerStorage.has("port") ? controllerStorage.get("port") : (0, util_1.getIntParameter)("port");
100
+ const pairingCode = (0, util_1.getParameter)("pairingcode");
101
+ let longDiscriminator, setupPin, shortDiscriminator;
102
+ if (pairingCode !== undefined) {
103
+ const pairingCodeCodec = schema_1.ManualPairingCodeCodec.decode(pairingCode);
104
+ shortDiscriminator = pairingCodeCodec.shortDiscriminator;
105
+ longDiscriminator = undefined;
106
+ setupPin = pairingCodeCodec.passcode;
107
+ logger.debug(`Data extracted from pairing code: ${log_1.Logger.toJSON(pairingCodeCodec)}`);
108
+ }
109
+ else {
110
+ longDiscriminator =
111
+ (_a = (0, util_1.getIntParameter)("longDiscriminator")) !== null && _a !== void 0 ? _a : controllerStorage.get("longDiscriminator", 3840);
112
+ if (longDiscriminator > 4095)
113
+ throw new Error("Discriminator value must be less than 4096");
114
+ setupPin = (_b = (0, util_1.getIntParameter)("pin")) !== null && _b !== void 0 ? _b : controllerStorage.get("pin", 20202021);
115
+ }
116
+ if ((shortDiscriminator === undefined && longDiscriminator === undefined) || setupPin === undefined) {
117
+ throw new Error("Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode");
118
+ }
119
+ // Collect commissioning options from commandline parameters
120
+ const commissioningOptions = {
121
+ regulatoryLocation: 2 /* GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor */,
122
+ regulatoryCountryCode: "XX",
123
+ };
124
+ if ((0, util_1.hasParameter)("ble")) {
125
+ const wifiSsid = (0, util_1.getParameter)("ble-wifi-ssid");
126
+ const wifiCredentials = (0, util_1.getParameter)("ble-wifi-credentials");
127
+ const threadNetworkName = (0, util_1.getParameter)("ble-thread-networkname");
128
+ const threadOperationalDataset = (0, util_1.getParameter)("ble-thread-operationaldataset");
129
+ if (wifiSsid !== undefined && wifiCredentials !== undefined) {
130
+ logger.info(`Registering Commissioning over BLE with WiFi: ${wifiSsid}`);
131
+ commissioningOptions.wifiNetwork = {
132
+ wifiSsid: wifiSsid,
133
+ wifiCredentials: wifiCredentials,
134
+ };
135
+ }
136
+ if (threadNetworkName !== undefined && threadOperationalDataset !== undefined) {
137
+ logger.info(`Registering Commissioning over BLE with Thread: ${threadNetworkName}`);
138
+ commissioningOptions.threadNetwork = {
139
+ networkName: threadNetworkName,
140
+ operationalDataset: threadOperationalDataset,
141
+ };
142
+ }
143
+ }
144
+ /**
145
+ * Create Matter Server and Controller Node
146
+ *
147
+ * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a
148
+ * CommissioningController to it and add the just created device instance to it.
149
+ * The Controller node defines the port where the server listens for the UDP packages of the Matter protocol
150
+ * and initializes deice specific certificates and such.
151
+ *
152
+ * The below logic also adds command handlers for commands of clusters that normally are handled internally
153
+ * like testEventTrigger (General Diagnostic Cluster) that can be implemented with the logic when these commands
154
+ * are called.
155
+ */
156
+ const matterServer = new matter_node_js_1.MatterServer(storageManager);
157
+ const commissioningController = new matter_node_js_1.CommissioningController({
158
+ serverAddress: ip !== undefined && port !== undefined ? { ip, port, type: "udp" } : undefined,
159
+ longDiscriminator,
160
+ shortDiscriminator,
161
+ passcode: setupPin,
162
+ delayedPairing: true,
163
+ commissioningOptions,
164
+ subscribeAllAttributes: true,
165
+ });
166
+ matterServer.addCommissioningController(commissioningController);
167
+ /**
168
+ * Start the Matter Server
169
+ *
170
+ * After everything was plugged together we can start the server. When not delayed announcement is set for the
171
+ * CommissioningServer node then this command also starts the announcement of the device into the network.
172
+ */
173
+ yield matterServer.start();
174
+ /**
175
+ * TBD
176
+ */
177
+ try {
178
+ yield commissioningController.connect();
179
+ if (commissioningController.serverAddress !== undefined) {
180
+ const { ip, port } = commissioningController.serverAddress;
181
+ controllerStorage.set("ip", ip);
182
+ controllerStorage.set("port", port);
183
+ }
184
+ if (longDiscriminator !== undefined) {
185
+ controllerStorage.set("longDiscriminator", longDiscriminator);
186
+ }
187
+ controllerStorage.set("pin", setupPin);
188
+ // Important: This is a temporary API to proof the methods working and this will change soon and is NOT stable!
189
+ // It is provided to proof the concept
190
+ (0, util_1.logEndpoint)(commissioningController.getRootEndpoint());
191
+ // Example to initialize a ClusterClient and access concrete fields as API methods
192
+ const descriptor = commissioningController.getRootClusterClient(cluster_1.DescriptorCluster);
193
+ if (descriptor !== undefined) {
194
+ console.log(yield descriptor.attributes.deviceTypeList.get()); // you can call that way
195
+ console.log(yield descriptor.getServerListAttribute()); // or more convenient that way
196
+ }
197
+ else {
198
+ console.log("No Descriptor Cluster found. This should never happen!");
199
+ }
200
+ // Example to subscribe to a field and get the value
201
+ const info = commissioningController.getRootClusterClient(cluster_1.BasicInformationCluster);
202
+ if (info !== undefined) {
203
+ console.log(yield info.getProductNameAttribute()); // This call is executed remotely
204
+ //console.log(await info.subscribeProductNameAttribute(value => console.log("productName", value), 5, 30));
205
+ //console.log(await info.getProductNameAttribute()); // This call is resolved locally because we have subscribed to the value!
206
+ }
207
+ else {
208
+ console.log("No BasicInformation Cluster found. This should never happen!");
209
+ }
210
+ // Example to get all Attributes of the commissioned node: */*/*
211
+ //const attributesAll = await interactionClient.getAllAttributes();
212
+ //console.log("Attributes-All:", Logger.toJSON(attributesAll));
213
+ // Example to get all Attributes of all Descriptor Clusters of the commissioned node: */DescriptorCluster/*
214
+ //const attributesAllDescriptor = await interactionClient.getMultipleAttributes([{ clusterId: DescriptorCluster.id} ]);
215
+ //console.log("Attributes-Descriptor:", JSON.stringify(attributesAllDescriptor, null, 2));
216
+ // Example to get all Attributes of the Basic Information Cluster of endpoint 0 of the commissioned node: 0/BasicInformationCluster/*
217
+ //const attributesBasicInformation = await interactionClient.getMultipleAttributes([{ endpointId: 0, clusterId: BasicInformationCluster.id} ]);
218
+ //console.log("Attributes-BasicInformation:", JSON.stringify(attributesBasicInformation, null, 2));
219
+ const devices = commissioningController.getDevices();
220
+ if (devices[0] && devices[0].id === 1) {
221
+ // Example to subscribe to all Attributes of endpoint 1 of the commissioned node: */*/*
222
+ //await interactionClient.subscribeMultipleAttributes([{ endpointId: 1, /* subscribe anything from endpoint 1 */ }], 0, 180, data => {
223
+ // console.log("Subscribe-All Data:", Logger.toJSON(data));
224
+ //});
225
+ const onOff = devices[0].getClusterClient(cluster_1.OnOffCluster);
226
+ if (onOff !== undefined) {
227
+ let onOffStatus = yield onOff.getOnOffAttribute();
228
+ console.log("initial onOffStatus", onOffStatus);
229
+ onOff.addOnOffAttributeListener(value => {
230
+ console.log("subscription onOffStatus", value);
231
+ onOffStatus = value;
232
+ });
233
+ // read data every minute to keep up the connection to show the subscription is working
234
+ setInterval(() => {
235
+ onOff
236
+ .toggle()
237
+ .then(() => {
238
+ onOffStatus = !onOffStatus;
239
+ console.log("onOffStatus", onOffStatus);
240
+ })
241
+ .catch(error => logger.error(error));
242
+ }, 60000);
243
+ }
244
+ }
245
+ }
246
+ finally {
247
+ //await matterServer.close(); // Comment out when subscribes are used, else the connection will be closed
248
+ setTimeout(() => process.exit(0), 1000000);
249
+ }
250
+ });
251
+ }
252
+ }
253
+ new ControllerNode().start().catch(error => logger.error(error));
254
+ process.on("SIGINT", () => {
255
+ // Pragmatic way to make sure the storage is correctly closed before the process ends.
256
+ storage
257
+ .close()
258
+ .then(() => process.exit(0))
259
+ .catch(() => process.exit(1));
260
+ });
261
+ //# sourceMappingURL=ControllerNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ControllerNode.js","sourceRoot":"","sources":["../../src/examples/ControllerNode.ts"],"names":[],"mappings":";;AAEA;;;;GAIG;;;;;;;;;;;;AAEH;;;;GAIG;AAEH;;GAEG;AACH,uFAAuF;AACvF,iEAAqF;AAErF,8DAA+D;AAC/D,0DAAuD;AACvD,kEAK8C;AAC9C,0DAAyE;AAEzE,gEAA6E;AAC7E,kEAA0F;AAC1F,4DAO2C;AAE3C,MAAM,MAAM,GAAG,YAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAExC,IAAA,4BAAqB,EAAC,EAAE,CAAC,CAAC;AAE1B,wBAAwB;AACxB,QAAQ,IAAA,mBAAY,EAAC,UAAU,CAAC,EAAE;IAC9B,KAAK,OAAO;QACR,YAAM,CAAC,eAAe,GAAG,WAAK,CAAC,KAAK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