### Setup development environment Source: https://github.com/matter-js/matter.js/blob/main/README.md Clone the repository and install dependencies for local development and building. ```bash git clone https://github.com/matter-js/matter.js cd matter.js npm install ``` -------------------------------- ### Run Matter.js Sensor Example Source: https://github.com/matter-js/matter.js/blob/main/examples/device-sensor/README.md Execute this command in the examples root directory to start the Matter.js sensor example. Refer to the general Examples README for details on CLI parameters and environment variables. ```bash npm run matter-sensor ``` -------------------------------- ### Install @matter/examples Globally Source: https://github.com/matter-js/matter.js/blob/main/examples/README.md Install the @matter/examples package globally using npm. This command is useful for quickly accessing example implementations. ```bash npm i -g @matter/examples ``` -------------------------------- ### Run Robotic Vacuum Cleaner Example Source: https://github.com/matter-js/matter.js/blob/main/examples/device-robotic-vacuum-cleaner/README.md Execute this command in the examples root directory to start the Robotic Vacuum Cleaner example. Refer to the general examples README for CLI parameters and environment variables. ```bash npm run matter-rvc ``` -------------------------------- ### Run OnOff Light Example Source: https://github.com/matter-js/matter.js/blob/main/examples/device-onoff-light/README.md Execute this command in the examples root directory to run the OnOff light example. Refer to the general examples README for details on CLI parameters and environment variables. ```bash npm run matter-light ``` -------------------------------- ### Run the OnOff Sensor Binding Example Source: https://github.com/matter-js/matter.js/blob/main/examples/device-onoff-sensor-binding/README.md Commands to build the project and execute the device example. ```bash npm run build npm run device-onoff-sensor-binding ``` -------------------------------- ### Install Matter.js Dependencies and Build Source: https://github.com/matter-js/matter.js/blob/main/examples/README.md Install all dependencies and build the Matter.js packages from a cloned repository. This is a prerequisite for using the examples directly from the source code. ```bash npm install ``` -------------------------------- ### Run matter.js Device Example for Thread Credentials Source: https://github.com/matter-js/matter.js/blob/main/docs/USAGE_THREAD.md Use this command to start a mock device for commissioning. Adjust passcode or discriminator if re-pairing is needed. BLE support can be finicky. ```bash node node_modules/@matter/examples/dist/esm/examples/DeviceNodeFull.js --storage-path=.thread --ble-enable --ble-thread-fake --passcode=20202021 --discriminator=1234 ``` -------------------------------- ### Run Air Quality Sensor Example Source: https://github.com/matter-js/matter.js/blob/main/examples/device-air-quality-sensor/README.md Execute this command to run the air quality sensor example. Ensure you are in the examples root directory. ```bash npm run matter-air-quality-sensor ``` -------------------------------- ### Run Composed Device Example Source: https://github.com/matter-js/matter.js/blob/main/examples/device-composed-wc-light/README.md Execute this command to run the example that implements a composed device with Window Covering and Light endpoints. Refer to the general CLI usage documentation for more parameters. ```bash npm run matter-excelsior1000 ``` -------------------------------- ### Run Advanced OnOff Device Node Source: https://github.com/matter-js/matter.js/blob/main/examples/device-onoff-advanced/README.md Execute the advanced OnOff device node example using Node.js. This command starts the device with its configured features. ```bash node .dist/examples/device-onoff-advanced-cli/DeviceNodeFull.js ``` -------------------------------- ### CLI Command for Composed Device (Socket Example) Source: https://github.com/matter-js/matter.js/blob/main/examples/device-composed-onoff/README.md Execute this command to start a composed device with two socket types. It specifies the shell commands to run when each socket is turned on or off. ```bash matter-composeddevice --type=socket --num=2 --on1="echo 255 > /sys/class/leds/led1/brightness" --off1="echo 0 > /sys/class/leds/led1/brightness" --type2=socket --on2="echo 255 > /sys/class/leds/led2/brightness" --off2="echo 0 > /sys/class/leds/led2/brightness" ``` -------------------------------- ### NPM Run Command for Multiple OnOff Devices Source: https://github.com/matter-js/matter.js/blob/main/examples/device-multiple-onoff/README.md Use this command when starting from TS files. The '--' separates npm run arguments from the script's arguments. This example starts two socket devices with custom shell commands for on and off states. ```bash npm run matter-multidevice -- --type=socket --num=2 --on1="echo 255 > /sys/class/leds/led1/brightness" --off1="echo 0 > /sys/class/leds/led1/brightness" --type2=socket --on2="echo 255 > /sys/class/leds/led2/brightness" --off2="echo 0 > /sys/class/leds/led2/brightness" ``` -------------------------------- ### Install Python Setuptools for Node-gyp Source: https://github.com/matter-js/matter.js/blob/main/docs/TROUBLESHOOTING.md If you encounter errors related to missing 'setuptools' during matter.js BLE builds, install it using pip. Ensure your Node.js and npm versions are up-to-date. ```bash pip install setuptools ``` -------------------------------- ### Run Matter Measured Socket Example Source: https://github.com/matter-js/matter.js/blob/main/examples/device-measuring-socket/README.md Execute this command in the examples root directory to run the measured socket device. Refer to the Examples README for general CLI parameter and environment variable documentation. ```bash npm run matter-measuredsocket ``` -------------------------------- ### Start OpenThread simulator Source: https://github.com/matter-js/matter.js/blob/main/packages/thread-br-client/README.md Launch the simulator binary from the build directory. ```bash cd ~/src/openthread ./build/simulation/examples/apps/cli/ot-cli-ftd 1 ``` -------------------------------- ### Run Smoke CO Alarm Example Source: https://github.com/matter-js/matter.js/blob/main/examples/device-smoke-co-alarm/README.md Execute this command in the examples root directory to run the Smoke CO Alarm example. ```bash npm run matter-smoke-co-alarm ``` -------------------------------- ### Start the Application Source: https://github.com/matter-js/matter.js/blob/main/examples/electron-matter-controller/README.md Execute this command to launch the Electron application. ```shell npm start ``` -------------------------------- ### Initialize development environment Source: https://github.com/matter-js/matter.js/blob/main/CONTRIBUTING.md Commands to clone the repository, configure the upstream remote, and install dependencies. ```bash # Clone your fork git clone git@github.com:/matter.js.git cd matter.js # Configure upstream alias git remote add upstream git@github.com:matter-js/matter.js.git # Install dependencies and build — always from the repository root npm install ``` -------------------------------- ### Start Device with Amazon Thread Network Parameters Source: https://github.com/matter-js/matter.js/blob/main/docs/USAGE_THREAD.md Use this command to start a device and connect it to an Amazon-branded Thread network. Ensure you have scanned for networks using `ot-ctl discover` and replaced the placeholder values with your network's specific details. ```bash node node_modules/@matter/examples/dist/esm/examples/DeviceNodeFull.js --storage-path=.thread --ble-enable --ble-thread-fake --passcode=20202438 --discriminator=1248 --ble-thread-panid=XXXX --ble-thread-extendedpanid=XXXXXXXXX --ble-thread-networkname=AMZN-Thread-XXXX --ble-thread-channel=XX --ble-thread-address=XXXXXXXXXXX ``` -------------------------------- ### Install OpenThread CLI simulator Source: https://github.com/matter-js/matter.js/blob/main/packages/thread-br-client/README.md Install the OpenThread CLI tool using Homebrew. ```bash brew install openthread ``` -------------------------------- ### Install Matter.js Node Shell Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/README.md Install the shell application using npm. ```bash npm install @matter/nodejs-shell ``` -------------------------------- ### Configure OpenThread CLI Source: https://github.com/matter-js/matter.js/blob/main/packages/thread-br-client/README.md Commands to initialize a new dataset and start the Thread network. ```text > dataset init new Done > dataset commit active Done > ifconfig up Done > thread start Done ``` -------------------------------- ### Install nightly build via NPM Source: https://github.com/matter-js/matter.js/blob/main/README.md Use this command to install the latest development version of the @matter/main package. ```bash npm install @matter/main@dev ``` -------------------------------- ### Execute DTLS handshake test Source: https://github.com/matter-js/matter.js/blob/main/packages/thread-br-client/README.md Build the client and run the handshake example with the extracted PSKc. ```bash cd npm run build -w @matter/thread-br-client cd packages/thread-br-client PSKC=$(npm run --silent example -- examples/extract-pskc.ts 2>/dev/null) npm run example -- examples/handshake-dtls.ts 127.0.0.1 "$PSKC" ``` -------------------------------- ### Instantiate and Run a Server Node Source: https://github.com/matter-js/matter.js/blob/main/packages/node/src/node/README.md Use this to start and publish a Matter node. Additional functionality must be added to make the node useful. The import referencing 'matter-node.js' is necessary for Node.js-specific extensions. ```typescript import { ServerNode } from "@matter/main"; const node = await ServerNode.create(); await node.run(); ``` -------------------------------- ### CLI Command for Multiple OnOff Devices Source: https://github.com/matter-js/matter.js/blob/main/examples/device-multiple-onoff/README.md Execute this command to start two socket devices with custom shell commands for on and off states. Ensure you use different storage locations, network ports, and passcodes if starting multiple parallel processes. ```bash matter-multidevice --type=socket --num=2 --on1="echo 255 > /sys/class/leds/led1/brightness" --off1="echo 0 > /sys/class/leds/led1/brightness" --type2=socket --on2="echo 255 > /sys/class/leds/led2/brightness" --off2="echo 0 > /sys/class/leds/led2/brightness" ``` -------------------------------- ### Run Matter.js Server Source: https://github.com/matter-js/matter.js/blob/main/examples/README.md Execute the Matter.js server using npm. This command is used to start the server when using the Matter.js library directly from a cloned repository. ```bash npm run matter-device ``` -------------------------------- ### Run Matter Device (Bash) Source: https://github.com/matter-js/matter.js/blob/main/examples/device-onoff/README.md Starts a MatterServer (DeviceNode) listening on port 5540 and announces it as a socket device. Use this command to run the device from compiled JavaScript files. ```bash matter-device ``` -------------------------------- ### Read Events and Execute Commands Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/README.md Examples for reading cluster events and invoking commands on specific nodes. ```shell events basicinformation startup 5000 0 ``` ```shell commands onoff toggle 5000 1 ``` ```shell commands onoff offwitheffect '{"effectIdentifier":0,"effectVariant":0}' 5000 1 ``` -------------------------------- ### Initialize Web Shell Constants Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/src/shell/webassets/index.html JavaScript constants and WebSocket connection setup for the Matter.js web shell. ```javascript const DEFAULT_PORT = 3000; // Default port for WebSocket connection const tiles = document.getElementById('tiles'); const consoleDiv = document.getElementById('console'); const matterCommand = document.getElementById('matterCommand'); const pairingCode = document.getElementById('pairingCode'); const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const host = window.location.hostname || 'localhost'; const defaultPort = window.location.port || DEFAULT_PORT; const wsUrl = `${protocol}//${host}:${defaultPort}`; let ws = null; let reconnectAttempts = 0; const ON_OFF = 6; const ILLUMINANCE = 1024; const TEMPERATURE = 1026; const PRESSURE = 1027; const HUMIDITY = 1029; const VOLTAGE = 144; // etc. ``` -------------------------------- ### Run Matter.js Node Shell Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/README.md Start the shell application using npx or via the node_modules directory. ```bash npx matter-shell ``` ```bash cd node_modules/@matter/nodejs-shell npm run shell ``` -------------------------------- ### Add matter.js dependency Source: https://github.com/matter-js/matter.js/blob/main/README.md Install the main package to an existing Node.js project. ```bash npm install @matter/main --save ``` -------------------------------- ### Run multiple shell instances Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/README.md Start separate shell instances by passing a unique node number to each process. ```bash # From matter-node-shell top-level npm run shell 1 # In different terminal npm run shell 2 ``` -------------------------------- ### CLI Command for Matter Bridge with On/Off Scripts Source: https://github.com/matter-js/matter.js/blob/main/examples/device-bridge-onoff/README.md Use this command to start a Matter bridge that exposes two devices: a light and a socket. It configures specific shell commands to control the brightness of system LEDs when the devices are turned on or off. ```bash matter-bridge --num=2 --on1="echo 255 > /sys/class/leds/led1/brightness" --off1="echo 0 > /sys/class/leds/led1/brightness" --type2=socket --on2="echo 255 > /sys/class/leds/led2/brightness" --off2="echo 0 > /sys/class/leds/led2/brightness" ``` -------------------------------- ### Read and Write Node Attributes Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/README.md Examples for reading and writing attributes on specific clusters, endpoints, and nodes using the shell. ```shell attributes basicinformation read all 5000 0 ``` ```shell attributes basicinformation read all 5000 0 --remote ``` ```shell attributes basicinformation read nodelabel 5000 0 ``` ```shell attributes basicinformation read 0x5 5000 0 ``` ```shell attributes by-id 0x28 read 0x5 5000 0 ``` ```shell attributes basicinformation write nodelabel "My Node" 5000 0 ``` ```shell attributes binding write binding '[{"node": "4568118954124746267" , "cluster": 6 , "endpoint": 1 }]' 5000 1 ``` ```shell attributes binding write binding '[{"node": "4568118954124746267" , "cluster": "0x6" , "endpoint": 1 }]' 5000 1 ``` -------------------------------- ### Bootstrap a new matter.js project Source: https://github.com/matter-js/matter.js/blob/main/README.md Use the project creator to initialize a new Node.js project with matter.js templates. ```bash npm init @matter ``` ```bash npm init @matter help ``` -------------------------------- ### Run project gate checks Source: https://github.com/matter-js/matter.js/blob/main/CONTRIBUTING.md Commands to execute build, formatting, linting, and testing from the repository root. ```bash npm run build-clean # incremental caches can mask errors in dependent packages npm run format # rewrites files in place npm run lint npm run test ``` -------------------------------- ### Run Controller with Pairing Code Source: https://github.com/matter-js/matter.js/blob/main/examples/controller/README.md Execute the controller from build files, initiating device commissioning with a provided pairing code. ```bash matter-controller --pairingcode=12345678901 ``` -------------------------------- ### Provision Device with chip-tool Source: https://github.com/matter-js/matter.js/blob/main/docs/ECOSYSTEMS.md Use this command to provision a Matter device onto your network using the chip-tool. Ensure the device ID and passcode are correct. ```bash chip-tool pairing onnetwork 222 20202021 ``` -------------------------------- ### WebSocket Lifecycle Management Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/src/shell/webassets/index.html Handles WebSocket connection setup, message processing, and automatic reconnection logic. ```javascript function setupWebSocket() { ws = new WebSocket(wsUrl); initConsole(false); ws.onopen = () => { sendCommand('config loglevel set info'); // info level required for some msgs to be passed sendCommand('nodes connect'); reconnectAttempts = 0; } ws.onclose = () => { logMessage('WebSocket connection closed. Attempting to reconnect...', 'error'); scheduleReconnect(); }; ws.onerror = () => { logMessage('WebSocket error...', 'error'); }; ws.onmessage = (event) => { if (typeof event.data === 'string') { const message = event.data; let trimmed = message.slice(0, 5000); // don't let message to log get too long if (trimmed.length !== message.length) trimmed += ' ...'; logMessage(`Received: "${trimmed}"`, trimmed.toLowerCase().includes('error') ? 'error' : 'received'); // result of nodes log command let matches = message.match(/Logging structure of Node\s+(\d+)/); if (matches) { // could save this message of extensive node data for later use let currentNode = matches[1]; let currentEndpoint = null; let currentEndpointType = ""; const lines = message.split('\n'); lines.forEach(line => { let matches = line.match(/ MA-[\w*]+ endpoint#: (\d+) type: MA-([\w*]+) \(([^)]+)\)/); if (matches) { // could start collecting upcoming messages that define this endpoint currentEndpoint = matches[1]; currentEndpointType = matches[2]; } // device type list for the this node and endpoint matches = line.match(/deviceTypeList id: 0x0 val: ((\{.*?\})(?:\s*\{.*?\})*)/); if (matches) logMessage(`Device Type List: ${currentNode}/${currentEndpoint} ${matches[1]}`, 'status'); // could also check and handle others, "moveToLevel", "movetohueandsaturation", etc. ``` -------------------------------- ### Customize device clusters with custom implementations Source: https://github.com/matter-js/matter.js/blob/main/docs/MIGRATION_GUIDE_08.md Extend existing server requirements to create custom cluster implementations and apply them to a device using the .with() method. ```javascript class ReportingOnOffServer extends OnOffLightRequirements.OnOffServer { // see LightDevice.ts in examples package //... } // Use the above defined OnOffServer for the OnOff cluster in the Device const ExampleLight = OnOffLightDevice.with(ReportingOnOffServer); const endpoint = await serverNode.add(ExampleLight, { id: "myonofflight" }); ``` -------------------------------- ### Run Controller with Pairing Code (NPM) Source: https://github.com/matter-js/matter.js/blob/main/examples/controller/README.md Execute the controller directly from Typescript files using npm, enabling on-the-fly compilation and device commissioning with a pairing code. ```bash npm run matter-controller -- --pairingcode=12345678901 ``` -------------------------------- ### Defining Mandatory Cluster Attributes Source: https://github.com/matter-js/matter.js/blob/main/docs/MIGRATION_GUIDE_08.md Provides examples for overriding default cluster attributes to resolve conformance errors during endpoint initialization. ```javascript const endpoint = new Endpoint(ContactSensorDevice, { booleanState: { stateValue: false, }, }); ``` ```javascript const endpoint = new Endpoint(OccupancySensorDevice, { occupancySensing: { occupancy: { occupied: true, occupancySensorType: OccupancySensorType.Pir, occupancySensorTypeBitmap: { pir: true, ultrasonic: false, physicalContact: false, }, }, }, }); ``` -------------------------------- ### Download an OTA image Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/README.md Queries the DCL for an update for a specific vendor, product, and version, and saves it locally. ```bash ota download 0xfff1 0x8000 1 ota download 0xfff1 0x8000 1 --mode test ``` -------------------------------- ### TypeScript Configuration for Matter.js Source: https://github.com/matter-js/matter.js/blob/main/packages/matter.js/README.md Configure your tsconfig.json to ensure TypeScript and your IDE correctly recognize Matter.js exports. This setup is crucial for module resolution and import handling. ```json { compilerOptions: { moduleResolution: "node16", // Required to support package.json exports module: "node16", // Required to make sure all imports are js }, } ``` -------------------------------- ### Display command help Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/README.md Shows sub-commands and options for a specific command. ```text > config config loglevel Manage Console and File LogLevels config logfile Manage Logfile path config ble-hci Manage BLE HCI ID (Linux) config wifi-credentials Manage Wi-Fi credentials used in commissioning process config thread-credentials Manage Thread credentials used in commissioning process config dcl-test-certificates Manage DCL test certificate fetching Done ``` -------------------------------- ### Customizing Storage Implementation Source: https://github.com/matter-js/matter.js/blob/main/docs/MIGRATION_GUIDE_08.md Shows how to replace the default storage factory within the Environment service. ```typescript Environment.default.get(StorageService).factory = (namespace: string) => new MyOwnStorage(namespace); ``` -------------------------------- ### Run Matter Controller with Custom Environment Variables Source: https://github.com/matter-js/matter.js/blob/main/examples/controller-shared-fabric/README.md Configure and run Matter controller commands using custom environment variables for fabric ID, node ID, target node ID, and endpoint. This allows for flexible multi-controller setups. ```bash MATTER_CERTDIR=/path/to/certificates \ MATTER_FABRICID=2 \ MATTER_NODEID=200 \ MATTER_TARGETNODEID=1 \ MATTER_ENDPOINT=1 \ npm run matter-controller-shared-fabric toggle ``` -------------------------------- ### Bundle Device Application (Bash) Source: https://github.com/matter-js/matter.js/blob/main/examples/device-onoff/README.md Executes the bundling script to create a single JavaScript file for the application and its dependencies. This is useful for production environments where space and CPU are limited. ```bash npm run bundle-device ``` -------------------------------- ### Generate External Certificates with chip-tool Source: https://github.com/matter-js/matter.js/blob/main/examples/controller-shared-fabric/README.md Use chip-tool to generate the necessary certificate chain for multi-controller setups. This includes the Root CA (RCAC), and intermediate CAs (ICACs) for each controller, along with their corresponding keys. Certificates are converted to Matter TLV formats for use. ```bash cd /path/to/connectedhomeip # Create certificates directory mkdir -p certificates # Generate RCAC (Root CA) ./out/linux-x64-chip-tool/chip-cert gen-att-cert \ --type r \ --subject-cn "Matter Test Root CA" \ --valid-from "2024-01-01 00:00:00" \ --lifetime 3650 \ --out-key certificates/rcac_key.pem \ --out certificates/rcac.pem # Convert RCAC to Matter TLV format ./out/linux-x64-chip-tool/chip-cert convert-cert \ certificates/rcac.pem certificates/rcac.chip --chip # Generate ICAC 1 (for chip-tool controller) ./out/linux-x64-chip-tool/chip-cert gen-att-cert \ --type i \ --subject-cn "Matter Test ICA 1" \ --ca-cert certificates/rcac.pem \ --ca-key certificates/rcac_key.pem \ --valid-from "2024-01-01 00:00:00" \ --lifetime 3650 \ --out-key certificates/icac1_key.pem \ --out certificates/icac1.pem # Convert ICAC 1 to Matter formats ./out/linux-x64-chip-tool/chip-cert convert-cert \ certificates/icac1.pem certificates/icac1.chip --chip ./out/linux-x64-chip-tool/chip-cert convert-key \ certificates/icac1_key.pem certificates/icac1_key.bin --chip # Generate ICAC 2 (for matter.js controller) ./out/linux-x64-chip-tool/chip-cert gen-att-cert \ --type i \ --subject-cn "Matter Test ICA 2" \ --ca-cert certificates/rcac.pem \ --ca-key certificates/rcac_key.pem \ --valid-from "2024-01-01 00:00:00" \ --lifetime 3650 \ --out-key certificates/icac2_key.pem \ --out certificates/icac2.pem # Convert ICAC 2 to Matter formats ./out/linux-x64-chip-tool/chip-cert convert-cert \ certificates/icac2.pem certificates/icac2.chip --chip ./out/linux-x64-chip-tool/chip-cert convert-key \ certificates/icac2_key.pem certificates/icac2_key.bin --chip ``` -------------------------------- ### Display help commands Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/README.md Lists all top-level commands supported by the shell. ```text matter-node> help commission Handle device commissioning config Manage global configuration session Manage session nodes Manage nodes ota OTA update operations cert Certificate management operations subscribe [node-id] Subscribe to all events and attributes of a node 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 discover Handle device discovery attributes Read and Write attributes events Read events commands Invoke commands tlv TLV decoding tools exit Exit ``` -------------------------------- ### Generate Standard Model Source: https://github.com/matter-js/matter.js/blob/main/packages/model/README.md Command to recreate the standard model files. ```sh cd matter.js/support/codegen npm run generate-model ``` -------------------------------- ### Add OnOffLightDevice to a ServerNode Source: https://github.com/matter-js/matter.js/blob/main/packages/node/src/node/README.md Demonstrates how to add a predefined OnOffLightDevice to a Matter.js server node. This publishes a node with a functional 'on/off' cluster. ```typescript import { OnOffLightDevice } from "@matter/main/devices/OnOffLightDevice"; import { ServerNode } from "@matter/main"; const node = await ServerNode.create(); await node.add(OnOffLightDevice); await node.run(); ``` -------------------------------- ### Run project lifecycle commands Source: https://github.com/matter-js/matter.js/blob/main/CLAUDE.md Execute these commands in order from the repository root to ensure code quality and build integrity before finalizing changes. ```bash npm run build # `npm run build-clean` before opening a PR — incremental caches mask errors in dependent packages npm run format # rewrites files in place; `npm run format-verify` only checks npm run lint npm test # `npm test -- -p packages/` while iterating on one package ``` -------------------------------- ### Run linting and formatting commands Source: https://github.com/matter-js/matter.js/blob/main/README.md Available scripts for maintaining code style and quality across all packages. ```bash npm run lint ``` ```bash npm run lint-fix ``` ```bash npm run format ``` ```bash npm run format-verify ``` -------------------------------- ### Build OpenThread FTD simulator Source: https://github.com/matter-js/matter.js/blob/main/packages/thread-br-client/README.md Clone and build the OpenThread repository to generate the simulation binary. ```bash git clone https://github.com/openthread/openthread.git ~/src/openthread cd ~/src/openthread ./script/bootstrap ./script/cmake-build simulation ``` -------------------------------- ### Import Matter Model Source: https://github.com/matter-js/matter.js/blob/main/packages/model/README.md Initialize the Matter model instance. ```ts import { Matter } from "@matter/model"; ``` -------------------------------- ### Add a simple DeviceType to ServerNode Source: https://github.com/matter-js/matter.js/blob/main/docs/MIGRATION_GUIDE_08.md Demonstrates three ways to add a device endpoint to a server node, including direct addition, pre-creation, and configuration-time definition. ```javascript const endpoint = await serverNode.add(OnOffLightDevice, { id: "myonofflight" }); ``` ```javascript const endpoint = new Endpoint(OnOffLightDevice, { id: "myonofflight" }); await serverNode.add(endpoint); ``` ```javascript const serverNode = await ServerNode.create({ id: "myNode", //... serverNode configuration parts: [ { type: OnOffLightDevice, id: "myonofflight", //... more config for this part }, ], }); ``` -------------------------------- ### ota add Source: https://github.com/matter-js/matter.js/blob/main/packages/nodejs-shell/README.md Imports an OTA image into local storage. ```APIDOC ## ota add ### Description Imports an OTA image into storage after validation. Accepts absolute paths, file:// URLs, or http(s) URLs. ``` -------------------------------- ### Run Matter Controller Commands Source: https://github.com/matter-js/matter.js/blob/main/examples/controller-shared-fabric/README.md Execute common Matter controller operations like toggling, turning on/off, or reading the state of a device. These commands assume default environment variables are set. ```bash cd examples # Toggle the device ON/OFF npm run matter-controller-shared-fabric toggle # Turn device ON npm run matter-controller-shared-fabric on # Turn device OFF npm run matter-controller-shared-fabric off # Read current OnOff state npm run matter-controller-shared-fabric read ``` -------------------------------- ### Create a working branch Source: https://github.com/matter-js/matter.js/blob/main/CONTRIBUTING.md Commands to create and switch to a new branch based on the main branch. ```bash git branch --track origin/main git checkout ``` -------------------------------- ### Discover commissionable devices with serverNode.peers.discover Source: https://github.com/matter-js/matter.js/blob/main/docs/MIGRATION_CONTROLLER_018.md Use this pattern to initiate device discovery with specific filters and handle discovered nodes via events. Note that the awaited result is empty if no timeout is provided. ```ts import { ChannelType, Seconds } from "@matter/general"; const discovery = serverNode.peers.discover({ longDiscriminator: 3840, // or { shortDiscriminator } / { vendorId } / { productId } / { deviceType }, or {} for all timeout: Seconds(120), // omit to search until you call discovery.stop() scannerFilter: scanner => // optional: restrict transports (default: all) scanner.type === ChannelType.UDP || scanner.type === ChannelType.BLE, }); // `discovered` fires per (re-)advertisement — the same device can fire repeatedly, so dedupe: const seen = new Set(); discovery.discovered.on(node => { const { deviceIdentifier, addresses } = node.state.commissioning; const id = deviceIdentifier || JSON.stringify(addresses ?? []); if (seen.has(id)) return; seen.add(id); console.log(node.state.commissioning); // discovery.stop(); // end early, e.g. on first match }); const results = await discovery; // ClientNode[] once the timeout elapses (empty if no timeout was set) ``` -------------------------------- ### Clearing Storage on Startup in Matter.js Source: https://github.com/matter-js/matter.js/blob/main/examples/README.md Enable or disable storage reset on startup using command-line arguments or environment variables. Setting `MATTER_STORAGE_CLEAR` to 1 or `environment.vars.set('storage.clear', true)` will clear the storage. ```bash --storage-clear ``` ```bash MATTER_STORAGE_CLEAR=1 ``` ```javascript environment.vars.set('storage.clear', true) ``` -------------------------------- ### Logging Level Transitions Source: https://github.com/matter-js/matter.js/blob/main/docs/LOGGING.md A summary of the logic used to transition between different logging levels based on event characteristics. ```text DEBUG → INFO : pure wire/diagnostic detail vs worth a dev seeing on a healthy run INFO → NOTICE : dev-facing / high-volume vs operator-significant, lower-volume NOTICE→ WARN : nobody-can-fix, handled vs someone should investigate/fix WARN → ERROR : single operation vs whole feature/subsystem ERROR → FATAL : a feature dead vs the whole runtime dead ``` -------------------------------- ### Commissioning a Device with a Known Address Source: https://github.com/matter-js/matter.js/blob/main/docs/MIGRATION_CONTROLLER_018.md Use peers.forDescriptor to initialize a peer node from a known address, then call commission on the resulting node instance. ```ts const node = await serverNode.peers.forDescriptor({ addresses: [{ ip, port, type: "udp" }] }); await node.commission({ passcode: 20202021 /* ...same CommissioningOptions... */ }); ```