Skip to content

Commit f01c8f5

Browse files
committed
Add readme and additional functions for controller
1 parent b994417 commit f01c8f5

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

examples/valve/controller/README.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Running the drinks machine app and controller
2+
3+
To run this example matter application, you need a version of the example app
4+
and a controller. The example app can be compiled with gn / ninja, the
5+
controller functions can be used through the chip-repl python shell
6+
7+
## App
8+
9+
### Compiling the app on linux
10+
11+
From the root of the chip tree
12+
13+
```
14+
cd examples/valve/linux
15+
gn gen out/debug
16+
ninja -C out/debug
17+
```
18+
19+
### Running the app on linux
20+
21+
From the root of the chip tree
22+
23+
```
24+
./examples/valve/linux/out/debug/valve-app --KVS /tmp/valve_kvs.json
25+
```
26+
27+
The KVS file is where the commissioning data is stored for the app, so be sure
28+
to start the app with the same kvs file if you do not want to re-commission it
29+
every time. All the standard linux app flags also work for this app. Use --help
30+
to see the available options.
31+
32+
## Controller
33+
34+
### Compiling the chip-repl
35+
36+
To compile the chip-repl, from the root of the chip tree:
37+
38+
```
39+
. scripts/activate.sh
40+
./scripts/build_python.sh -i out/pyenv
41+
source out/pyenv/activate
42+
out/pyenv/chip-repl --
43+
```
44+
45+
The chip-repl is a shell that lets you directly call python functions. It
46+
instantiates a controller object that can be used to communicate with devices.
47+
The controller is called devCtrl. By default, its KVS is at
48+
/tmp/repl-storage.json, but this can be changed on the command line if desired.
49+
Use --help to see options.
50+
51+
### Commissioning the valve app
52+
53+
As long as the controller and the application KVSs are kept constant, the app
54+
should only need to be commissioned once.
55+
56+
To commission the device use:
57+
58+
```
59+
from chip import ChipDeviceCtrl
60+
await devCtrl.CommissionOnNetwork(nodeId=1, setupPinCode=20202021, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=3840)
61+
```
62+
63+
### Interacting with teh valve app
64+
65+
To create a drinks machine controller:
66+
67+
```
68+
import examples.valve.controller as DrinksController
69+
dm = DrinksController.DrinkMachine(devCtrl, 1)
70+
```
71+
72+
You can now call functions on the drinks machine controller. Tab completion will
73+
work within the repl, so you can see the available options.

examples/valve/controller/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import StrEnum
22
from chip import ChipDeviceCtrl
3+
from chip.clusters.Types import NullValue
34
import chip.clusters as Clusters
45

56

@@ -73,3 +74,11 @@ async def dispense(self, recipe: str):
7374
time = amount.time()
7475
await self.dev_ctrl.SendCommand(nodeid=self.node_id, endpoint=ep,
7576
payload=Clusters.ValveConfigurationAndControl.Commands.Open(openDuration=time))
77+
78+
async def prime(self, endpoint: int):
79+
await self.dev_ctrl.SendCommand(nodeid=self.node_id, endpoint=endpoint,
80+
payload=Clusters.ValveConfigurationAndControl.Commands.Open(openDuration=NullValue))
81+
82+
async def stop(self, endpoint: int):
83+
await self.dev_ctrl.SendCommand(nodeid=self.node_id, endpoint=endpoint,
84+
payload=Clusters.ValveConfigurationAndControl.Commands.Close())

0 commit comments

Comments
 (0)