|
| 1 | +# Matter Linux Contact Sensor Example |
| 2 | + |
| 3 | +An example showing the use of CHIP on the Linux. This document will describe how |
| 4 | +to build and run Matter Linux Contact Sensor Example on Raspberry Pi. This |
| 5 | +document is tested on **Ubuntu for Raspberry Pi Server 20.04 LTS (aarch64)** and |
| 6 | +**Ubuntu for Raspberry Pi Desktop 20.10 (aarch64)** |
| 7 | + |
| 8 | +To cross-compile this example on an x64 host and run it on **NXP i.MX 8M Mini** |
| 9 | +**EVK**, see the associated |
| 10 | +[README document](../../../docs/guides/nxp/nxp_imx8m_linux_examples.md) for |
| 11 | +details. |
| 12 | + |
| 13 | +<hr> |
| 14 | + |
| 15 | +- [Matter Linux Contact Sensor Example](#matter-linux-contact-sensor-example) |
| 16 | + - [Building](#building) |
| 17 | + - [Commandline Arguments](#commandline-arguments) |
| 18 | + - [Running the Complete Example on Raspberry Pi 4](#running-the-complete-example-on-raspberry-pi-4) |
| 19 | + - [Running RPC console](#running-rpc-console) |
| 20 | + - [Device Tracing](#device-tracing) |
| 21 | + |
| 22 | +<hr> |
| 23 | + |
| 24 | +## Building |
| 25 | + |
| 26 | +- Install tool chain |
| 27 | + |
| 28 | + $ sudo apt-get install git gcc g++ python pkg-config libssl-dev libdbus-1-dev libglib2.0-dev ninja-build python3-venv python3-dev unzip |
| 29 | + |
| 30 | +- Build the example application: |
| 31 | + |
| 32 | + $ cd ~/connectedhomeip/examples/contact-sensor-app/linux |
| 33 | + $ git submodule update --init |
| 34 | + $ source third_party/connectedhomeip/scripts/activate.sh |
| 35 | + $ gn gen out/debug |
| 36 | + $ ninja -C out/debug |
| 37 | + |
| 38 | +- To delete generated executable, libraries and object files use: |
| 39 | + |
| 40 | + $ cd ~/connectedhomeip/examples/contact-sensor-app/linux |
| 41 | + $ rm -rf out/ |
| 42 | + |
| 43 | +- Build the example with pigweed RPC |
| 44 | + |
| 45 | + $ cd ~/connectedhomeip/examples/contact-sensor-app/linux |
| 46 | + $ git submodule update --init |
| 47 | + $ source third_party/connectedhomeip/scripts/activate.sh |
| 48 | + $ gn gen out/debug --args='import("//with_pw_rpc.gni")' |
| 49 | + $ ninja -C out/debug |
| 50 | + |
| 51 | +## Commandline arguments |
| 52 | + |
| 53 | +- `--wifi` |
| 54 | + |
| 55 | + Enables WiFi management feature. Required for WiFi commissioning. |
| 56 | + |
| 57 | +- `--thread` |
| 58 | + |
| 59 | + Enables Thread management feature, requires ot-br-posix dbus daemon running. |
| 60 | + Required for Thread commissioning. |
| 61 | + |
| 62 | +- `--ble-device <interface id>` |
| 63 | + |
| 64 | + Use specific bluetooth interface for BLE advertisement and connections. |
| 65 | + |
| 66 | + `interface id`: the number after `hci` when listing BLE interfaces by |
| 67 | + `hciconfig` command, for example, `--ble-device 1` means using `hci1` |
| 68 | + interface. Default: `0`. |
| 69 | + |
| 70 | +## Running the Complete Example on Raspberry Pi 4 |
| 71 | + |
| 72 | +> If you want to test Echo protocol, please enable Echo handler |
| 73 | +> |
| 74 | +> gn gen out/debug --args='chip_app_use_echo=true' |
| 75 | +> ninja -C out/debug |
| 76 | +
|
| 77 | +- Prerequisites |
| 78 | + |
| 79 | + 1. A Raspberry Pi 4 board |
| 80 | + 2. A USB Bluetooth Dongle, Ubuntu desktop will send Bluetooth advertisement, |
| 81 | + which will block CHIP from connecting via BLE. On Ubuntu server, you need |
| 82 | + to install `pi-bluetooth` via APT. |
| 83 | + 3. Ubuntu 20.04 or newer image for ARM64 platform. |
| 84 | + |
| 85 | +- Building |
| 86 | + |
| 87 | + Follow [Building](#building) section of this document. |
| 88 | + |
| 89 | +- Running |
| 90 | + |
| 91 | + - [Optional] Plug USB Bluetooth dongle |
| 92 | + |
| 93 | + - Plug USB Bluetooth dongle and find its bluetooth device number. The |
| 94 | + number after `hci` is the bluetooth device number, `1` in this |
| 95 | + example. |
| 96 | + |
| 97 | + $ hciconfig |
| 98 | + hci1: Type: Primary Bus: USB |
| 99 | + BD Address: 00:1A:7D:AA:BB:CC ACL MTU: 310:10 SCO MTU: 64:8 |
| 100 | + UP RUNNING PSCAN ISCAN |
| 101 | + RX bytes:20942 acl:1023 sco:0 events:1140 errors:0 |
| 102 | + TX bytes:16559 acl:1011 sco:0 commands:121 errors:0 |
| 103 | + |
| 104 | + hci0: Type: Primary Bus: UART |
| 105 | + BD Address: B8:27:EB:AA:BB:CC ACL MTU: 1021:8 SCO MTU: 64:1 |
| 106 | + UP RUNNING PSCAN ISCAN |
| 107 | + RX bytes:8609495 acl:14 sco:0 events:217484 errors:0 |
| 108 | + TX bytes:92185 acl:20 sco:0 commands:5259 errors:0 |
| 109 | + |
| 110 | + - Run Linux Contact Sensor App |
| 111 | + |
| 112 | + $ cd ~/connectedhomeip/examples/contact-sensor-app/linux |
| 113 | + $ sudo out/debug/chip-contact-sensor-app --ble-device [bluetooth device number] |
| 114 | + # In this example, the device we want to use is hci1 |
| 115 | + $ sudo out/debug/chip-contact-sensor-app --ble-device 1 |
| 116 | + |
| 117 | + - Test the device using ChipDeviceController on your laptop / |
| 118 | + workstation etc. |
| 119 | + |
| 120 | +## Running RPC Console |
| 121 | + |
| 122 | +- As part of building the example with RPCs enabled the chip_rpc python |
| 123 | + interactive console is installed into your venv. The python wheel files are |
| 124 | + also created in the output folder: out/debug/chip_rpc_console_wheels. To |
| 125 | + install the wheel files without rebuilding: |
| 126 | + `pip3 install out/debug/chip_rpc_console_wheels/*.whl` |
| 127 | + |
| 128 | +- To use the chip-rpc console after it has been installed run: |
| 129 | + `chip-console -s localhost:33000 -o /<YourFolder>/pw_log.out` |
| 130 | + |
| 131 | +- Then you can Get the contact sensor status using the RPCs: |
| 132 | + `rpcs.chip.rpc.BooleanState.Get()` |
| 133 | + |
| 134 | +## Device Tracing |
| 135 | + |
| 136 | +Device tracing is available to analyze the device performance. To turn on |
| 137 | +tracing, build with RPC enabled. See [Building with RPC enabled](#building). |
| 138 | + |
| 139 | +To obtain the tracing json file, run: |
| 140 | + |
| 141 | +``` |
| 142 | + $ ./{PIGWEED_REPO}/pw_trace_tokenized/py/pw_trace_tokenized/get_trace.py -s localhost:33000 \ |
| 143 | + -o {OUTPUT_FILE} -t {ELF_FILE} {PIGWEED_REPO}/pw_trace_tokenized/pw_trace_protos/trace_rpc.proto |
| 144 | +``` |
0 commit comments