<jupyter_start><jupyter_text>Interaction Model ExamplesThis notebook walks through the various interactions that can be initiated from the REPL towards a target using the Matter Interaction Model (IM) and Data Model (DM).  ImportsLet's first begin by setting up by importing some key modules that are needed to make it easier for us to interact with the Matter stack.<jupyter_code>from rich import print
from rich.pretty import pprint
from rich import inspect
import logging
import chip
import chip.logging
from chip import ChipDeviceCtrl
import chip.clusters as Clusters
from chip.ChipReplStartup import *
from chip.ChipStack import *
import subprocess, sys<jupyter_output><empty_output><jupyter_text>InitializationNext, let's initialize the REPL environment and the Matter Stack.<jupyter_code>ReplInit()
chipStack = ChipStack()<jupyter_output><empty_output><jupyter_text>Launch ServerLet's launch an instance of the `chip-all-clusters-app`.<jupyter_code>subprocess.Popen(['pkill', '-f', 'chip-all-clusters-app'])
process = subprocess.Popen('./out/debug/chip-all-clusters-app', stdout=subprocess.DEVNULL)<jupyter_output><empty_output><jupyter_text>Commission TargetCommission the target with a NodeId of 1.<jupyter_code>devCtrl = ChipDeviceCtrl.ChipDeviceController(controllerNodeId=1)
devCtrl.CommissionIP(b'127.0.0.1', 20202021, 1)<jupyter_output>2022-01-02 21:25:51 johnsj-macbookpro1.roam.corp.google.com chip.CTL[93727] ERROR Unable to find country code, defaulting to WW<jupyter_text>Invoke Commands  Basic Command (Success Response) Let's send a basic command to turn on/off the light on Endpoint 1.<jupyter_code>await devCtrl.SendCommand(1, 1, Clusters.OnOff.Commands.On())<jupyter_output><empty_output><jupyter_text>The receipt of a successful status response will result in the command just returning successfully. Otherwise, an exception will be thrown.  Basic Command (Failure Response) If we send the same command to an invalid endpoint, an exception is thrown:<jupyter_code>await devCtrl.SendCommand(1, 100, Clusters.OnOff.Commands.On())<jupyter_output><empty_output><jupyter_text>Basic Command (Data Response) Here's an example of a command that sends back a data response, and how that is presented:<jupyter_code>await devCtrl.SendCommand(1, 1, Clusters.TestCluster.Commands.TestListInt8UReverseRequest([1, 3, 5, 7]))<jupyter_output><empty_output><jupyter_text>Read out the Fabric List to validate<jupyter_code>await devCtrl.ReadAttribute(1, [(Clusters.OperationalCredentials)])
await devCtrl.ReadAttribute(1, [(Clusters.Descriptor)], True)<jupyter_output><empty_output><jupyter_text>Note that the `FabricsList` contains just a single item with a `fabriIndex` of 1, and a `fabricId` of 1.  Create Controller on Fabric B<jupyter_code>a = [1, 2, 3, 4]
a<jupyter_output><empty_output><jupyter_text>Open Commissioning WindowThe target right now doesn't accept commissioning requests. So let's go ahead and open the commissioning window to permit the second controller on Fabric B to commission the target. This request has to originate from the 1st controller.<jupyter_code>await devCtrl.SendCommand(1, 0, Clusters.AdministratorCommissioning.Commands.OpenBasicCommissioningWindow(100))<jupyter_output><empty_output><jupyter_text>Commission Target on Fabric B<jupyter_code>devCtrl2.CommissionIP(b'127.0.0.1', 20202021, 1)<jupyter_output>2021-12-30 21:35:59 johnsj-macbookpro1.roam.corp.google.com chip.CTL[58883] ERROR Unable to find country code, defaulting to WW<jupyter_text>Read out the Fabric List to validate<jupyter_code>await devCtrl2.ReadAttribute(1, [(Clusters.OperationalCredentials)])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08741066520065971, 'fraction_numerical': 0.028312259483232547, 'mean_word_length': 7.5825471698113205, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '142515', 'license': 'Apache-2.0', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1121, 'n_words': 332, 'path': 'Matter - REPL Basics.ipynb', 'repo_name': 'wystans/connectedhomeip', 'size': '3638'}