Back to Connectedhomeip

REPL Basics

docs/development_controllers/matter-repl/Matter_REPL_Intro.ipynb

1.5.1.02.0 KB
Original Source

REPL Basics

<a href="http://35.236.121.59/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fproject-chip%2Fconnectedhomeip&urlpath=lab%2Ftree%2Fconnectedhomeip%2Fdocs%2Fguides%2Frepl%2FMatter%2520-%2520REPL%2520Intro.ipynb&branch=master"> </a> </br>

This goes over the basics of interacting with the REPL.

Initialization

Let'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.

ReplStartup.py is run within the global namespace. This results in all of its imports being made available here.

NOTE: This is not needed if you launch the REPL from the command-line.

python
%reset -f
import importlib.util
spec = importlib.util.find_spec('matter.ReplStartup')
%run {spec.origin}

Persistent Storage

NOTE: By default, the REPL points to /tmp/repl-storage.json for its persistent storage. To change that location, you can pass that in directly as follows:

python
%reset -f
import importlib.util
spec = importlib.util.find_spec('matter.ReplStartup')
%run {spec.origin} --storage-path /tmp/repl.json

Help

To get help for the various classes and their respective methods, run:

python
matterhelp()

To get help on a specific method in that class, you can pass that in as an argument:

python
matterhelp(devCtrl.SendCommand)

Log Levels

By default on boot, the log level is set to logging.ERROR. If you would like to see more debug messages, you can set the logging level by doing so:

python
mattersetlog(logging.DEBUG)

To set it back:

python
mattersetlog(logging.WARNING)

Pretty Printing

The Matter REPL leverages the rich Python package heavily to do pretty printing of various data structures with appropriate colored formatting.

This pretty printer is installed by default into the REPL environment:

python
a = {'value': [1, 2, 3, 4, [1, 2]]}
a