@matter/nodejs-shell 0.11.0-alpha.0-20241007-547af42a8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +192 -0
  3. package/dist/cjs/MatterNode.js +115 -0
  4. package/dist/cjs/MatterNode.js.map +6 -0
  5. package/dist/cjs/app.js +162 -0
  6. package/dist/cjs/app.js.map +6 -0
  7. package/dist/cjs/package.json +7 -0
  8. package/dist/cjs/shell/Shell.js +195 -0
  9. package/dist/cjs/shell/Shell.js.map +6 -0
  10. package/dist/cjs/shell/cmd_cluster-attributes.js +310 -0
  11. package/dist/cjs/shell/cmd_cluster-attributes.js.map +6 -0
  12. package/dist/cjs/shell/cmd_cluster-commands.js +158 -0
  13. package/dist/cjs/shell/cmd_cluster-commands.js.map +6 -0
  14. package/dist/cjs/shell/cmd_cluster-events.js +104 -0
  15. package/dist/cjs/shell/cmd_cluster-events.js.map +6 -0
  16. package/dist/cjs/shell/cmd_commission.js +237 -0
  17. package/dist/cjs/shell/cmd_commission.js.map +6 -0
  18. package/dist/cjs/shell/cmd_config.js +315 -0
  19. package/dist/cjs/shell/cmd_config.js.map +6 -0
  20. package/dist/cjs/shell/cmd_discover.js +123 -0
  21. package/dist/cjs/shell/cmd_discover.js.map +6 -0
  22. package/dist/cjs/shell/cmd_identify.js +66 -0
  23. package/dist/cjs/shell/cmd_identify.js.map +6 -0
  24. package/dist/cjs/shell/cmd_nodes.js +244 -0
  25. package/dist/cjs/shell/cmd_nodes.js.map +6 -0
  26. package/dist/cjs/shell/cmd_session.js +43 -0
  27. package/dist/cjs/shell/cmd_session.js.map +6 -0
  28. package/dist/cjs/shell/cmd_subscribe.js +59 -0
  29. package/dist/cjs/shell/cmd_subscribe.js.map +6 -0
  30. package/dist/cjs/shell/cmd_tlv.js +175 -0
  31. package/dist/cjs/shell/cmd_tlv.js.map +6 -0
  32. package/dist/cjs/util/CommandlineParser.js +106 -0
  33. package/dist/cjs/util/CommandlineParser.js.map +6 -0
  34. package/dist/cjs/util/Json.js +66 -0
  35. package/dist/cjs/util/Json.js.map +6 -0
  36. package/dist/cjs/util/String.js +32 -0
  37. package/dist/cjs/util/String.js.map +6 -0
  38. package/package.json +58 -0
  39. package/src/MatterNode.ts +141 -0
  40. package/src/app.ts +158 -0
  41. package/src/shell/Shell.ts +184 -0
  42. package/src/shell/cmd_cluster-attributes.ts +340 -0
  43. package/src/shell/cmd_cluster-commands.ts +174 -0
  44. package/src/shell/cmd_cluster-events.ts +99 -0
  45. package/src/shell/cmd_commission.ts +273 -0
  46. package/src/shell/cmd_config.ts +366 -0
  47. package/src/shell/cmd_discover.ts +127 -0
  48. package/src/shell/cmd_identify.ts +51 -0
  49. package/src/shell/cmd_nodes.ts +249 -0
  50. package/src/shell/cmd_session.ts +23 -0
  51. package/src/shell/cmd_subscribe.ts +43 -0
  52. package/src/shell/cmd_tlv.ts +169 -0
  53. package/src/tsconfig.json +22 -0
  54. package/src/util/CommandlineParser.ts +123 -0
  55. package/src/util/Json.ts +50 -0
  56. package/src/util/String.ts +9 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # matter.js Node Shell
2
+
3
+ This project provides a light-weight node.js implementation of a Matter shell application like the chip-tool from the official Matter-SDK.
4
+
5
+ > This package supports all Node.js LTS versions starting with 18.x
6
+
7
+ ## Install
8
+
9
+ If you want to install just the shell app then you can do so by running:
10
+
11
+ ```
12
+ npm install @matter/nodejs-shell
13
+ ```
14
+
15
+ ## Run
16
+
17
+ There are three ways to start matter-node-shell. The `nodenum` parameter provides a unique identifier for the matter-node-shell process mainly to allocate a unique port number. If `nodenum` is not passed, it will default to `0`.
18
+ The shell currently just supports Controller side and so the port is not used and the node is always by default a "controller".
19
+
20
+ ```
21
+ npm shell <nodenum>
22
+ ```
23
+
24
+ There are other parameters available to enable BLE and define the HCI device to use. See `npm shell -- --help` for more details.
25
+
26
+ ## General usage
27
+
28
+ The shell offers and interactive prompt that can execute commands. If you just enter the command name that has sub commands (with or without followed by "help"), it will display the command options. If you enter the command name followed by the options, it will execute the command, with "help" after the command name it will show the detailed help for this command.
29
+
30
+ e.g. `commission` or `commission help` will display the commissioning command options
31
+
32
+ ### help
33
+
34
+ Display a list of all top-level commands supported and a brief description.
35
+
36
+ ```
37
+ matter-node> help
38
+ commission Handle device commissioning
39
+ config Manage global configuration
40
+ session Manage session
41
+ nodes Manage nodes
42
+ subscribe [node-id] Subscribe to all events and attributes of a node
43
+ identify [time] [node-id] [endpoint-id] Trigger Identify command with given time (default 10s). Execute on one node or endpoint, else all onoff clusters will be controlled
44
+ discover Handle device discovery
45
+ attributes Read and Write attributes
46
+ events Read events
47
+ commands Invoke commands
48
+ tlv TLV decoding tools
49
+ exit Exit
50
+ ```
51
+
52
+ ### Help for commands
53
+
54
+ For every command help can be requested by using the command name, or by adding with `--help` as parameter to any command text.
55
+
56
+ For instance `config --help` will display all node configuration for the persistent store of the shell.
57
+
58
+ ```
59
+ > config
60
+ config loglevel Manage Console and File LogLevels
61
+ config logfile Manage Logfile path
62
+ config ble-hci Manage BLE HCI ID (Linux)
63
+ config wifi-credentials Manage Wi-Fi credentials used in commissioning process
64
+ config thread-credentials Manage Thread credentials used in commissioning process
65
+
66
+ Done
67
+ ```
68
+
69
+ ### Logging
70
+
71
+ By default the Shell logs messages to the console. The log level can be changed using the `config loglevel` command. The log level can be set to `error`, `warn`, `info`, `debug` or `trace`. The console default is "info".
72
+
73
+ Additionally the Shell can log to a file. The log file path can be set using the `config logfile` command or as commandline parameter (which will then be persisted in the configuration). The log file always contain the logs in "debug" level.
74
+
75
+ ### Commission a device
76
+
77
+ The shell supports discovery and also commissioning of devices. The commissioning process is based on the Matter SDK and uses the same commissioning process as the chip-tool. The commissioning process is started by the `commission pair` command.
78
+
79
+ In order to pair a device you need to specify the pairing-code which is printed on the device QR-Code as parameter pairing-code: `commission pair --pairing-code 123456789`. This is the easiest way for all production devices.
80
+ For development devices that use the matter standard discriminator and pin code the parameter con be omitted or more details can be provided as parameters (see `commission pair --help` for more details).
81
+
82
+ If the device should be commissioned via BLE because it is not yet in the IP network you can add the `--ble` parameter. This will start the BLE advertisement and the device can be paired via BLE. BLE is only available when the shell was started with the `--ble` parameter!
83
+ When commissioning a device via BLE you also need to setup wifi or thread credentials (based on the device type) that are then used in the commissioning process. This can be done using the `config wifi-credentials` or `config thread-credentials` commands.
84
+ IMPORTANT: These credentials are stored unencrypted in the filesystem!
85
+
86
+ You can also define the node id to pair the device by providing this ID as parameter `commission pair 5000`.
87
+
88
+ You can commission multiple nodes to the controller.
89
+
90
+ After a successfull commissioning the shell outputs the device name and some information and automatically described to the node and logs potential updates.
91
+
92
+ ### List commissioned nodes
93
+
94
+ The list of nodes can be listed using `nodes list` command. This will list all nodes that are currently commissioned to the controller and provides some information stored in the controller like name, node-id and a copy of the Basic Information cluster details and latest MDNS discovery data.
95
+
96
+ ### Connect to a node
97
+
98
+ When fresh starting the shell it do not connect to the commissioned nodes automatically.
99
+
100
+ Using `nodes connect` the shell tries to connect to all commissioned nodes. Alternatively you can provide a node-id to connect to a specific node (`nodes connect 5000`).
101
+
102
+ Additional parameters to the connect command are the subscription delays (min/max). So if you want to make sure you get data subscribed use `nodes connect 5000 <min> <max>` with values in seconds.
103
+
104
+ ### Log a Node structure
105
+
106
+ To see the full node structure of a node you can use the `nodes log` command and provide the node-id as parameter (`nodes log 5000`).
107
+
108
+ ### Commissioning related node operations
109
+
110
+ To open a commissioning window on a node to allow an additional pairing use `commission open-enhanced-window <node-id>`. When the command was successful the shell outputs the pairing code and a QR code to scan with the relevant pairing App.
111
+
112
+ To unpair a node use `commission unpair <node-id>`. This will remove the node from the controller and also remove the node from the persistent storage.
113
+
114
+ ### Interact with the node using Attributes, Events and Commands
115
+
116
+ The shell supports reading and writing attributes (top level command `attributes` or `a` as alias), reading events (`events`/`e`) and invoking commands (`commands`/`c`) on the node. Below these top level commands the full list of the officially defined clusters is available to be used. See the help for the relevant cluster for more details.
117
+
118
+ For reading attributes also a bulk read for all attributes is supported and with the `by-id` variant you can read and attribute from any cluster including custom clusters.
119
+ Attribute reads are done locally (when connected with a subscription and attribute is subscribable) by default. For remote reads (always from the node) add the `--remote` parameter. Unknown attributes or attributes from unknown clusters are always read remotely.
120
+
121
+ Writing attributes and executing commands (when the request requires data) these can be provided as JSON when it is no simple type. The shell will try to parse the JSON and send the data to the node. Binary data and Numbers >56bit needs to be provided as strings in this JSON and are automatically converted.
122
+ For convenience reasons any number in the value to write or invoke data can be provided as hex string by prefixing it with `0x` (e.g. `"0x1234"`) and is then also converted automatically.
123
+ When sending complex JSON content ideally use single quotes around the json because double quotes are used to define the JSON content.
124
+
125
+ Some examples:
126
+
127
+ - `attributes basicinformation read all 5000 0` reads all attributes from the Basic Information cluster from node 5000 endpoint 0 (reads values locally when connected with subscription, else remote)
128
+ - `attributes basicinformation read all 5000 0 --remote` reads all attributes from the Basic Information cluster from node 5000 endpoint 0 always from remote (also when connected with a subscription)
129
+ - `attributes basicinformation read nodelabel 5000 0` reads the attribute "nodelabel" from the Basic Information cluster from node 5000 endpoint 0
130
+ - `attributes basicinformation read 0x5 5000 0` reads the attribute "nodelabel" (aliased with it's hex attribute id) from the Basic Information cluster from node 5000 endpoint 0
131
+ - `attributes by-id 0x28 read 0x5 5000 0` also reads the attribute "nodelabel" from the Basic Information cluster from node 5000 endpoint 0, but as generic read from the cluster with id 0x28 (also the decimal value 40 can be used)
132
+ - `attributes basicinformation write nodelabel "My Node" 5000 0` writes the value "My Node" to the attribute "nodelabel" from the Basic Information cluster from node 5000 endpoint 0. Instead of nodelabel also 0x5 as alias can be used.
133
+ - `attributes binding write binding '[{"node": "4568118954124746267" , "cluster": 6 , "endpoint": 1 }]' 5000 1` writes the binding array to the Binding cluster from node 5000 endpoint 1 to create a binding for node 4568118954124746267 to cluster 6 on endpoint 1. Note that the 64bit Node-id (4568118954124746267) needs to be provided as string because it is too big for a number.
134
+ - `attributes binding write binding '[{"node": "4568118954124746267" , "cluster": "0x6" , "endpoint": 1 }]' 5000 1` writes the same binding array as abobe but uses a hex string for the cluster id in the json data
135
+ - `events basicinformation startup 5000 0` reads the details from the startup event from the Basic Information cluster from node 5000 endpoint 0
136
+ - `commands onoff toggle 5000 1` executes the "toggle" command on the OnOff cluster from node 5000 endpoint 1
137
+ - `commands onoff offwitheffect '{"effectIdentifier":0,"effectVariant":0}' 5000 1` executes the "offwitheffect" command on the OnOff cluster from node 5000 endpoint 1 with the given JSON data
138
+
139
+ ### exit
140
+
141
+ Exit the shell terminal.
142
+
143
+ ```
144
+ > exit
145
+ Goodbye
146
+ ```
147
+
148
+ # Running multiple instances
149
+
150
+ The matter shell app uses the `node-localstorage` package to persistently store configuration data of each node on disk. In order to run multiple nodes on one machine, start each node with their own `nodenum` so each will create and use their own `.matter-shell-#` directory and use different ports for communication where `#` is the `nodenum` passed from the commandline.
151
+
152
+ ```
153
+ # From matter-node-shell top-level
154
+ npm shell 1
155
+
156
+ # In different terminal
157
+ npm shell 2
158
+ ```
159
+
160
+ To delete node state, i.e. factory reset, just delete the `.matter-shell-#` directory of the node:
161
+
162
+ ```
163
+ rm -fr .matter-shell-2
164
+ ```
165
+
166
+ The contents of the `.matter-shell-#` directory are human-readable, where each field in the key/value store is a separate file in ascii format:
167
+
168
+ ```
169
+ $ ls .matter-shell-1
170
+ 0.MatterController.fabric 0.SessionManager.resumptionRecords
171
+ 0.MatterController.fabricCommissioned Node.discriminator
172
+ 0.MatterController.operationalIpServerAddress Node.ip
173
+ 0.RootCertificateManager.nextCertificateId Node.longDiscriminator
174
+ 0.RootCertificateManager.rootCertBytes Node.pin
175
+ 0.RootCertificateManager.rootCertId Node.port
176
+ 0.RootCertificateManager.rootKeyIdentifier Node.shortDiscriminator
177
+ 0.RootCertificateManager.rootKeyPair
178
+
179
+ $ more .matter-shell-1/Node.ip
180
+ "fe80::148d:9bd8:5006:243%en0"
181
+ ```
182
+
183
+ ```
184
+
185
+
186
+ ▄ █ ▄
187
+ ▀▀█████▀▀
188
+ ▀█▄ ▄█▀
189
+ ▀█▄ ▄█▀
190
+ ▄██▀▀█ █▀▀██▄
191
+ ▀▀ █ █ ▀▀
192
+ ```
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var MatterNode_exports = {};
20
+ __export(MatterNode_exports, {
21
+ MatterNode: () => MatterNode
22
+ });
23
+ module.exports = __toCommonJS(MatterNode_exports);
24
+ var import_general = require("@matter/general");
25
+ var import_nodejs = require("@matter/nodejs");
26
+ var import_matter = require("@project-chip/matter.js");
27
+ var import_datatype = require("@project-chip/matter.js/datatype");
28
+ /**
29
+ * @license
30
+ * Copyright 2022-2024 Matter.js Authors
31
+ * SPDX-License-Identifier: Apache-2.0
32
+ */
33
+ const logger = import_general.Logger.get("Node");
34
+ class MatterNode {
35
+ constructor(nodeNum, netInterface) {
36
+ this.nodeNum = nodeNum;
37
+ this.netInterface = netInterface;
38
+ }
39
+ storageLocation;
40
+ storage;
41
+ storageManager;
42
+ storageContext;
43
+ commissioningController;
44
+ matterController;
45
+ async initialize(resetStorage) {
46
+ this.storageLocation = `.matter-shell-${this.nodeNum}`;
47
+ this.storage = new import_nodejs.StorageBackendDisk(this.storageLocation, false);
48
+ logger.info(`Storage location: ${this.storageLocation} (Directory)`);
49
+ this.storageManager = new import_general.StorageManager(this.storage);
50
+ await this.storageManager.initialize();
51
+ this.storageContext = this.storageManager.createContext("Node");
52
+ if (resetStorage) {
53
+ this.storage.clearAll([]);
54
+ }
55
+ }
56
+ get Store() {
57
+ if (!this.storageContext) {
58
+ throw new Error("Storage uninitialized");
59
+ }
60
+ return this.storageContext;
61
+ }
62
+ async close() {
63
+ await this.matterController?.close();
64
+ this.closeStorage();
65
+ }
66
+ closeStorage() {
67
+ try {
68
+ this.storage?.close();
69
+ process.exit(0);
70
+ } catch {
71
+ process.exit(1);
72
+ }
73
+ }
74
+ async start() {
75
+ if (this.storageManager === void 0) {
76
+ throw new Error("StorageManager not initialized");
77
+ }
78
+ if (this.matterController !== void 0) {
79
+ return;
80
+ }
81
+ logger.info(`matter.js shell controller started for node ${this.nodeNum}`);
82
+ this.matterController = new import_matter.MatterServer(this.storageManager, { mdnsInterface: this.netInterface });
83
+ this.commissioningController = new import_matter.CommissioningController({
84
+ autoConnect: false
85
+ });
86
+ await this.matterController.addCommissioningController(this.commissioningController);
87
+ await this.matterController.start();
88
+ }
89
+ async connectAndGetNodes(nodeIdStr, connectOptions) {
90
+ await this.start();
91
+ const nodeId = nodeIdStr !== void 0 ? (0, import_datatype.NodeId)(BigInt(nodeIdStr)) : void 0;
92
+ if (this.commissioningController === void 0) {
93
+ throw new Error("CommissioningController not initialized");
94
+ }
95
+ let nodes;
96
+ if (nodeId === void 0) {
97
+ nodes = await this.commissioningController.connect(connectOptions);
98
+ } else {
99
+ nodes = [await this.commissioningController.connectNode((0, import_datatype.NodeId)(nodeId), connectOptions)];
100
+ }
101
+ return nodes;
102
+ }
103
+ async iterateNodeDevices(nodes, callback, endpointId) {
104
+ for (const node of nodes) {
105
+ let devices = node.getDevices();
106
+ if (endpointId !== void 0) {
107
+ devices = devices.filter((device) => device.number === endpointId);
108
+ }
109
+ for (const device of devices) {
110
+ await callback(device, node);
111
+ }
112
+ }
113
+ }
114
+ }
115
+ //# sourceMappingURL=MatterNode.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/MatterNode.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,qBAAuD;AACvD,oBAAmC;AACnC,oBAAsD;AACtD,sBAAuB;AAVvB;AAAA;AAAA;AAAA;AAAA;AAcA,MAAM,SAAS,sBAAO,IAAI,MAAM;AAEzB,MAAM,WAAW;AAAA,EASpB,YACqB,SACA,cACnB;AAFmB;AACA;AAAA,EAClB;AAAA,EAXK;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER;AAAA,EACQ;AAAA,EAOR,MAAM,WAAW,cAAuB;AAQpC,SAAK,kBAAkB,iBAAiB,KAAK,OAAO;AACpD,SAAK,UAAU,IAAI,iCAAmB,KAAK,iBAAiB,KAAK;AACjE,WAAO,KAAK,qBAAqB,KAAK,eAAe,cAAc;AACnE,SAAK,iBAAiB,IAAI,8BAAe,KAAK,OAAO;AACrD,UAAM,KAAK,eAAe,WAAW;AACrC,SAAK,iBAAiB,KAAK,eAAe,cAAc,MAAM;AAC9D,QAAI,cAAc;AACd,WAAK,QAAQ,SAAS,CAAC,CAAC;AAAA,IAC5B;AAAA,EACJ;AAAA,EAEA,IAAI,QAAQ;AACR,QAAI,CAAC,KAAK,gBAAgB;AACtB,YAAM,IAAI,MAAM,uBAAuB;AAAA,IAC3C;AACA,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,MAAM,QAAQ;AACV,UAAM,KAAK,kBAAkB,MAAM;AACnC,SAAK,aAAa;AAAA,EACtB;AAAA,EAEA,eAAe;AACX,QAAI;AACA,WAAK,SAAS,MAAM;AACpB,cAAQ,KAAK,CAAC;AAAA,IAClB,QAAQ;AACJ,cAAQ,KAAK,CAAC;AAAA,IAClB;AAAA,EACJ;AAAA,EAEA,MAAM,QAAQ;AACV,QAAI,KAAK,mBAAmB,QAAW;AACnC,YAAM,IAAI,MAAM,gCAAgC;AAAA,IACpD;AACA,QAAI,KAAK,qBAAqB,QAAW;AACrC;AAAA,IACJ;AACA,WAAO,KAAK,+CAA+C,KAAK,OAAO,EAAE;AAezE,SAAK,mBAAmB,IAAI,2BAAa,KAAK,gBAAgB,EAAE,eAAe,KAAK,aAAa,CAAC;AAClG,SAAK,0BAA0B,IAAI,sCAAwB;AAAA,MACvD,aAAa;AAAA,IACjB,CAAC;AACD,UAAM,KAAK,iBAAiB,2BAA2B,KAAK,uBAAuB;AASnF,UAAM,KAAK,iBAAiB,MAAM;AAAA,EACtC;AAAA,EAEA,MAAM,mBAAmB,WAAoB,gBAAqD;AAC9F,UAAM,KAAK,MAAM;AACjB,UAAM,SAAS,cAAc,aAAY,wBAAO,OAAO,SAAS,CAAC,IAAI;AAErE,QAAI,KAAK,4BAA4B,QAAW;AAC5C,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC7D;AACA,QAAI;AACJ,QAAI,WAAW,QAAW;AACtB,cAAQ,MAAM,KAAK,wBAAwB,QAAQ,cAAc;AAAA,IACrE,OAAO;AACH,cAAQ,CAAC,MAAM,KAAK,wBAAwB,gBAAY,wBAAO,MAAM,GAAG,cAAc,CAAC;AAAA,IAC3F;AACA,WAAO;AAAA,EACX;AAAA,EAEA,MAAM,mBACF,OACA,UACA,YACF;AACE,eAAW,QAAQ,OAAO;AACtB,UAAI,UAAU,KAAK,WAAW;AAC9B,UAAI,eAAe,QAAW;AAC1B,kBAAU,QAAQ,OAAO,YAAU,OAAO,WAAW,UAAU;AAAA,MACnE;AAEA,iBAAW,UAAU,SAAS;AAC1B,cAAM,SAAS,QAAQ,IAAI;AAAA,MAC/B;AAAA,IACJ;AAAA,EACJ;AACJ;",
5
+ "names": []
6
+ }