@matter/examples 0.12.0-alpha.0-20250101-22e7c1044 → 0.12.0-alpha.0-20250107-af5a068c3
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.
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* SPDX-License-Identifier: Apache-2.0
|
|
6
6
|
*/
|
|
7
7
|
import {
|
|
8
|
+
Bytes,
|
|
8
9
|
DeviceTypeId,
|
|
9
10
|
Endpoint,
|
|
10
11
|
EndpointServer,
|
|
@@ -18,7 +19,7 @@ import {
|
|
|
18
19
|
logLevelFromString,
|
|
19
20
|
singleton
|
|
20
21
|
} from "@matter/main";
|
|
21
|
-
import {
|
|
22
|
+
import { OnOffServer } from "@matter/main/behaviors";
|
|
22
23
|
import { NetworkCommissioning } from "@matter/main/clusters";
|
|
23
24
|
import { OnOffLightDevice, OnOffPlugInUnitDevice } from "@matter/main/devices";
|
|
24
25
|
import { RootRequirements } from "@matter/main/endpoints";
|
|
@@ -102,6 +103,7 @@ class OnOffShellExecServer extends OnOffServer {
|
|
|
102
103
|
class TestGeneralDiagnosticsServer extends RootRequirements.GeneralDiagnosticsServer {
|
|
103
104
|
initialize() {
|
|
104
105
|
this.state.testEventTriggersEnabled = true;
|
|
106
|
+
this.state.deviceTestEnableKey = Bytes.fromHex("0102030405060708090a0b0c0d0e0f10");
|
|
105
107
|
super.initialize();
|
|
106
108
|
}
|
|
107
109
|
testEventTrigger({ enableKey, eventTrigger }) {
|
|
@@ -120,25 +122,8 @@ class MyFancyOwnFunctionalityServer extends MyFancyOwnFunctionalityBehavior {
|
|
|
120
122
|
this.state.myFancyValue = -1;
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
|
-
const OnOffDevice = isSocket ?
|
|
124
|
-
|
|
125
|
-
let wifiOrThreadAdded = false;
|
|
126
|
-
let threadAdded = false;
|
|
127
|
-
if (Ble.enabled) {
|
|
128
|
-
if (environment.vars.has("ble.wifi.fake")) {
|
|
129
|
-
RootEndpoint = RootEndpoint.with(DummyWifiNetworkCommissioningServer);
|
|
130
|
-
wifiOrThreadAdded = true;
|
|
131
|
-
} else if (environment.vars.has("ble.thread.fake")) {
|
|
132
|
-
RootEndpoint = RootEndpoint.with(DummyThreadNetworkCommissioningServer);
|
|
133
|
-
wifiOrThreadAdded = true;
|
|
134
|
-
threadAdded = true;
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
RootEndpoint = RootEndpoint.with(
|
|
138
|
-
NetworkCommissioningServer.with(NetworkCommissioning.Feature.EthernetNetworkInterface)
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
const networkId = new Uint8Array(32);
|
|
125
|
+
const OnOffDevice = isSocket ? OnOffPlugInUnitDevice.with(OnOffShellExecServer) : OnOffLightDevice.with(OnOffShellExecServer);
|
|
126
|
+
const RootEndpoint = ServerNode.RootEndpoint.with(TestGeneralDiagnosticsServer);
|
|
142
127
|
const server = await ServerNode.create(RootEndpoint, {
|
|
143
128
|
id: uniqueId,
|
|
144
129
|
network: {
|
|
@@ -167,26 +152,43 @@ const server = await ServerNode.create(RootEndpoint, {
|
|
|
167
152
|
productId,
|
|
168
153
|
serialNumber: `node-matter-${uniqueId}`,
|
|
169
154
|
uniqueId
|
|
170
|
-
},
|
|
171
|
-
// @ts-expect-error ... TS do not see the types because both next clusters was added conditionally
|
|
172
|
-
networkCommissioning: {
|
|
173
|
-
maxNetworks: 1,
|
|
174
|
-
interfaceEnabled: true,
|
|
175
|
-
lastConnectErrorValue: 0,
|
|
176
|
-
lastNetworkId: wifiOrThreadAdded ? null : networkId,
|
|
177
|
-
lastNetworkingStatus: wifiOrThreadAdded ? null : NetworkCommissioning.NetworkCommissioningStatus.Success,
|
|
178
|
-
networks: [{ networkId, connected: !wifiOrThreadAdded }],
|
|
179
|
-
scanMaxTimeSeconds: wifiOrThreadAdded ? 3 : void 0,
|
|
180
|
-
connectMaxTimeSeconds: wifiOrThreadAdded ? 3 : void 0,
|
|
181
|
-
supportedWifiBands: wifiOrThreadAdded && !threadAdded ? [NetworkCommissioning.WiFiBand["2G4"]] : void 0,
|
|
182
|
-
supportedThreadFeatures: wifiOrThreadAdded && threadAdded ? { isFullThreadDevice: true } : void 0,
|
|
183
|
-
threadVersion: wifiOrThreadAdded && threadAdded ? 4 : void 0
|
|
184
|
-
// means: Thread 1.3
|
|
185
|
-
},
|
|
186
|
-
myFancyFunctionality: {
|
|
187
|
-
myFancyValue: 0
|
|
188
155
|
}
|
|
189
156
|
});
|
|
157
|
+
const networkId = new Uint8Array(32);
|
|
158
|
+
if (Ble.enabled) {
|
|
159
|
+
if (environment.vars.has("ble.wifi.fake")) {
|
|
160
|
+
server.behaviors.require(DummyWifiNetworkCommissioningServer, {
|
|
161
|
+
maxNetworks: 1,
|
|
162
|
+
interfaceEnabled: true,
|
|
163
|
+
lastConnectErrorValue: 0,
|
|
164
|
+
lastNetworkId: networkId,
|
|
165
|
+
lastNetworkingStatus: null,
|
|
166
|
+
networks: [{ networkId, connected: false }],
|
|
167
|
+
scanMaxTimeSeconds: 3,
|
|
168
|
+
connectMaxTimeSeconds: 3,
|
|
169
|
+
supportedWiFiBands: [NetworkCommissioning.WiFiBand["2G4"]]
|
|
170
|
+
});
|
|
171
|
+
} else if (environment.vars.has("ble.thread.fake")) {
|
|
172
|
+
server.behaviors.require(DummyThreadNetworkCommissioningServer, {
|
|
173
|
+
maxNetworks: 1,
|
|
174
|
+
interfaceEnabled: true,
|
|
175
|
+
lastConnectErrorValue: 0,
|
|
176
|
+
lastNetworkId: null,
|
|
177
|
+
lastNetworkingStatus: null,
|
|
178
|
+
networks: [{ networkId, connected: false }],
|
|
179
|
+
scanMaxTimeSeconds: 3,
|
|
180
|
+
connectMaxTimeSeconds: 3,
|
|
181
|
+
supportedThreadFeatures: { isFullThreadDevice: true },
|
|
182
|
+
threadVersion: 4
|
|
183
|
+
// means: Thread 1.3
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (vendorId === 65524) {
|
|
188
|
+
server.behaviors.require(MyFancyOwnFunctionalityServer, {
|
|
189
|
+
myFancyValue: 0
|
|
190
|
+
});
|
|
191
|
+
}
|
|
190
192
|
const endpoint = new Endpoint(OnOffDevice, { id: "onoff" });
|
|
191
193
|
await server.add(endpoint);
|
|
192
194
|
server.lifecycle.commissioned.on(() => console.log("Server was initially commissioned successfully!"));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/device-onoff-advanced/DeviceNodeFull.ts"],
|
|
4
|
-
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAqBA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,
|
|
4
|
+
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAqBA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,mBAAmB;AAC5B,SAA6B,4BAA4B;AACzD,SAAS,kBAAkB,6BAA6B;AACxD,SAAS,wBAAwB;AACjC,SAAS,KAAK,cAAc,mBAAmB;AAC/C,SAAS,cAAc;AACvB,SAAS,wBAAwB;AACjC,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,6CAA6C;AACtD,SAAS,2CAA2C;AACpD;AAAA,EAGI;AAAA,OACG;AAeP,MAAM,cAAc,YAAY;AAIhC,IAAI,YAAY,KAAK,IAAI,YAAY,GAAG;AAEpC,MAAI,MAAM;AAAA,IACN,MACI,IAAI,UAAU;AAAA,MACV,OAAO,YAAY,KAAK,OAAO,WAAW;AAAA,IAC9C,CAAC;AA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",
|
|
3
|
-
"version": "0.12.0-alpha.0-
|
|
3
|
+
"version": "0.12.0-alpha.0-20250107-af5a068c3",
|
|
4
4
|
"description": "Matter.js examples and reference implementations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"iot",
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"matter-controller": "dist/esm/controller/ControllerNode.js"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@matter/main": "0.12.0-alpha.0-
|
|
56
|
-
"@matter/nodejs": "0.12.0-alpha.0-
|
|
57
|
-
"@matter/tools": "0.12.0-alpha.0-
|
|
55
|
+
"@matter/main": "0.12.0-alpha.0-20250107-af5a068c3",
|
|
56
|
+
"@matter/nodejs": "0.12.0-alpha.0-20250107-af5a068c3",
|
|
57
|
+
"@matter/tools": "0.12.0-alpha.0-20250107-af5a068c3",
|
|
58
58
|
"esbuild": "^0.24.2"
|
|
59
59
|
},
|
|
60
60
|
"optionalDependencies": {
|
|
61
|
-
"@matter/nodejs-ble": "0.12.0-alpha.0-
|
|
61
|
+
"@matter/nodejs-ble": "0.12.0-alpha.0-20250107-af5a068c3"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=18.0.0"
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
import {
|
|
24
|
+
Bytes,
|
|
24
25
|
DeviceTypeId,
|
|
25
26
|
Endpoint,
|
|
26
27
|
EndpointServer,
|
|
@@ -34,7 +35,7 @@ import {
|
|
|
34
35
|
logLevelFromString,
|
|
35
36
|
singleton,
|
|
36
37
|
} from "@matter/main";
|
|
37
|
-
import {
|
|
38
|
+
import { OnOffServer } from "@matter/main/behaviors";
|
|
38
39
|
import { GeneralDiagnostics, NetworkCommissioning } from "@matter/main/clusters";
|
|
39
40
|
import { OnOffLightDevice, OnOffPlugInUnitDevice } from "@matter/main/devices";
|
|
40
41
|
import { RootRequirements } from "@matter/main/endpoints";
|
|
@@ -164,6 +165,7 @@ class OnOffShellExecServer extends OnOffServer {
|
|
|
164
165
|
class TestGeneralDiagnosticsServer extends RootRequirements.GeneralDiagnosticsServer {
|
|
165
166
|
override initialize() {
|
|
166
167
|
this.state.testEventTriggersEnabled = true; // set to true if you support test triggers ...
|
|
168
|
+
this.state.deviceTestEnableKey = Bytes.fromHex("0102030405060708090a0b0c0d0e0f10");
|
|
167
169
|
super.initialize();
|
|
168
170
|
}
|
|
169
171
|
|
|
@@ -205,12 +207,8 @@ class MyFancyOwnFunctionalityServer extends MyFancyOwnFunctionalityBehavior {
|
|
|
205
207
|
// In this case we are using with() to install our On/Off cluster behavior.
|
|
206
208
|
// .with("Lighting") not needed because we always have it in by default because we have default implementation
|
|
207
209
|
const OnOffDevice = isSocket
|
|
208
|
-
?
|
|
209
|
-
|
|
210
|
-
: OnOffPlugInUnitDevice.with(OnOffShellExecServer)
|
|
211
|
-
: vendorId === 0xfff4
|
|
212
|
-
? OnOffLightDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer)
|
|
213
|
-
: OnOffLightDevice.with(OnOffShellExecServer);
|
|
210
|
+
? OnOffPlugInUnitDevice.with(OnOffShellExecServer)
|
|
211
|
+
: OnOffLightDevice.with(OnOffShellExecServer);
|
|
214
212
|
|
|
215
213
|
/**
|
|
216
214
|
* Modify automatically added clusters of the Root endpoint if needed
|
|
@@ -222,32 +220,8 @@ const OnOffDevice = isSocket
|
|
|
222
220
|
*/
|
|
223
221
|
|
|
224
222
|
// We use the Basic Root Endpoint without a NetworkCommissioning cluster
|
|
225
|
-
|
|
223
|
+
const RootEndpoint = ServerNode.RootEndpoint.with(TestGeneralDiagnosticsServer);
|
|
226
224
|
|
|
227
|
-
let wifiOrThreadAdded = false;
|
|
228
|
-
let threadAdded = false;
|
|
229
|
-
if (Ble.enabled) {
|
|
230
|
-
// matter.js will create a Ethernet-only device by default when ut comes to Network Commissioning Features.
|
|
231
|
-
// To offer e.g. a "Wi-Fi only device" (or any other combination) we need to override the Network Commissioning
|
|
232
|
-
// cluster and implement all the need handling here. This is a "static implementation" for pure demonstration
|
|
233
|
-
// purposes and just "simulates" the actions to be done. In a real world implementation this would be done by
|
|
234
|
-
// the device implementor based on the relevant networking stack.
|
|
235
|
-
// The NetworkCommissioningCluster and all logics are described in Matter Core Specifications section 11.8
|
|
236
|
-
if (environment.vars.has("ble.wifi.fake")) {
|
|
237
|
-
RootEndpoint = RootEndpoint.with(DummyWifiNetworkCommissioningServer);
|
|
238
|
-
wifiOrThreadAdded = true;
|
|
239
|
-
} else if (environment.vars.has("ble.thread.fake")) {
|
|
240
|
-
RootEndpoint = RootEndpoint.with(DummyThreadNetworkCommissioningServer);
|
|
241
|
-
wifiOrThreadAdded = true;
|
|
242
|
-
threadAdded = true;
|
|
243
|
-
}
|
|
244
|
-
} else {
|
|
245
|
-
RootEndpoint = RootEndpoint.with(
|
|
246
|
-
NetworkCommissioningServer.with(NetworkCommissioning.Feature.EthernetNetworkInterface),
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const networkId = new Uint8Array(32);
|
|
251
225
|
// Physical devices appear as "nodes" on a Matter network. As a device implementer you use a NodeServer to bring a
|
|
252
226
|
// device online.
|
|
253
227
|
//
|
|
@@ -281,28 +255,54 @@ const server = await ServerNode.create(RootEndpoint, {
|
|
|
281
255
|
serialNumber: `node-matter-${uniqueId}`,
|
|
282
256
|
uniqueId,
|
|
283
257
|
},
|
|
258
|
+
});
|
|
284
259
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
260
|
+
const networkId = new Uint8Array(32);
|
|
261
|
+
if (Ble.enabled) {
|
|
262
|
+
// matter.js will create an Ethernet-only device by default when it comes to Network Commissioning Features.
|
|
263
|
+
// To offer e.g. a "Wi-Fi only device" (or any other combination) we need to override the Network Commissioning
|
|
264
|
+
// cluster and implement all the need handling here. This is a "static implementation" for pure demonstration
|
|
265
|
+
// purposes and just "simulates" the actions to be done. In a real world implementation this would be done by
|
|
266
|
+
// the device implementor based on the relevant networking stack.
|
|
267
|
+
// The NetworkCommissioningCluster and all logics are described in Matter Core Specifications section 11.8
|
|
268
|
+
if (environment.vars.has("ble.wifi.fake")) {
|
|
269
|
+
server.behaviors.require(DummyWifiNetworkCommissioningServer, {
|
|
270
|
+
maxNetworks: 1,
|
|
271
|
+
interfaceEnabled: true,
|
|
272
|
+
lastConnectErrorValue: 0,
|
|
273
|
+
lastNetworkId: networkId,
|
|
274
|
+
lastNetworkingStatus: null,
|
|
275
|
+
networks: [{ networkId: networkId, connected: false }],
|
|
276
|
+
scanMaxTimeSeconds: 3,
|
|
277
|
+
connectMaxTimeSeconds: 3,
|
|
278
|
+
supportedWiFiBands: [NetworkCommissioning.WiFiBand["2G4"]],
|
|
279
|
+
});
|
|
280
|
+
} else if (environment.vars.has("ble.thread.fake")) {
|
|
281
|
+
server.behaviors.require(DummyThreadNetworkCommissioningServer, {
|
|
282
|
+
maxNetworks: 1,
|
|
283
|
+
interfaceEnabled: true,
|
|
284
|
+
lastConnectErrorValue: 0,
|
|
285
|
+
lastNetworkId: null,
|
|
286
|
+
lastNetworkingStatus: null,
|
|
287
|
+
networks: [{ networkId: networkId, connected: false }],
|
|
288
|
+
scanMaxTimeSeconds: 3,
|
|
289
|
+
connectMaxTimeSeconds: 3,
|
|
290
|
+
supportedThreadFeatures: { isFullThreadDevice: true },
|
|
291
|
+
threadVersion: 4, // means: Thread 1.3
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Also add our Custom behavior when vendor id is 0xfff4 (just to show how it works)
|
|
297
|
+
if (vendorId === 0xfff4) {
|
|
298
|
+
server.behaviors.require(MyFancyOwnFunctionalityServer, {
|
|
300
299
|
myFancyValue: 0,
|
|
301
|
-
}
|
|
302
|
-
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
303
302
|
|
|
304
303
|
// Nodes are a composition of endpoints. Add a single endpoint to the node, our example light device.
|
|
305
304
|
const endpoint = new Endpoint(OnOffDevice, { id: "onoff" });
|
|
305
|
+
|
|
306
306
|
await server.add(endpoint);
|
|
307
307
|
|
|
308
308
|
/**
|
|
@@ -317,7 +317,7 @@ server.lifecycle.decommissioned.on(() => console.log("Server was fully decommiss
|
|
|
317
317
|
/** This event is triggered when the device went online. This means that it is discoverable in the network. */
|
|
318
318
|
server.lifecycle.online.on(() => console.log("Server is online"));
|
|
319
319
|
|
|
320
|
-
/** This event is triggered when the device went offline.
|
|
320
|
+
/** This event is triggered when the device went offline. It is no longer discoverable or connectable in the network. */
|
|
321
321
|
server.lifecycle.offline.on(() => console.log("Server is offline"));
|
|
322
322
|
|
|
323
323
|
/**
|
|
@@ -24,21 +24,21 @@ For this to work you first of all need to enable BLE by using `--ble-enable` to
|
|
|
24
24
|
Please also make sure you follow the [BLE enablement steps for your operating system](../../../nodejs-ble/README.md#prerequisites-and-limitations).
|
|
25
25
|
|
|
26
26
|
The following parameters are available:
|
|
27
|
-
* --ble: enable BLE support (default: false) If this is enabled the device will announce itself _only_ via BLE if not commissioned and also presents a "Wifi only" device for commissioning to show this feature!
|
|
28
|
-
* --ble-hci-id
|
|
27
|
+
* --ble-enable: enable BLE support (default: false) If this is enabled the device will announce itself _only_ via BLE if not commissioned and also presents a "Wifi only" device for commissioning to show this feature!
|
|
28
|
+
* --ble-hci-id=...: Optionally, HCI ID to use (Linux only, default 0)
|
|
29
29
|
|
|
30
30
|
Additionally, you need to choose if the device should simulate a Thread or a Wifi enabled device. This can be done by adding `--ble-fake-wifi` or `--ble-fake-thread` to the command line. Then a dummy WifiNetworkCommissioning or ThreadNetworkCommissioning cluster is added to the device node.
|
|
31
31
|
|
|
32
32
|
Depending on the method you chose you probably need to also add additional parameters for either Wifi or thread which are returned when the device is asked to scn for available networks.
|
|
33
33
|
|
|
34
34
|
For Wifi the parameters to use are:
|
|
35
|
-
* --ble-wifi-
|
|
36
|
-
* --ble-wifi-
|
|
35
|
+
* --ble-wifi-scanSsid=...: The Wi-Fi SSID returned by the "ScanNetworks" call of the Wifi Network commissioning cluster used when using BLE commissioning (default: "TestSSID"). Ideally use a really existing SSID that also the commissioner (Apple, Alexa, ...) knows to make it easier to commission. Else you could get errors while commissioning.
|
|
36
|
+
* --ble-wifi-scanBssid=...: The Wi-Fi BSSID returned by the "ScanNetworks" call of the Wifi Network commissioning cluster used when using BLE commissioning (default: "00:00:00:00:00:00").
|
|
37
37
|
|
|
38
38
|
For Thread the parameters to use are:
|
|
39
|
-
* --ble.thread.
|
|
40
|
-
* --ble.thread.
|
|
41
|
-
* --ble.thread.
|
|
42
|
-
* --ble.thread.channel
|
|
43
|
-
* --ble.thread.address
|
|
39
|
+
* --ble.thread.panId=...: The PAN ID to use for the Thread network
|
|
40
|
+
* --ble.thread.extendedPanId=...: The extended PAN ID to use for the Thread network
|
|
41
|
+
* --ble.thread.networkName=...: The network name to use for the Thread network
|
|
42
|
+
* --ble.thread.channel=...: The channel to use for the Thread network
|
|
43
|
+
* --ble.thread.address=...: The address to use for the Thread network
|
|
44
44
|
Thread parameters are as of now only needed when commissioning with Amazon because the others are currently not scanning for Thread networks.
|