@matter/examples 0.11.0-alpha.0-20241005-e3e4e4a7a
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.
- package/LICENSE +201 -0
- package/README.md +274 -0
- package/dist/esm/examples/BridgedDevicesNode.js +138 -0
- package/dist/esm/examples/BridgedDevicesNode.js.map +6 -0
- package/dist/esm/examples/ComposedDeviceNode.js +118 -0
- package/dist/esm/examples/ComposedDeviceNode.js.map +6 -0
- package/dist/esm/examples/ControllerNode.js +191 -0
- package/dist/esm/examples/ControllerNode.js.map +6 -0
- package/dist/esm/examples/DeviceNode.js +130 -0
- package/dist/esm/examples/DeviceNode.js.map +6 -0
- package/dist/esm/examples/DeviceNodeFull.js +259 -0
- package/dist/esm/examples/DeviceNodeFull.js.map +6 -0
- package/dist/esm/examples/IlluminatedRollerShade.js +56 -0
- package/dist/esm/examples/IlluminatedRollerShade.js.map +6 -0
- package/dist/esm/examples/LightDevice.js +34 -0
- package/dist/esm/examples/LightDevice.js.map +6 -0
- package/dist/esm/examples/MultiDeviceNode.js +143 -0
- package/dist/esm/examples/MultiDeviceNode.js.map +6 -0
- package/dist/esm/examples/SensorDeviceNode.js +170 -0
- package/dist/esm/examples/SensorDeviceNode.js.map +6 -0
- package/dist/esm/examples/cluster/DummyThreadNetworkCommissioningServer.js +121 -0
- package/dist/esm/examples/cluster/DummyThreadNetworkCommissioningServer.js.map +6 -0
- package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServer.js +121 -0
- package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServer.js.map +6 -0
- package/dist/esm/examples/cluster/MyFancyOwnFunctionality.js +113 -0
- package/dist/esm/examples/cluster/MyFancyOwnFunctionality.js.map +6 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/tutorial/example01.js +4 -0
- package/dist/esm/tutorial/example01.js.map +6 -0
- package/dist/esm/tutorial/example02.js +6 -0
- package/dist/esm/tutorial/example02.js.map +6 -0
- package/dist/esm/tutorial/example03.js +14 -0
- package/dist/esm/tutorial/example03.js.map +6 -0
- package/dist/esm/tutorial/example04.js +9 -0
- package/dist/esm/tutorial/example04.js.map +6 -0
- package/dist/esm/tutorial/example05.js +13 -0
- package/dist/esm/tutorial/example05.js.map +6 -0
- package/package.json +70 -0
- package/src/examples/BridgedDevicesNode.ts +247 -0
- package/src/examples/ComposedDeviceNode.ts +185 -0
- package/src/examples/ControllerNode.ts +305 -0
- package/src/examples/DeviceNode.ts +198 -0
- package/src/examples/DeviceNodeFull.ts +440 -0
- package/src/examples/IlluminatedRollerShade.ts +89 -0
- package/src/examples/LightDevice.ts +58 -0
- package/src/examples/MultiDeviceNode.ts +205 -0
- package/src/examples/SensorDeviceNode.ts +236 -0
- package/src/examples/cluster/DummyThreadNetworkCommissioningServer.ts +162 -0
- package/src/examples/cluster/DummyWifiNetworkCommissioningServer.ts +160 -0
- package/src/examples/cluster/MyFancyOwnFunctionality.ts +188 -0
- package/src/tsconfig.json +13 -0
- package/src/tsconfig.tsbuildinfo +1 -0
- package/src/tutorial/example01.ts +5 -0
- package/src/tutorial/example02.ts +8 -0
- package/src/tutorial/example03.ts +18 -0
- package/src/tutorial/example04.ts +12 -0
- package/src/tutorial/example05.ts +18 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2022-2024 Matter.js Authors
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
DeviceTypeId,
|
|
9
|
+
Endpoint,
|
|
10
|
+
EndpointServer,
|
|
11
|
+
Environment,
|
|
12
|
+
LogLevel,
|
|
13
|
+
Logger,
|
|
14
|
+
ServerNode,
|
|
15
|
+
StorageService,
|
|
16
|
+
Time,
|
|
17
|
+
VendorId,
|
|
18
|
+
logLevelFromString,
|
|
19
|
+
singleton
|
|
20
|
+
} from "@matter/main";
|
|
21
|
+
import { NetworkCommissioningServer } from "@matter/main/behaviors/network-commissioning";
|
|
22
|
+
import { OnOffServer } from "@matter/main/behaviors/on-off";
|
|
23
|
+
import { NetworkCommissioning } from "@matter/main/clusters";
|
|
24
|
+
import { OnOffLightDevice } from "@matter/main/devices/on-off-light";
|
|
25
|
+
import { OnOffPlugInUnitDevice } from "@matter/main/devices/on-off-plug-in-unit";
|
|
26
|
+
import { RootRequirements } from "@matter/main/endpoints/root";
|
|
27
|
+
import { Ble, FabricAction, logEndpoint } from "@matter/main/protocol";
|
|
28
|
+
import { QrCode } from "@matter/main/types";
|
|
29
|
+
import { createFileLogger } from "@matter/nodejs";
|
|
30
|
+
import { NodeJsBle } from "@matter/nodejs-ble";
|
|
31
|
+
import { execSync } from "child_process";
|
|
32
|
+
import { DummyThreadNetworkCommissioningServer } from "./cluster/DummyThreadNetworkCommissioningServer.js";
|
|
33
|
+
import { DummyWifiNetworkCommissioningServer } from "./cluster/DummyWifiNetworkCommissioningServer.js";
|
|
34
|
+
import {
|
|
35
|
+
MyFancyOwnFunctionalityBehavior
|
|
36
|
+
} from "./cluster/MyFancyOwnFunctionality.js";
|
|
37
|
+
const environment = Environment.default;
|
|
38
|
+
if (environment.vars.get("ble.enable")) {
|
|
39
|
+
Ble.get = singleton(
|
|
40
|
+
() => new NodeJsBle({
|
|
41
|
+
hciId: environment.vars.number("ble.hciId")
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
function executeCommand(scriptParamName) {
|
|
46
|
+
const script = environment.vars.string(scriptParamName);
|
|
47
|
+
if (script === void 0) return void 0;
|
|
48
|
+
console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);
|
|
49
|
+
}
|
|
50
|
+
const logFile = environment.vars.string("logfile.filename");
|
|
51
|
+
if (logFile !== void 0) {
|
|
52
|
+
Logger.addLogger("filelogger", await createFileLogger(logFile), {
|
|
53
|
+
defaultLogLevel: logLevelFromString(environment.vars.string("logfile.loglevel")) ?? LogLevel.DEBUG
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const storageService = environment.get(StorageService);
|
|
57
|
+
console.log(`Storage location: ${storageService.location} (Directory)`);
|
|
58
|
+
console.log(
|
|
59
|
+
'Use the parameter "--storage-path=NAME-OR-PATH" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.'
|
|
60
|
+
);
|
|
61
|
+
const deviceStorage = (await storageService.open("device")).createContext("data");
|
|
62
|
+
if (await deviceStorage.has("isSocket")) {
|
|
63
|
+
console.log("Device type found in storage. --type parameter is ignored.");
|
|
64
|
+
}
|
|
65
|
+
const isSocket = await deviceStorage.get("isSocket", environment.vars.string("type") === "socket");
|
|
66
|
+
const deviceName = "Matter test device";
|
|
67
|
+
const vendorName = "matter-node.js";
|
|
68
|
+
const passcode = environment.vars.number("passcode") ?? await deviceStorage.get("passcode", 20202021);
|
|
69
|
+
const discriminator = environment.vars.number("discriminator") ?? await deviceStorage.get("discriminator", 3840);
|
|
70
|
+
const vendorId = environment.vars.number("vendorid") ?? await deviceStorage.get("vendorid", 65521);
|
|
71
|
+
const productName = `node-matter OnOff ${isSocket ? "Socket" : "Light"}`;
|
|
72
|
+
const productId = environment.vars.number("productid") ?? await deviceStorage.get("productid", 32768);
|
|
73
|
+
const port = environment.vars.number("port") ?? 5540;
|
|
74
|
+
const uniqueId = environment.vars.string("uniqueid") ?? await deviceStorage.get("uniqueid", Time.nowMs().toString());
|
|
75
|
+
await deviceStorage.set({
|
|
76
|
+
passcode,
|
|
77
|
+
discriminator,
|
|
78
|
+
vendorid: vendorId,
|
|
79
|
+
productid: productId,
|
|
80
|
+
isSocket,
|
|
81
|
+
uniqueid: uniqueId
|
|
82
|
+
});
|
|
83
|
+
class OnOffShellExecServer extends OnOffServer {
|
|
84
|
+
// Intercept the "on" command to the Matter On/Off cluster to print a log message.
|
|
85
|
+
async on() {
|
|
86
|
+
executeCommand("on");
|
|
87
|
+
await super.on();
|
|
88
|
+
}
|
|
89
|
+
// This is the functional inverse of on() above.
|
|
90
|
+
//
|
|
91
|
+
// For demonstration purposes we update state ourselves rather than deferring to matter.js's default "off" handler
|
|
92
|
+
// via super.off().
|
|
93
|
+
async off() {
|
|
94
|
+
executeCommand("off");
|
|
95
|
+
this.state.onOff = false;
|
|
96
|
+
}
|
|
97
|
+
// Use event handlers to log on/off state reactively, after it changes.
|
|
98
|
+
initialize() {
|
|
99
|
+
this.events.onOff$Changed.on((value) => {
|
|
100
|
+
console.log(`Light is now ${value ? "ON" : "OFF"}`);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
class TestGeneralDiagnosticsServer extends RootRequirements.GeneralDiagnosticsServer {
|
|
105
|
+
initialize() {
|
|
106
|
+
this.state.testEventTriggersEnabled = true;
|
|
107
|
+
super.initialize();
|
|
108
|
+
}
|
|
109
|
+
testEventTrigger({ enableKey, eventTrigger }) {
|
|
110
|
+
console.log(`testEventTrigger called on GeneralDiagnostic cluster: ${enableKey} ${eventTrigger}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
class MyFancyOwnFunctionalityServer extends MyFancyOwnFunctionalityBehavior {
|
|
114
|
+
/** We return the incoming value and store the length of the string in our attribute and send it out as event */
|
|
115
|
+
myFancyCommand(request) {
|
|
116
|
+
const { value } = request;
|
|
117
|
+
this.state.myFancyValue = value.length;
|
|
118
|
+
this.events.myFancyEvent.emit({ eventValue: value }, this.context);
|
|
119
|
+
return { response: value };
|
|
120
|
+
}
|
|
121
|
+
initialize() {
|
|
122
|
+
this.state.myFancyValue = -1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const OnOffDevice = isSocket ? vendorId === 65524 ? OnOffPlugInUnitDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer) : OnOffPlugInUnitDevice.with(OnOffShellExecServer) : vendorId === 65524 ? OnOffLightDevice.with(OnOffShellExecServer, MyFancyOwnFunctionalityServer) : OnOffLightDevice.with(OnOffShellExecServer);
|
|
126
|
+
let RootEndpoint = ServerNode.RootEndpoint.with(TestGeneralDiagnosticsServer);
|
|
127
|
+
let wifiOrThreadAdded = false;
|
|
128
|
+
let threadAdded = false;
|
|
129
|
+
if (Ble.enabled) {
|
|
130
|
+
if (environment.vars.has("ble.wifi.fake")) {
|
|
131
|
+
RootEndpoint = RootEndpoint.with(DummyWifiNetworkCommissioningServer);
|
|
132
|
+
wifiOrThreadAdded = true;
|
|
133
|
+
} else if (environment.vars.has("ble.thread.fake")) {
|
|
134
|
+
RootEndpoint = RootEndpoint.with(DummyThreadNetworkCommissioningServer);
|
|
135
|
+
wifiOrThreadAdded = true;
|
|
136
|
+
threadAdded = true;
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
RootEndpoint = RootEndpoint.with(
|
|
140
|
+
NetworkCommissioningServer.with(NetworkCommissioning.Feature.EthernetNetworkInterface)
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
const networkId = new Uint8Array(32);
|
|
144
|
+
const server = await ServerNode.create(RootEndpoint, {
|
|
145
|
+
id: uniqueId,
|
|
146
|
+
network: {
|
|
147
|
+
port,
|
|
148
|
+
discoveryCapabilities: {
|
|
149
|
+
onIpNetwork: !environment.vars.has("ble.enable"),
|
|
150
|
+
ble: environment.vars.has("ble.enable")
|
|
151
|
+
},
|
|
152
|
+
ble: environment.vars.has("ble.enable")
|
|
153
|
+
// TODO remove when state init is fixed
|
|
154
|
+
},
|
|
155
|
+
commissioning: {
|
|
156
|
+
passcode,
|
|
157
|
+
discriminator
|
|
158
|
+
},
|
|
159
|
+
productDescription: {
|
|
160
|
+
name: deviceName,
|
|
161
|
+
deviceType: DeviceTypeId(OnOffDevice.deviceType)
|
|
162
|
+
},
|
|
163
|
+
basicInformation: {
|
|
164
|
+
vendorName,
|
|
165
|
+
vendorId: VendorId(vendorId),
|
|
166
|
+
nodeLabel: productName,
|
|
167
|
+
productName,
|
|
168
|
+
productLabel: productName,
|
|
169
|
+
productId,
|
|
170
|
+
serialNumber: `node-matter-${uniqueId}`,
|
|
171
|
+
uniqueId
|
|
172
|
+
},
|
|
173
|
+
// @ts-expect-error ... TS do not see the types because both next clusters was added conditionally
|
|
174
|
+
networkCommissioning: {
|
|
175
|
+
maxNetworks: 1,
|
|
176
|
+
interfaceEnabled: true,
|
|
177
|
+
lastConnectErrorValue: 0,
|
|
178
|
+
lastNetworkId: wifiOrThreadAdded ? null : networkId,
|
|
179
|
+
lastNetworkingStatus: wifiOrThreadAdded ? null : NetworkCommissioning.NetworkCommissioningStatus.Success,
|
|
180
|
+
networks: [{ networkId, connected: !wifiOrThreadAdded }],
|
|
181
|
+
scanMaxTimeSeconds: wifiOrThreadAdded ? 3 : void 0,
|
|
182
|
+
connectMaxTimeSeconds: wifiOrThreadAdded ? 3 : void 0,
|
|
183
|
+
supportedWifiBands: wifiOrThreadAdded && !threadAdded ? [NetworkCommissioning.WiFiBand["2G4"]] : void 0,
|
|
184
|
+
supportedThreadFeatures: wifiOrThreadAdded && threadAdded ? { isFullThreadDevice: true } : void 0,
|
|
185
|
+
threadVersion: wifiOrThreadAdded && threadAdded ? 4 : void 0
|
|
186
|
+
// means: Thread 1.3
|
|
187
|
+
},
|
|
188
|
+
myFancyFunctionality: {
|
|
189
|
+
myFancyValue: 0
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
const endpoint = new Endpoint(OnOffDevice, { id: "onoff" });
|
|
193
|
+
await server.add(endpoint);
|
|
194
|
+
server.lifecycle.commissioned.on(() => console.log("Server was initially commissioned successfully!"));
|
|
195
|
+
server.lifecycle.decommissioned.on(() => console.log("Server was fully decommissioned successfully!"));
|
|
196
|
+
server.lifecycle.online.on(() => console.log("Server is online"));
|
|
197
|
+
server.lifecycle.offline.on(() => console.log("Server is offline"));
|
|
198
|
+
server.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {
|
|
199
|
+
let action = "";
|
|
200
|
+
switch (fabricAction) {
|
|
201
|
+
case FabricAction.Added:
|
|
202
|
+
action = "added";
|
|
203
|
+
break;
|
|
204
|
+
case FabricAction.Removed:
|
|
205
|
+
action = "removed";
|
|
206
|
+
break;
|
|
207
|
+
case FabricAction.Updated:
|
|
208
|
+
action = "updated";
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
console.log(`Commissioned Fabrics changed event (${action}) for ${fabricIndex} triggered`);
|
|
212
|
+
console.log(server.state.commissioning.fabrics[fabricIndex]);
|
|
213
|
+
});
|
|
214
|
+
server.events.sessions.opened.on((session) => console.log(`Session opened`, session));
|
|
215
|
+
server.events.sessions.closed.on((session) => console.log(`Session closed`, session));
|
|
216
|
+
server.events.sessions.subscriptionsChanged.on((session) => {
|
|
217
|
+
console.log(`Session subscriptions changed`, session);
|
|
218
|
+
console.log(`Status of all sessions`, server.state.sessions.sessions);
|
|
219
|
+
});
|
|
220
|
+
endpoint.events.identify.startIdentifying.on(() => {
|
|
221
|
+
console.log(`Run identify logic, ideally blink a light every 0.5s ...`);
|
|
222
|
+
});
|
|
223
|
+
endpoint.events.identify.stopIdentifying.on(() => {
|
|
224
|
+
console.log(`Stop identify logic ...`);
|
|
225
|
+
});
|
|
226
|
+
logEndpoint(EndpointServer.forEndpoint(server));
|
|
227
|
+
await server.start();
|
|
228
|
+
console.log("Initial Fabrics", server.state.operationalCredentials.fabrics);
|
|
229
|
+
if (!server.lifecycle.isCommissioned) {
|
|
230
|
+
const { qrPairingCode, manualPairingCode } = server.state.commissioning.pairingCodes;
|
|
231
|
+
console.log(QrCode.get(qrPairingCode));
|
|
232
|
+
console.log(`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`);
|
|
233
|
+
console.log(`Manual pairing code: ${manualPairingCode}`);
|
|
234
|
+
} else {
|
|
235
|
+
console.log("Device is already commissioned. Waiting for controllers to connect ...");
|
|
236
|
+
const onOffValue = endpoint.state.onOff.onOff;
|
|
237
|
+
console.log(`current OnOff attribute: ${onOffValue}`);
|
|
238
|
+
if (vendorId === 65524) {
|
|
239
|
+
await endpoint.set({
|
|
240
|
+
onOff: {
|
|
241
|
+
onOff: !onOffValue
|
|
242
|
+
},
|
|
243
|
+
// @ts-expect-error Needed because the Fancy cluster is added conditionally, so TS do not get that it's there.
|
|
244
|
+
myFancyOwnFunctionality: {
|
|
245
|
+
myFancyValue: 36
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
} else {
|
|
249
|
+
await endpoint.set({
|
|
250
|
+
onOff: {
|
|
251
|
+
onOff: !onOffValue
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
process.on("SIGINT", () => {
|
|
257
|
+
server.close().then(() => process.exit(0)).catch((err) => console.error(err));
|
|
258
|
+
});
|
|
259
|
+
//# sourceMappingURL=DeviceNodeFull.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/examples/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,kCAAkC;AAC3C,SAAS,mBAAmB;AAC5B,SAA6B,4BAA4B;AACzD,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,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,OAA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KAAK,CAAC,CAAC,EAC1B,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AACxC,CAAC;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2022-2024 Matter.js Authors
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
import { ServerNode } from "@matter/main";
|
|
8
|
+
import { MovementDirection, WindowCoveringServer } from "@matter/main/behaviors/window-covering";
|
|
9
|
+
import { OnOffLightDevice, OnOffLightRequirements } from "@matter/main/devices/on-off-light";
|
|
10
|
+
import { WindowCoveringDevice } from "@matter/main/devices/window-covering";
|
|
11
|
+
const LiftingWindowCoveringServer = WindowCoveringServer.with("Lift", "AbsolutePosition", "PositionAwareLift");
|
|
12
|
+
class RollerShade extends LiftingWindowCoveringServer {
|
|
13
|
+
async handleMovement(type, reversed, direction, targetPercent100ths) {
|
|
14
|
+
console.log(
|
|
15
|
+
"Move window shade",
|
|
16
|
+
direction === MovementDirection.Open ? "Open" : "Close",
|
|
17
|
+
targetPercent100ths !== void 0 ? `${targetPercent100ths / 100}%` : ""
|
|
18
|
+
);
|
|
19
|
+
await super.handleMovement(type, reversed, direction, targetPercent100ths);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
class ValanceLight extends OnOffLightRequirements.OnOffServer {
|
|
23
|
+
initialize() {
|
|
24
|
+
this.reactTo(this.events.onOff$Changed, this.#stateChanged);
|
|
25
|
+
}
|
|
26
|
+
#stateChanged(value) {
|
|
27
|
+
console.log(`Valance is now ${value ? "illuminated" : "dark"}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const node = new ServerNode({
|
|
31
|
+
id: "excelsior1000",
|
|
32
|
+
productDescription: {},
|
|
33
|
+
commissioning: {
|
|
34
|
+
passcode: 20202021,
|
|
35
|
+
discriminator: 3840
|
|
36
|
+
},
|
|
37
|
+
basicInformation: {
|
|
38
|
+
vendorName: "Acme Corporation",
|
|
39
|
+
productName: "Excelsior 1000 EZ-Nite\u2122",
|
|
40
|
+
vendorId: 65521,
|
|
41
|
+
productId: 32768,
|
|
42
|
+
serialNumber: "1234-12345-123"
|
|
43
|
+
},
|
|
44
|
+
parts: [
|
|
45
|
+
{
|
|
46
|
+
type: WindowCoveringDevice.with(RollerShade),
|
|
47
|
+
id: "shade"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: OnOffLightDevice.with(ValanceLight),
|
|
51
|
+
id: "valance"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
await node.run();
|
|
56
|
+
//# sourceMappingURL=IlluminatedRollerShade.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/examples/IlluminatedRollerShade.ts"],
|
|
4
|
+
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,kBAAkB;AAC3B,SAAS,mBAAiC,4BAA4B;AACtE,SAAS,kBAAkB,8BAA8B;AACzD,SAAS,4BAA4B;AAQrC,MAAM,8BAA8B,qBAAqB,KAAK,QAAQ,oBAAoB,mBAAmB;AAK7G,MAAM,oBAAoB,4BAA4B;AAAA,EAClD,MAAe,eACX,MACA,UACA,WACA,qBACF;AACE,YAAQ;AAAA,MACJ;AAAA,MACA,cAAc,kBAAkB,OAAO,SAAS;AAAA,MAChD,wBAAwB,SAAY,GAAG,sBAAsB,GAAG,MAAM;AAAA,IAC1E;AAGA,UAAM,MAAM,eAAe,MAAM,UAAU,WAAW,mBAAmB;AAAA,EAC7E;AACJ;AAKA,MAAM,qBAAqB,uBAAuB,YAAY;AAAA,EACjD,aAAa;AAClB,SAAK,QAAQ,KAAK,OAAO,eAAe,KAAK,aAAa;AAAA,EAC9D;AAAA,EAEA,cAAc,OAAgB;AAC1B,YAAQ,IAAI,kBAAkB,QAAQ,gBAAgB,MAAM,EAAE;AAAA,EAClE;AACJ;AAKA,MAAM,OAAO,IAAI,WAAW;AAAA,EACxB,IAAI;AAAA,EAEJ,oBAAoB,CAAC;AAAA,EAErB,eAAe;AAAA,IACX,UAAU;AAAA,IACV,eAAe;AAAA,EACnB;AAAA,EAEA,kBAAkB;AAAA,IACd,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,UAAU;AAAA,IACV,WAAW;AAAA,IACX,cAAc;AAAA,EAClB;AAAA,EAEA,OAAO;AAAA,IACH;AAAA,MACI,MAAM,qBAAqB,KAAK,WAAW;AAAA,MAC3C,IAAI;AAAA,IACR;AAAA,IAEA;AAAA,MACI,MAAM,iBAAiB,KAAK,YAAY;AAAA,MACxC,IAAI;AAAA,IACR;AAAA,EACJ;AACJ,CAAC;AAED,MAAM,KAAK,IAAI;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2022-2024 Matter.js Authors
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
import { ServerNode } from "@matter/main";
|
|
8
|
+
import { OnOffLightDevice, OnOffLightRequirements } from "@matter/main/devices/on-off-light";
|
|
9
|
+
class ReportingOnOffServer extends OnOffLightRequirements.OnOffServer {
|
|
10
|
+
// Intercept the "on" command to the Matter On/Off cluster to print a log message.
|
|
11
|
+
async on() {
|
|
12
|
+
console.log("Turning light ON");
|
|
13
|
+
await super.on();
|
|
14
|
+
}
|
|
15
|
+
// This is the functional inverse of on() above.
|
|
16
|
+
//
|
|
17
|
+
// For demonstration purposes we update state ourselves rather than deferring to matter.js's default "off" handler
|
|
18
|
+
// via super.off().
|
|
19
|
+
off() {
|
|
20
|
+
console.log("Turning light OFF");
|
|
21
|
+
this.state.onOff = false;
|
|
22
|
+
}
|
|
23
|
+
// Use event handlers to log on/off state reactively, after it changes.
|
|
24
|
+
initialize() {
|
|
25
|
+
this.events.onOff$Changed.on((value) => {
|
|
26
|
+
console.log(`Light is now ${value ? "ON" : "OFF"}`);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const ExampleLight = OnOffLightDevice.with(ReportingOnOffServer);
|
|
31
|
+
const node = await ServerNode.create();
|
|
32
|
+
await node.add(ExampleLight);
|
|
33
|
+
await node.run();
|
|
34
|
+
//# sourceMappingURL=LightDevice.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/examples/LightDevice.ts"],
|
|
4
|
+
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAQA,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB,8BAA8B;AAIzD,MAAM,6BAA6B,uBAAuB,YAAY;AAAA;AAAA,EAElE,MAAe,KAAK;AAChB,YAAQ,IAAI,kBAAkB;AAC9B,UAAM,MAAM,GAAG;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,MAAM;AACX,YAAQ,IAAI,mBAAmB;AAC/B,SAAK,MAAM,QAAQ;AAAA,EACvB;AAAA;AAAA,EAGS,aAAa;AAClB,SAAK,OAAO,cAAc,GAAG,WAAS;AAClC,cAAQ,IAAI,gBAAgB,QAAQ,OAAO,KAAK,EAAE;AAAA,IACtD,CAAC;AAAA,EACL;AACJ;AAKA,MAAM,eAAe,iBAAiB,KAAK,oBAAoB;AAO/D,MAAM,OAAO,MAAM,WAAW,OAAO;AAGrC,MAAM,KAAK,IAAI,YAAY;AAM3B,MAAM,KAAK,IAAI;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2022-2024 Matter.js Authors
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
DeviceTypeId,
|
|
9
|
+
Endpoint,
|
|
10
|
+
EndpointServer,
|
|
11
|
+
Environment,
|
|
12
|
+
ServerNode,
|
|
13
|
+
StorageService,
|
|
14
|
+
Time,
|
|
15
|
+
VendorId
|
|
16
|
+
} from "@matter/main";
|
|
17
|
+
import { OnOffLightDevice } from "@matter/main/devices/on-off-light";
|
|
18
|
+
import { OnOffPlugInUnitDevice } from "@matter/main/devices/on-off-plug-in-unit";
|
|
19
|
+
import { logEndpoint } from "@matter/main/protocol";
|
|
20
|
+
import { execSync } from "child_process";
|
|
21
|
+
const devices = await getConfiguration();
|
|
22
|
+
for (let idx = 1; idx < devices.length; idx++) {
|
|
23
|
+
const {
|
|
24
|
+
isSocket,
|
|
25
|
+
deviceName,
|
|
26
|
+
vendorName,
|
|
27
|
+
passcode,
|
|
28
|
+
discriminator,
|
|
29
|
+
vendorId,
|
|
30
|
+
productName,
|
|
31
|
+
productId,
|
|
32
|
+
port,
|
|
33
|
+
uniqueId
|
|
34
|
+
} = devices[idx];
|
|
35
|
+
const i = idx + 1;
|
|
36
|
+
const server = await ServerNode.create({
|
|
37
|
+
// Required: Give the Node a unique ID which is used to store the state of this node
|
|
38
|
+
id: uniqueId,
|
|
39
|
+
// Provide Network relevant configuration like the port
|
|
40
|
+
// Optional when operating only one device on a host, Default port is 5540
|
|
41
|
+
network: {
|
|
42
|
+
port
|
|
43
|
+
},
|
|
44
|
+
// Provide Commissioning relevant settings
|
|
45
|
+
// Optional for development/testing purposes
|
|
46
|
+
commissioning: {
|
|
47
|
+
passcode,
|
|
48
|
+
discriminator
|
|
49
|
+
},
|
|
50
|
+
// Provide Node announcement settings
|
|
51
|
+
// Optional: If Ommitted some development defaults are used
|
|
52
|
+
productDescription: {
|
|
53
|
+
name: deviceName,
|
|
54
|
+
deviceType: DeviceTypeId(isSocket ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType)
|
|
55
|
+
},
|
|
56
|
+
// Provide defaults for the BasicInformation cluster on the Root endpoint
|
|
57
|
+
// Optional: If Omitted some development defaults are used
|
|
58
|
+
basicInformation: {
|
|
59
|
+
vendorName,
|
|
60
|
+
vendorId: VendorId(vendorId),
|
|
61
|
+
nodeLabel: productName,
|
|
62
|
+
productName,
|
|
63
|
+
productLabel: productName,
|
|
64
|
+
productId,
|
|
65
|
+
serialNumber: `matterjs-${uniqueId}`,
|
|
66
|
+
uniqueId
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
console.log(
|
|
70
|
+
`Added device ${i} on port ${port} and unique id ${uniqueId}: Passcode: ${passcode}, Discriminator: ${discriminator}`
|
|
71
|
+
);
|
|
72
|
+
const endpoint = new Endpoint(isSocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: "onoff" });
|
|
73
|
+
await server.add(endpoint);
|
|
74
|
+
endpoint.events.identify.startIdentifying.on(() => {
|
|
75
|
+
console.log(`Run identify logic for device ${i}, ideally blink a light every 0.5s ...`);
|
|
76
|
+
});
|
|
77
|
+
endpoint.events.identify.stopIdentifying.on(() => {
|
|
78
|
+
console.log(`Stop identify logic for device ${i}...`);
|
|
79
|
+
});
|
|
80
|
+
endpoint.events.onOff.onOff$Changed.on((value) => {
|
|
81
|
+
executeCommand(value ? `on${i}` : `off${i}`);
|
|
82
|
+
console.log(`OnOff ${i} is now ${value ? "ON" : "OFF"}`);
|
|
83
|
+
});
|
|
84
|
+
logEndpoint(EndpointServer.forEndpoint(server));
|
|
85
|
+
console.log("----------------------------");
|
|
86
|
+
console.log(`QR Code for Device ${i} on port ${port}:`);
|
|
87
|
+
console.log("----------------------------");
|
|
88
|
+
await server.start();
|
|
89
|
+
}
|
|
90
|
+
function executeCommand(scriptParamName) {
|
|
91
|
+
const script = Environment.default.vars.string(scriptParamName);
|
|
92
|
+
if (script === void 0) return void 0;
|
|
93
|
+
console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);
|
|
94
|
+
}
|
|
95
|
+
async function getConfiguration() {
|
|
96
|
+
const environment = Environment.default;
|
|
97
|
+
const storageService = environment.get(StorageService);
|
|
98
|
+
console.log(`Storage location: ${storageService.location} (Directory)`);
|
|
99
|
+
console.log(
|
|
100
|
+
'Use the parameter "--storage-path=NAME-OR-PATH" to specify a different storage location in this directory, use --storage-clear to start with an empty storage.'
|
|
101
|
+
);
|
|
102
|
+
const deviceStorage = (await storageService.open("device")).createContext("data");
|
|
103
|
+
let defaultPasscode = 20202021;
|
|
104
|
+
let defaultDiscriminator = 3840;
|
|
105
|
+
let defaultPort = 5550;
|
|
106
|
+
const devices2 = [];
|
|
107
|
+
const numDevices = environment.vars.number("num") ?? 2;
|
|
108
|
+
for (let i = 1; i <= numDevices; i++) {
|
|
109
|
+
const isSocket = await deviceStorage.get(`isSocket${i}`, environment.vars.string(`type${i}`) === "socket");
|
|
110
|
+
if (await deviceStorage.has(`isSocket${i}`)) {
|
|
111
|
+
console.log(`Device type ${isSocket ? "socket" : "light"} found in storage. --type parameter is ignored.`);
|
|
112
|
+
}
|
|
113
|
+
const deviceName = `Matter ${environment.vars.string(`type${i}`) ?? "light"} device ${i}`;
|
|
114
|
+
const vendorName = "matter-node.js";
|
|
115
|
+
const passcode = environment.vars.number(`passcode${i}`) ?? await deviceStorage.get(`passcode${i}`, defaultPasscode++);
|
|
116
|
+
const discriminator = environment.vars.number(`discriminator${i}`) ?? await deviceStorage.get(`discriminator${i}`, defaultDiscriminator++);
|
|
117
|
+
const vendorId = environment.vars.number(`vendorid${i}`) ?? await deviceStorage.get(`vendorid${i}`, 65521);
|
|
118
|
+
const productName = `node-matter OnOff-Device ${i}`;
|
|
119
|
+
const productId = environment.vars.number(`productid${i}`) ?? await deviceStorage.get(`productid${i}`, 32768);
|
|
120
|
+
const port = environment.vars.number(`port${i}`) ?? defaultPort++;
|
|
121
|
+
const uniqueId = environment.vars.string(`uniqueid${i}`) ?? await deviceStorage.get(`uniqueid${i}`, `${i}-${Time.nowMs()}`);
|
|
122
|
+
await deviceStorage.set(`passcode${i}`, passcode);
|
|
123
|
+
await deviceStorage.set(`discriminator${i}`, discriminator);
|
|
124
|
+
await deviceStorage.set(`vendorid${i}`, vendorId);
|
|
125
|
+
await deviceStorage.set(`productid${i}`, productId);
|
|
126
|
+
await deviceStorage.set(`isSocket${i}`, isSocket);
|
|
127
|
+
await deviceStorage.set(`uniqueid${i}`, uniqueId);
|
|
128
|
+
devices2.push({
|
|
129
|
+
isSocket,
|
|
130
|
+
deviceName,
|
|
131
|
+
vendorName,
|
|
132
|
+
passcode,
|
|
133
|
+
discriminator,
|
|
134
|
+
vendorId,
|
|
135
|
+
productName,
|
|
136
|
+
productId,
|
|
137
|
+
port,
|
|
138
|
+
uniqueId
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return devices2;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=MultiDeviceNode.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/examples/MultiDeviceNode.ts"],
|
|
4
|
+
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAaA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,MAAM,UAAU,MAAM,iBAAiB;AACvC,SAAS,MAAM,GAAG,MAAM,QAAQ,QAAQ,OAAO;AAC3C,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI,QAAQ,GAAG;AACf,QAAM,IAAI,MAAM;AAKhB,QAAM,SAAS,MAAM,WAAW,OAAO;AAA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