Skip to content

Commit

Permalink
Add readme and additional functions for controller
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Oct 1, 2024
1 parent b994417 commit f01c8f5
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
73 changes: 73 additions & 0 deletions examples/valve/controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Running the drinks machine app and controller

To run this example matter application, you need a version of the example app
and a controller. The example app can be compiled with gn / ninja, the
controller functions can be used through the chip-repl python shell

## App

### Compiling the app on linux

From the root of the chip tree

```
cd examples/valve/linux
gn gen out/debug
ninja -C out/debug
```

### Running the app on linux

From the root of the chip tree

```
./examples/valve/linux/out/debug/valve-app --KVS /tmp/valve_kvs.json
```

The KVS file is where the commissioning data is stored for the app, so be sure
to start the app with the same kvs file if you do not want to re-commission it
every time. All the standard linux app flags also work for this app. Use --help
to see the available options.

## Controller

### Compiling the chip-repl

To compile the chip-repl, from the root of the chip tree:

```
. scripts/activate.sh
./scripts/build_python.sh -i out/pyenv
source out/pyenv/activate
out/pyenv/chip-repl --
```

The chip-repl is a shell that lets you directly call python functions. It
instantiates a controller object that can be used to communicate with devices.
The controller is called devCtrl. By default, its KVS is at
/tmp/repl-storage.json, but this can be changed on the command line if desired.
Use --help to see options.

### Commissioning the valve app

As long as the controller and the application KVSs are kept constant, the app
should only need to be commissioned once.

To commission the device use:

```
from chip import ChipDeviceCtrl
await devCtrl.CommissionOnNetwork(nodeId=1, setupPinCode=20202021, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=3840)
```

### Interacting with teh valve app

To create a drinks machine controller:

```
import examples.valve.controller as DrinksController
dm = DrinksController.DrinkMachine(devCtrl, 1)
```

You can now call functions on the drinks machine controller. Tab completion will
work within the repl, so you can see the available options.
9 changes: 9 additions & 0 deletions examples/valve/controller/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import StrEnum
from chip import ChipDeviceCtrl
from chip.clusters.Types import NullValue
import chip.clusters as Clusters


Expand Down Expand Up @@ -73,3 +74,11 @@ async def dispense(self, recipe: str):
time = amount.time()
await self.dev_ctrl.SendCommand(nodeid=self.node_id, endpoint=ep,
payload=Clusters.ValveConfigurationAndControl.Commands.Open(openDuration=time))

async def prime(self, endpoint: int):
await self.dev_ctrl.SendCommand(nodeid=self.node_id, endpoint=endpoint,
payload=Clusters.ValveConfigurationAndControl.Commands.Open(openDuration=NullValue))

async def stop(self, endpoint: int):
await self.dev_ctrl.SendCommand(nodeid=self.node_id, endpoint=endpoint,
payload=Clusters.ValveConfigurationAndControl.Commands.Close())

0 comments on commit f01c8f5

Please sign in to comment.