@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,118 @@
|
|
|
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 { Endpoint, EndpointServer, Environment, ServerNode, StorageService, Time } from "@matter/main";
|
|
8
|
+
import { OnOffLightDevice } from "@matter/main/devices/on-off-light";
|
|
9
|
+
import { OnOffPlugInUnitDevice } from "@matter/main/devices/on-off-plug-in-unit";
|
|
10
|
+
import { logEndpoint } from "@matter/protocol";
|
|
11
|
+
import { DeviceTypeId, VendorId } from "@matter/types";
|
|
12
|
+
import { execSync } from "child_process";
|
|
13
|
+
const { isSocket, deviceName, vendorName, passcode, discriminator, vendorId, productName, productId, port, uniqueId } = await getConfiguration();
|
|
14
|
+
const server = await ServerNode.create({
|
|
15
|
+
// Required: Give the Node a unique ID which is used to store the state of this node
|
|
16
|
+
id: uniqueId,
|
|
17
|
+
// Provide Network relevant configuration like the port
|
|
18
|
+
// Optional when operating only one device on a host, Default port is 5540
|
|
19
|
+
network: {
|
|
20
|
+
port
|
|
21
|
+
},
|
|
22
|
+
// Provide Commissioning relevant settings
|
|
23
|
+
// Optional for development/testing purposes
|
|
24
|
+
commissioning: {
|
|
25
|
+
passcode,
|
|
26
|
+
discriminator
|
|
27
|
+
},
|
|
28
|
+
// Provide Node announcement settings
|
|
29
|
+
// Optional: If Ommitted some development defaults are used
|
|
30
|
+
productDescription: {
|
|
31
|
+
name: deviceName,
|
|
32
|
+
deviceType: DeviceTypeId(isSocket[0] ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType)
|
|
33
|
+
},
|
|
34
|
+
// Provide defaults for the BasicInformation cluster on the Root endpoint
|
|
35
|
+
// Optional: If Omitted some development defaults are used
|
|
36
|
+
basicInformation: {
|
|
37
|
+
vendorName,
|
|
38
|
+
vendorId: VendorId(vendorId),
|
|
39
|
+
nodeLabel: productName,
|
|
40
|
+
productName,
|
|
41
|
+
productLabel: productName,
|
|
42
|
+
productId,
|
|
43
|
+
serialNumber: `matterjs-${uniqueId}`,
|
|
44
|
+
uniqueId
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
for (let idx = 0; idx < isSocket.length; idx++) {
|
|
48
|
+
const i = idx + 1;
|
|
49
|
+
const isASocket = isSocket[idx];
|
|
50
|
+
const endpoint = new Endpoint(isASocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: `onoff-${i}` });
|
|
51
|
+
await server.add(endpoint);
|
|
52
|
+
endpoint.events.identify.startIdentifying.on(() => {
|
|
53
|
+
console.log(`Run identify logic for sub device ${i}, ideally blink a light every 0.5s ...`);
|
|
54
|
+
});
|
|
55
|
+
endpoint.events.identify.stopIdentifying.on(() => {
|
|
56
|
+
console.log(`Stop identify logic for sub device ${i}...`);
|
|
57
|
+
});
|
|
58
|
+
endpoint.events.onOff.onOff$Changed.on((value) => {
|
|
59
|
+
executeCommand(value ? `on${i}` : `off${i}`);
|
|
60
|
+
console.log(`OnOff ${i} is now ${value ? "ON" : "OFF"}`);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
logEndpoint(EndpointServer.forEndpoint(server));
|
|
64
|
+
await server.run();
|
|
65
|
+
function executeCommand(scriptParamName) {
|
|
66
|
+
const script = Environment.default.vars.string(scriptParamName);
|
|
67
|
+
if (script === void 0) return void 0;
|
|
68
|
+
console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);
|
|
69
|
+
}
|
|
70
|
+
async function getConfiguration() {
|
|
71
|
+
const environment = Environment.default;
|
|
72
|
+
const storageService = environment.get(StorageService);
|
|
73
|
+
console.log(`Storage location: ${storageService.location} (Directory)`);
|
|
74
|
+
console.log(
|
|
75
|
+
'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.'
|
|
76
|
+
);
|
|
77
|
+
const deviceStorage = (await storageService.open("device")).createContext("data");
|
|
78
|
+
const isSocket2 = Array();
|
|
79
|
+
const numDevices = environment.vars.number("num") || 2;
|
|
80
|
+
if (await deviceStorage.has("isSocket")) {
|
|
81
|
+
console.log(`Device types found in storage. --type parameter is ignored.`);
|
|
82
|
+
(await deviceStorage.get("isSocket")).forEach((type) => isSocket2.push(type));
|
|
83
|
+
}
|
|
84
|
+
for (let i = 1; i < numDevices; i++) {
|
|
85
|
+
if (isSocket2[i - 1] !== void 0) continue;
|
|
86
|
+
isSocket2.push(environment.vars.string(`type${i}`) === "socket");
|
|
87
|
+
}
|
|
88
|
+
const deviceName2 = "Matter test device";
|
|
89
|
+
const vendorName2 = "matter-node.js";
|
|
90
|
+
const passcode2 = environment.vars.number("passcode") ?? await deviceStorage.get("passcode", 20202021);
|
|
91
|
+
const discriminator2 = environment.vars.number("discriminator") ?? await deviceStorage.get("discriminator", 3840);
|
|
92
|
+
const vendorId2 = environment.vars.number("vendorid") ?? await deviceStorage.get("vendorid", 65521);
|
|
93
|
+
const productName2 = `node-matter OnOff ${isSocket2 ? "Socket" : "Light"}`;
|
|
94
|
+
const productId2 = environment.vars.number("productid") ?? await deviceStorage.get("productid", 32768);
|
|
95
|
+
const port2 = environment.vars.number("port") ?? 5540;
|
|
96
|
+
const uniqueId2 = environment.vars.string("uniqueid") ?? await deviceStorage.get("uniqueid", Time.nowMs().toString());
|
|
97
|
+
await deviceStorage.set({
|
|
98
|
+
passcode: passcode2,
|
|
99
|
+
discriminator: discriminator2,
|
|
100
|
+
vendorid: vendorId2,
|
|
101
|
+
productid: productId2,
|
|
102
|
+
isSocket: isSocket2,
|
|
103
|
+
uniqueid: uniqueId2
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
isSocket: isSocket2,
|
|
107
|
+
deviceName: deviceName2,
|
|
108
|
+
vendorName: vendorName2,
|
|
109
|
+
passcode: passcode2,
|
|
110
|
+
discriminator: discriminator2,
|
|
111
|
+
vendorId: vendorId2,
|
|
112
|
+
productName: productName2,
|
|
113
|
+
productId: productId2,
|
|
114
|
+
port: port2,
|
|
115
|
+
uniqueId: uniqueId2
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=ComposedDeviceNode.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/examples/ComposedDeviceNode.ts"],
|
|
4
|
+
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAaA,SAAS,UAAU,gBAAgB,aAAa,YAAY,gBAAgB,YAAY;AACxF,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,mBAAmB;AAC5B,SAAS,cAAc,gBAAgB;AACvC,SAAS,gBA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BN,YAAW,WAAW,OAAO;AACtE,QAAMO,aAAY,YAAY,KAAK,OAAO,WAAW,KAAM,MAAM,cAAc,IAAI,aAAa,KAAM;AAEtG,QAAMC,QAAO,YAAY,KAAK,OAAO,MAAM,KAAK;AAEhD,QAAMC,YACF,YAAY,KAAK,OAAO,UAAU,KAAM,MAAM,cAAc,IAAI,YAAY,KAAK,MAAM,EAAE,SAAS,CAAC;AAGvG,QAAM,cAAc,IAAI;AAAA,IACpB,UAAAN;AAAA,IACA,eAAAC;AAAA,IACA,UAAUC;AAAA,IACV,WAAWE;AAAA,IACX,UAAAP;AAAA,IACA,UAAUS;AAAA,EACd,CAAC;AAED,SAAO;AAAA,IACH,UAAAT;AAAA,IACA,YAAAC;AAAA,IACA,YAAAC;AAAA,IACA,UAAAC;AAAA,IACA,eAAAC;AAAA,IACA,UAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,MAAAC;AAAA,IACA,UAAAC;AAAA,EACJ;AACJ;",
|
|
5
|
+
"names": ["isSocket", "deviceName", "vendorName", "passcode", "discriminator", "vendorId", "productName", "productId", "port", "uniqueId"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
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 { Environment, Logger, singleton, StorageService, Time } from "@matter/main";
|
|
8
|
+
import { NodeJsBle } from "@matter/nodejs-ble";
|
|
9
|
+
import { NodeId } from "@matter/types";
|
|
10
|
+
import { CommissioningController } from "@project-chip/matter.js";
|
|
11
|
+
import { Ble } from "@project-chip/matter.js/ble";
|
|
12
|
+
import {
|
|
13
|
+
BasicInformationCluster,
|
|
14
|
+
DescriptorCluster,
|
|
15
|
+
GeneralCommissioning,
|
|
16
|
+
OnOff
|
|
17
|
+
} from "@project-chip/matter.js/cluster";
|
|
18
|
+
import { ManualPairingCodeCodec } from "@project-chip/matter.js/schema";
|
|
19
|
+
import { NodeStateInformation } from "../../../matter.js/dist/esm/device/PairedNode.js";
|
|
20
|
+
const logger = Logger.get("Controller");
|
|
21
|
+
const environment = Environment.default;
|
|
22
|
+
if (environment.vars.get("ble")) {
|
|
23
|
+
Ble.get = singleton(
|
|
24
|
+
() => new NodeJsBle({
|
|
25
|
+
hciId: environment.vars.number("ble-hci-id")
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const storageService = environment.get(StorageService);
|
|
30
|
+
console.log(`Storage location: ${storageService.location} (Directory)`);
|
|
31
|
+
logger.info(
|
|
32
|
+
'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.'
|
|
33
|
+
);
|
|
34
|
+
class ControllerNode {
|
|
35
|
+
async start() {
|
|
36
|
+
logger.info(`node-matter Controller started`);
|
|
37
|
+
const controllerStorage = (await storageService.open("controller")).createContext("data");
|
|
38
|
+
const ip = await controllerStorage.has("ip") ? await controllerStorage.get("ip") : environment.vars.string("ip");
|
|
39
|
+
const port = await controllerStorage.has("port") ? await controllerStorage.get("port") : environment.vars.number("port");
|
|
40
|
+
const uniqueId = await controllerStorage.has("uniqueid") ? await controllerStorage.get("uniqueid") : environment.vars.string("uniqueid") ?? Time.nowMs().toString();
|
|
41
|
+
await controllerStorage.set("uniqueid", uniqueId);
|
|
42
|
+
const pairingCode = environment.vars.string("pairingcode");
|
|
43
|
+
let longDiscriminator, setupPin, shortDiscriminator;
|
|
44
|
+
if (pairingCode !== void 0) {
|
|
45
|
+
const pairingCodeCodec = ManualPairingCodeCodec.decode(pairingCode);
|
|
46
|
+
shortDiscriminator = pairingCodeCodec.shortDiscriminator;
|
|
47
|
+
longDiscriminator = void 0;
|
|
48
|
+
setupPin = pairingCodeCodec.passcode;
|
|
49
|
+
logger.debug(`Data extracted from pairing code: ${Logger.toJSON(pairingCodeCodec)}`);
|
|
50
|
+
} else {
|
|
51
|
+
longDiscriminator = environment.vars.number("longDiscriminator") ?? await controllerStorage.get("longDiscriminator", 3840);
|
|
52
|
+
if (longDiscriminator > 4095) throw new Error("Discriminator value must be less than 4096");
|
|
53
|
+
setupPin = environment.vars.number("pin") ?? await controllerStorage.get("pin", 20202021);
|
|
54
|
+
}
|
|
55
|
+
if (shortDiscriminator === void 0 && longDiscriminator === void 0 || setupPin === void 0) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode"
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const commissioningOptions = {
|
|
61
|
+
regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,
|
|
62
|
+
regulatoryCountryCode: "XX"
|
|
63
|
+
};
|
|
64
|
+
let ble = false;
|
|
65
|
+
if (environment.vars.get("ble")) {
|
|
66
|
+
ble = true;
|
|
67
|
+
const wifiSsid = environment.vars.string("ble-wifi-ssid");
|
|
68
|
+
const wifiCredentials = environment.vars.string("ble-wifi-credentials");
|
|
69
|
+
const threadNetworkName = environment.vars.string("ble-thread-networkname");
|
|
70
|
+
const threadOperationalDataset = environment.vars.string("ble-thread-operationaldataset");
|
|
71
|
+
if (wifiSsid !== void 0 && wifiCredentials !== void 0) {
|
|
72
|
+
logger.info(`Registering Commissioning over BLE with WiFi: ${wifiSsid}`);
|
|
73
|
+
commissioningOptions.wifiNetwork = {
|
|
74
|
+
wifiSsid,
|
|
75
|
+
wifiCredentials
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (threadNetworkName !== void 0 && threadOperationalDataset !== void 0) {
|
|
79
|
+
logger.info(`Registering Commissioning over BLE with Thread: ${threadNetworkName}`);
|
|
80
|
+
commissioningOptions.threadNetwork = {
|
|
81
|
+
networkName: threadNetworkName,
|
|
82
|
+
operationalDataset: threadOperationalDataset
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const commissioningController = new CommissioningController({
|
|
87
|
+
environment: {
|
|
88
|
+
environment,
|
|
89
|
+
id: uniqueId
|
|
90
|
+
},
|
|
91
|
+
autoConnect: false
|
|
92
|
+
});
|
|
93
|
+
await commissioningController.start();
|
|
94
|
+
if (!commissioningController.isCommissioned()) {
|
|
95
|
+
const options = {
|
|
96
|
+
commissioning: commissioningOptions,
|
|
97
|
+
discovery: {
|
|
98
|
+
knownAddress: ip !== void 0 && port !== void 0 ? { ip, port, type: "udp" } : void 0,
|
|
99
|
+
identifierData: longDiscriminator !== void 0 ? { longDiscriminator } : shortDiscriminator !== void 0 ? { shortDiscriminator } : {},
|
|
100
|
+
discoveryCapabilities: {
|
|
101
|
+
ble
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
passcode: setupPin
|
|
105
|
+
};
|
|
106
|
+
logger.info(`Commissioning ... ${Logger.toJSON(options)}`);
|
|
107
|
+
const nodeId = await commissioningController.commissionNode(options);
|
|
108
|
+
console.log(`Commissioning successfully done with nodeId ${nodeId}`);
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const nodes = commissioningController.getCommissionedNodes();
|
|
112
|
+
console.log("Found commissioned nodes:", Logger.toJSON(nodes));
|
|
113
|
+
const nodeId = NodeId(environment.vars.number("nodeid") ?? nodes[0]);
|
|
114
|
+
if (!nodes.includes(nodeId)) {
|
|
115
|
+
throw new Error(`Node ${nodeId} not found in commissioned nodes`);
|
|
116
|
+
}
|
|
117
|
+
const node = await commissioningController.connectNode(nodeId, {
|
|
118
|
+
attributeChangedCallback: (peerNodeId, { path: { nodeId: nodeId2, clusterId, endpointId, attributeName }, value }) => console.log(
|
|
119
|
+
`attributeChangedCallback ${peerNodeId}: Attribute ${nodeId2}/${endpointId}/${clusterId}/${attributeName} changed to ${Logger.toJSON(
|
|
120
|
+
value
|
|
121
|
+
)}`
|
|
122
|
+
),
|
|
123
|
+
eventTriggeredCallback: (peerNodeId, { path: { nodeId: nodeId2, clusterId, endpointId, eventName }, events }) => console.log(
|
|
124
|
+
`eventTriggeredCallback ${peerNodeId}: Event ${nodeId2}/${endpointId}/${clusterId}/${eventName} triggered with ${Logger.toJSON(
|
|
125
|
+
events
|
|
126
|
+
)}`
|
|
127
|
+
),
|
|
128
|
+
stateInformationCallback: (peerNodeId, info2) => {
|
|
129
|
+
switch (info2) {
|
|
130
|
+
case NodeStateInformation.Connected:
|
|
131
|
+
console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} connected`);
|
|
132
|
+
break;
|
|
133
|
+
case NodeStateInformation.Disconnected:
|
|
134
|
+
console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} disconnected`);
|
|
135
|
+
break;
|
|
136
|
+
case NodeStateInformation.Reconnecting:
|
|
137
|
+
console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} reconnecting`);
|
|
138
|
+
break;
|
|
139
|
+
case NodeStateInformation.WaitingForDeviceDiscovery:
|
|
140
|
+
console.log(
|
|
141
|
+
`stateInformationCallback ${peerNodeId}: Node ${nodeId} waiting for device discovery`
|
|
142
|
+
);
|
|
143
|
+
break;
|
|
144
|
+
case NodeStateInformation.StructureChanged:
|
|
145
|
+
console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} structure changed`);
|
|
146
|
+
break;
|
|
147
|
+
case NodeStateInformation.Decommissioned:
|
|
148
|
+
console.log(`stateInformationCallback ${peerNodeId}: Node ${nodeId} decommissioned`);
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
node.logStructure();
|
|
154
|
+
const descriptor = node.getRootClusterClient(DescriptorCluster);
|
|
155
|
+
if (descriptor !== void 0) {
|
|
156
|
+
console.log(await descriptor.attributes.deviceTypeList.get());
|
|
157
|
+
console.log(await descriptor.getServerListAttribute());
|
|
158
|
+
} else {
|
|
159
|
+
console.log("No Descriptor Cluster found. This should never happen!");
|
|
160
|
+
}
|
|
161
|
+
const info = node.getRootClusterClient(BasicInformationCluster);
|
|
162
|
+
if (info !== void 0) {
|
|
163
|
+
console.log(await info.getProductNameAttribute());
|
|
164
|
+
} else {
|
|
165
|
+
console.log("No BasicInformation Cluster found. This should never happen!");
|
|
166
|
+
}
|
|
167
|
+
const devices = node.getDevices();
|
|
168
|
+
if (devices[0] && devices[0].number === 1) {
|
|
169
|
+
const onOff = devices[0].getClusterClient(OnOff.Complete);
|
|
170
|
+
if (onOff !== void 0) {
|
|
171
|
+
let onOffStatus = await onOff.getOnOffAttribute();
|
|
172
|
+
console.log("initial onOffStatus", onOffStatus);
|
|
173
|
+
onOff.addOnOffAttributeListener((value) => {
|
|
174
|
+
console.log("subscription onOffStatus", value);
|
|
175
|
+
onOffStatus = value;
|
|
176
|
+
});
|
|
177
|
+
setInterval(() => {
|
|
178
|
+
onOff.toggle().then(() => {
|
|
179
|
+
onOffStatus = !onOffStatus;
|
|
180
|
+
console.log("onOffStatus", onOffStatus);
|
|
181
|
+
}).catch((error) => logger.error(error));
|
|
182
|
+
}, 6e4);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} finally {
|
|
186
|
+
setTimeout(() => process.exit(0), 1e6);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
new ControllerNode().start().catch((error) => logger.error(error));
|
|
191
|
+
//# sourceMappingURL=ControllerNode.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/examples/ControllerNode.ts"],
|
|
4
|
+
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAYA,SAAS,aAAa,QAAQ,WAAW,gBAAgB,YAAY;AACrE,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,+BAAyD;AAClE,SAAS,WAAW;AACpB;AAAA,EACI;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,SAAS,8BAA8B;AACvC,SAAS,4BAA4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A0B,WAAS;AACrC,oBAAQ,IAAI,4BAA4B,KAAK;AAC7C,0BAAc;AAAA,UAClB,CAAC;AAED,sBAAY,MAAM;AACd,kBACK,OAAO,EACP,KAAK,MAAM;AACR,4BAAc,CAAC;AACf,sBAAQ,IAAI,eAAe,WAAW;AAAA,YAC1C,CAAC,EACA,MAAM,WAAS,OAAO,MAAM,KAAK,CAAC;AAAA,UAC3C,GAAG,GAAK;AAAA,QACZ;AAAA,MACJ;AAAA,IACJ,UAAE;AAEE,iBAAW,MAAM,QAAQ,KAAK,CAAC,GAAG,GAAO;AAAA,IAC7C;AAAA,EACJ;AACJ;AAEA,IAAI,eAAe,EAAE,MAAM,EAAE,MAAM,WAAS,OAAO,MAAM,KAAK,CAAC;",
|
|
5
|
+
"names": ["nodeId", "info"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
async function main() {
|
|
22
|
+
const {
|
|
23
|
+
isSocket,
|
|
24
|
+
deviceName,
|
|
25
|
+
vendorName,
|
|
26
|
+
passcode,
|
|
27
|
+
discriminator,
|
|
28
|
+
vendorId,
|
|
29
|
+
productName,
|
|
30
|
+
productId,
|
|
31
|
+
port,
|
|
32
|
+
uniqueId
|
|
33
|
+
} = await getConfiguration();
|
|
34
|
+
const server = await ServerNode.create({
|
|
35
|
+
// Required: Give the Node a unique ID which is used to store the state of this node
|
|
36
|
+
id: uniqueId,
|
|
37
|
+
// Provide Network relevant configuration like the port
|
|
38
|
+
// Optional when operating only one device on a host, Default port is 5540
|
|
39
|
+
network: {
|
|
40
|
+
port
|
|
41
|
+
},
|
|
42
|
+
// Provide Commissioning relevant settings
|
|
43
|
+
// Optional for development/testing purposes
|
|
44
|
+
commissioning: {
|
|
45
|
+
passcode,
|
|
46
|
+
discriminator
|
|
47
|
+
},
|
|
48
|
+
// Provide Node announcement settings
|
|
49
|
+
// Optional: If Ommitted some development defaults are used
|
|
50
|
+
productDescription: {
|
|
51
|
+
name: deviceName,
|
|
52
|
+
deviceType: DeviceTypeId(isSocket ? OnOffPlugInUnitDevice.deviceType : OnOffLightDevice.deviceType)
|
|
53
|
+
},
|
|
54
|
+
// Provide defaults for the BasicInformation cluster on the Root endpoint
|
|
55
|
+
// Optional: If Omitted some development defaults are used
|
|
56
|
+
basicInformation: {
|
|
57
|
+
vendorName,
|
|
58
|
+
vendorId: VendorId(vendorId),
|
|
59
|
+
nodeLabel: productName,
|
|
60
|
+
productName,
|
|
61
|
+
productLabel: productName,
|
|
62
|
+
productId,
|
|
63
|
+
serialNumber: `matterjs-${uniqueId}`,
|
|
64
|
+
uniqueId
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const endpoint = new Endpoint(isSocket ? OnOffPlugInUnitDevice : OnOffLightDevice, { id: "onoff" });
|
|
68
|
+
await server.add(endpoint);
|
|
69
|
+
endpoint.events.identify.startIdentifying.on(() => {
|
|
70
|
+
console.log(`Run identify logic, ideally blink a light every 0.5s ...`);
|
|
71
|
+
});
|
|
72
|
+
endpoint.events.identify.stopIdentifying.on(() => {
|
|
73
|
+
console.log(`Stop identify logic ...`);
|
|
74
|
+
});
|
|
75
|
+
endpoint.events.onOff.onOff$Changed.on((value) => {
|
|
76
|
+
executeCommand(value ? "on" : "off");
|
|
77
|
+
console.log(`OnOff is now ${value ? "ON" : "OFF"}`);
|
|
78
|
+
});
|
|
79
|
+
logEndpoint(EndpointServer.forEndpoint(server));
|
|
80
|
+
await server.run();
|
|
81
|
+
}
|
|
82
|
+
main().catch((error) => console.error(error));
|
|
83
|
+
function executeCommand(scriptParamName) {
|
|
84
|
+
const script = Environment.default.vars.string(scriptParamName);
|
|
85
|
+
if (script === void 0) return void 0;
|
|
86
|
+
console.log(`${scriptParamName}: ${execSync(script).toString().slice(0, -1)}`);
|
|
87
|
+
}
|
|
88
|
+
async function getConfiguration() {
|
|
89
|
+
const environment = Environment.default;
|
|
90
|
+
const storageService = environment.get(StorageService);
|
|
91
|
+
console.log(`Storage location: ${storageService.location} (Directory)`);
|
|
92
|
+
console.log(
|
|
93
|
+
'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.'
|
|
94
|
+
);
|
|
95
|
+
const deviceStorage = (await storageService.open("device")).createContext("data");
|
|
96
|
+
const isSocket = await deviceStorage.get("isSocket", environment.vars.get("type") === "socket");
|
|
97
|
+
if (await deviceStorage.has("isSocket")) {
|
|
98
|
+
console.log(`Device type ${isSocket ? "socket" : "light"} found in storage. --type parameter is ignored.`);
|
|
99
|
+
}
|
|
100
|
+
const deviceName = "Matter test device";
|
|
101
|
+
const vendorName = "matter-node.js";
|
|
102
|
+
const passcode = environment.vars.number("passcode") ?? await deviceStorage.get("passcode", 20202021);
|
|
103
|
+
const discriminator = environment.vars.number("discriminator") ?? await deviceStorage.get("discriminator", 3840);
|
|
104
|
+
const vendorId = environment.vars.number("vendorid") ?? await deviceStorage.get("vendorid", 65521);
|
|
105
|
+
const productName = `node-matter OnOff ${isSocket ? "Socket" : "Light"}`;
|
|
106
|
+
const productId = environment.vars.number("productid") ?? await deviceStorage.get("productid", 32768);
|
|
107
|
+
const port = environment.vars.number("port") ?? 5540;
|
|
108
|
+
const uniqueId = environment.vars.string("uniqueid") ?? (await deviceStorage.get("uniqueid", Time.nowMs())).toString();
|
|
109
|
+
await deviceStorage.set({
|
|
110
|
+
passcode,
|
|
111
|
+
discriminator,
|
|
112
|
+
vendorid: vendorId,
|
|
113
|
+
productid: productId,
|
|
114
|
+
isSocket,
|
|
115
|
+
uniqueid: uniqueId
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
isSocket,
|
|
119
|
+
deviceName,
|
|
120
|
+
vendorName,
|
|
121
|
+
passcode,
|
|
122
|
+
discriminator,
|
|
123
|
+
vendorId,
|
|
124
|
+
productName,
|
|
125
|
+
productId,
|
|
126
|
+
port,
|
|
127
|
+
uniqueId
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=DeviceNode.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/examples/DeviceNode.ts"],
|
|
4
|
+
"mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAYA;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,eAAe,OAAO;AAElB,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,IAAI,MAAM,iBAAiB;AAK3B,QAAM,SAAS,MAAM,WAAW,OAAO;AAAA;AAAA,IAEnC,IAAI;AAAA;AAAA;AAAA,IAIJ,SAAS;AAAA,MACL;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,eAAe;AAAA,MACX;AAAA,MACA;AAAA,IACJ;AAAA;AAAA;AAAA,IAIA,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