Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / lighting-app / nrfconnect / README.md
1 # CHIP nRF Connect Lighting Example Application
2
3 The nRF Connect Lighting Example demonstrates how to remotely control a white
4 dimmable light bulb. It uses buttons to test changing the lighting and device
5 states and LEDs to show the state of these changes. You can use this example as
6 a reference for creating your own application.
7
8 <p align="center">
9   <img src="../../platform/nrfconnect/doc/images/Logo_RGB_H-small.png" alt="Nordic Semiconductor logo"/>
10   <img src="../../platform/nrfconnect/doc/images/nRF52840-DK-small.png" alt="nRF52840 DK">
11 </p>
12
13 The example is based on [CHIP](https://github.com/project-chip/connectedhomeip)
14 and Nordic Semiconductor's nRF Connect SDK, and supports remote access and
15 control of a lighting over a low-power, 802.15.4 Thread network.
16
17 The example behaves as a CHIP accessory, that is a device that can be paired
18 into an existing CHIP network and can be controlled by this network.
19
20 <hr>
21
22 -   [Overview](#overview)
23     -   [Bluetooth LE advertising](#bluetooth-le-advertising)
24     -   [Bluetooth LE rendezvous](#bluetooth-le-rendezvous)
25 -   [Requirements](#requirements)
26     -   [Supported devices](#supported_devices)
27 -   [Device UI](#device-ui)
28 -   [Setting up the environment](#setting-up-the-environment)
29     -   [Using Docker container for setup](#using-docker-container-for-setup)
30     -   [Using native shell for setup](#using-native-shell-for-setup)
31 -   [Building](#building)
32     -   [Removing build artifacts](#removing-build-artifacts)
33     -   [Building with release configuration](#building-with-release-configuration)
34     -   [Building with Pigweed RPCs](#building-with-pigweed-rpcs)
35 -   [Configuring the example](#configuring-the-example)
36 -   [Flashing and debugging](#flashing-and-debugging)
37 -   [Testing the example](#testing-the-example)
38     -   [Testing using CHIPTool](#testing-using-chiptool)
39
40 <hr>
41
42 <a name="overview"></a>
43
44 ## Overview
45
46 This example is running on the nRF Connect platform, which is based on Nordic
47 Semiconductor's
48 [nRF Connect SDK](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/index.html)
49 and [Zephyr RTOS](https://zephyrproject.org/). Visit CHIP's
50 [nRF Connect platform overview](../../../docs/guides/nrfconnect_platform_overview.md)
51 to read more about the platform structure and dependencies.
52
53 The CHIP device that runs the lighting application is controlled by the CHIP
54 controller device over the Thread protocol. By default, the CHIP device has
55 Thread disabled, and it should be paired with CHIP controller and get
56 configuration from it. Some actions required before establishing full
57 communication are described below.
58
59 The example also comes with a test mode, which allows to start Thread with the
60 default settings by pressing button manually. However, this mode does not
61 guarantee that the device will be able to communicate with the CHIP controller
62 and other devices.
63
64 ### Bluetooth LE advertising
65
66 To commission the device onto a CHIP network, the device must be discoverable
67 over Bluetooth LE. For security reasons, you must start Bluetooth LE advertising
68 manually after powering up the device by pressing **Button 4**.
69
70 ### Bluetooth LE rendezvous
71
72 In CHIP, the commissioning procedure (called rendezvous) is done over Bluetooth
73 LE between a CHIP device and the CHIP controller, where the controller has the
74 commissioner role.
75
76 To start the rendezvous, the controller must get the commissioning information
77 from the CHIP device. The data payload is encoded within a QR code, printed to
78 the UART console, and shared using an NFC tag. For security reasons, you must
79 start NFC tag emulation manually after powering up the device by pressing
80 **Button 4**.
81
82 #### Thread provisioning
83
84 Last part of the rendezvous procedure, the provisioning operation involves
85 sending the Thread network credentials from the CHIP controller to the CHIP
86 device. As a result, device is able to join the Thread network and communicate
87 with other Thread devices in the network.
88
89 <hr>
90
91 <a name="requirements"></a>
92
93 ## Requirements
94
95 The application requires a specific revision of the nRF Connect SDK to work
96 correctly. See [Setting up the environment](#setting-up-the-environment) for
97 more information.
98
99 <a name="supported_devices"></a>
100
101 ### Supported devices
102
103 The example supports building and running on the following devices:
104
105 | Hardware platform                                                                         | Build target               | Platform image                                                                                                                                      |
106 | ----------------------------------------------------------------------------------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
107 | [nRF52840 DK](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK) | `nrf52840dk_nrf52840`      | <details><summary>nRF52840 DK</summary><img src="../../platform/nrfconnect/doc/images/nRF52840-DK_top-view-small.jpg" alt="nRF52840 DK"/></details> |
108 | [nRF5340 DK](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF5340-DK)   | `nrf5340dk_nrf5340_cpuapp` | <details><summary>nRF5340 DK</summary><img src="../../platform/nrfconnect/doc/images/nRF5340-DK_top-view-small.jpg" alt="nRF5340 DK"/></details>    |
109
110 <hr>
111
112 <a name="device-ui"></a>
113
114 ## Device UI
115
116 This section lists the User Interface elements that you can use to control and
117 monitor the state of the device. These correspond to PCB components on the
118 platform image.
119
120 **LED 1** shows the overall state of the device and its connectivity. The
121 following states are possible:
122
123 -   _Short Flash On (50 ms on/950 ms off)_ &mdash; The device is in the
124     unprovisioned (unpaired) state and is waiting for a commissioning
125     application to connect.
126
127 -   _Rapid Even Flashing (100 ms on/100 ms off)_ &mdash; The device is in the
128     unprovisioned state and a commissioning application is connected through
129     Bluetooth LE.
130
131 -   _Short Flash Off (950ms on/50ms off)_ &mdash; The device is fully
132     provisioned, but does not yet have full Thread network or service
133     connectivity.
134
135 -   _Solid On_ &mdash; The device is fully provisioned and has full Thread
136     network and service connectivity.
137
138 **LED 2** simulates the light bulb and shows the state of the lighting. The
139 following states are possible:
140
141 -   _Solid On_ &mdash; The light bulb is on.
142
143 -   _Off_ &mdash; The light bulb is off.
144
145 **Button 1** can be used for the following purposes:
146
147 -   _Pressed for 6 s_ &mdash; Initiates the factory reset of the device.
148     Releasing the button within the 6-second window cancels the factory reset
149     procedure. **LEDs 1-4** blink in unison when the factory reset procedure is
150     initiated.
151
152 -   _Pressed for less than 3 s_ &mdash; Initiates the OTA software update
153     process. This feature is not currently supported.
154
155 **Button 2** &mdash; Pressing the button once changes the lighting state to the
156 opposite one.
157
158 **Button 3** &mdash; Pressing the button once starts the Thread networking in
159 the test mode using the default configuration.
160
161 **Button 4** &mdash; Pressing the button once starts the NFC tag emulation and
162 enables Bluetooth LE advertising for the predefined period of time.
163
164 **SEGGER J-Link USB port** can be used to get logs from the device or
165 communicate with it using the
166 [command line interface](../../../docs/guides/nrfconnect_examples_cli.md).
167
168 **NFC port with antenna attached** can be used to start the
169 [rendezvous](#bluetooth-le-rendezvous) by providing the commissioning
170 information from the CHIP device in a data payload that can be shared using NFC.
171
172 <hr>
173
174 ## Setting up the environment
175
176 Before building the example, check out the CHIP repository and sync submodules
177 using the following command:
178
179         $ git submodule update --init
180
181 The example requires a specific revision of the nRF Connect SDK. You can either
182 install it along with the related tools directly on your system or use a Docker
183 image that has the tools pre-installed.
184
185 If you are a macOS user, you won't be able to use the Docker container to flash
186 the application onto a Nordic development kit due to
187 [certain limitations of Docker for macOS](https://docs.docker.com/docker-for-mac/faqs/#can-i-pass-through-a-usb-device-to-a-container).
188 Use the [native shell](#using-native-shell) for building instead.
189
190 ### Using Docker container for setup
191
192 To use the Docker container for setup, complete the following steps:
193
194 1.  If you do not have the nRF Connect SDK installed yet, create a directory for
195     it by running the following command:
196
197         $ mkdir ~/nrfconnect
198
199 2.  Download the latest version of the nRF Connect SDK Docker image by running
200     the following command:
201
202         $ docker pull nordicsemi/nrfconnect-chip
203
204 3.  Start Docker with the downloaded image by running the following command,
205     customized to your needs as described below:
206
207          $ docker run --rm -it -e RUNAS=$(id -u) -v ~/nrfconnect:/var/ncs -v ~/connectedhomeip:/var/chip \
208              -v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule "c 189:* rmw" nordicsemi/nrfconnect-chip
209
210     In this command:
211
212     -   _~/nrfconnect_ can be replaced with an absolute path to the nRF Connect
213         SDK source directory.
214     -   _~/connectedhomeip_ must be replaced with an absolute path to the CHIP
215         source directory.
216     -   _-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule "c 189:_ rmw"\*
217         parameters can be omitted if you are not planning to flash the example
218         onto hardware. These parameters give the container access to USB devices
219         connected to your computer such as the nRF52840 DK.
220     -   _--rm_ can be omitted if you do not want the container to be
221         auto-removed when you exit the container shell session.
222     -   _-e RUNAS=\$(id -u)_ is needed to start the container session as the
223         current user instead of root.
224
225 4.  Update the nRF Connect SDK to the most recent supported revision, by running
226     the following command:
227
228          $ cd /var/chip
229          $ python3 scripts/setup/nrfconnect/update_ncs.py --update
230
231 Now you can proceed with the [Building](#building) instruction.
232
233 ### Using native shell for setup
234
235 To use the native shell for setup, complete the following steps:
236
237 1.  Download and install the following additional software:
238
239     -   [nRF Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
240     -   [GN meta-build system](https://gn.googlesource.com/gn/)
241
242 2.  If you do not have the nRF Connect SDK installed, follow the
243     [guide](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#)
244     in the nRF Connect SDK documentation to install the latest stable nRF
245     Connect SDK version. Since command-line tools will be used for building the
246     example, installing SEGGER Embedded Studio is not required.
247
248     If you have the SDK already installed, continue to the next step and update
249     the nRF Connect SDK after initializing environment variables.
250
251 3.  Initialize environment variables referred to by the CHIP and the nRF Connect
252     SDK build scripts. Replace _nrfconnect-dir_ with the path to your nRF
253     Connect SDK installation directory, and _toolchain-dir_ with the path to GNU
254     Arm Embedded Toolchain.
255
256          $ source nrfconnect-dir/zephyr/zephyr-env.sh
257          $ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
258          $ export GNUARMEMB_TOOLCHAIN_PATH=toolchain-dir
259
260 4.  Update the nRF Connect SDK to the most recent supported revision by running
261     the following command (replace _chip-dir_ with the path to CHIP repository
262     directory):
263
264          $ cd chip-dir
265          $ python3 scripts/setup/nrfconnect/update_ncs.py --update
266
267 Now you can proceed with the [Building](#building) instruction.
268
269 <hr>
270
271 <a name="building"></a>
272
273 ## Building
274
275 Complete the following steps, regardless of the method used for setting up the
276 environment:
277
278 1.  Navigate to the example's directory:
279
280         $ cd examples/lighting-app/nrfconnect
281
282 2.  Run the following command to build the example, with _build-target_ replaced
283     with the build target name of the Nordic Semiconductor's kit you own, for
284     example `nrf52840dk_nrf52840`:
285
286          $ west build -b build-target
287
288     You only need to specify the build target on the first build. See
289     [Requirements](#requirements) for the build target names of compatible kits.
290
291 The output `zephyr.hex` file will be available in the `build/zephyr/` directory.
292
293 ### Removing build artifacts
294
295 If you're planning to build the example for a different kit or make changes to
296 the configuration, remove all build artifacts before building. To do so, use the
297 following command:
298
299     $ rm -r build
300
301 ### Building with release configuration
302
303 To build the example with release configuration that disables the diagnostic
304 features like logs and command-line interface, run the following command:
305
306     $ west build -b build-target -- -DOVERLAY_CONFIG=third_party/connectedhomeip/config/nrfconnect/app/release.conf
307
308 Remember to replace _build-target_ with the build target name of the Nordic
309 Semiconductor's kit you own.
310
311 ### Building with Pigweed RPCs
312
313 The RPCs in `lighting-common/pigweed-lighting.proto` can be used to control
314 various functionalities of the lighting app from a USB-connected host computer.
315 To build the example with the RPC server, run the following command with
316 _build-target_ replaced with the build target name of the Nordic Semiconductor's
317 kit you own:
318
319     $ west build -b build-target -- -DOVERLAY_CONFIG=rpc.overlay
320
321 <hr>
322
323 <a name="configuring"></a>
324
325 ## Configuring the example
326
327 The Zephyr ecosystem is based on Kconfig files and the settings can be modified
328 using the menuconfig utility.
329
330 To open the menuconfig utility, run the following command from the example
331 directory:
332
333     $ west build -b build-target -t menuconfig
334
335 Remember to replace _build-target_ with the build target name of the Nordic
336 Semiconductor's kit you own.
337
338 Changes done with menuconfig will be lost if the `build` directory is deleted.
339 To make them persistent, save the configuration options in the `prj.conf` file.
340 For more information, see the
341 [Configuring nRF Connect SDK examples](../../../docs/guides/nrfconnect_examples_configuration.md)
342 page.
343
344 <hr>
345
346 <a name="flashing"></a>
347
348 ## Flashing and debugging
349
350 To flash the application to the device, use the west tool and run the following
351 command from the example directory:
352
353         $ west flash
354
355 If you have multiple development kits connected, west will prompt you to pick
356 the correct one.
357
358 To debug the application on target, run the following command from the example
359 directory:
360
361         $ west debug
362
363 <hr>
364
365 ## Testing the example
366
367 Check the [CLI tutorial](../../../docs/guides/nrfconnect_examples_cli.md) to
368 learn how to use command-line interface of the application.
369
370 ### Testing using CHIPTool
371
372 Read the
373 [Android commissioning guide](../../../docs/guides/nrfconnect_android_commissioning.md)
374 to see how to use [CHIPTool](../../../src/android/CHIPTool/README.md) for
375 Android smartphones to commission and control the application within a
376 CHIP-enabled Thread network.