1 # CHIP nRF Connect Lighting Example Application
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.
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">
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.
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.
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)
42 <a name="overview"></a>
46 This example is running on the nRF Connect platform, which is based on Nordic
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.
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.
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
64 ### Bluetooth LE advertising
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**.
70 ### Bluetooth LE rendezvous
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
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
82 #### Thread provisioning
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.
91 <a name="requirements"></a>
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
99 <a name="supported_devices"></a>
101 ### Supported devices
103 The example supports building and running on the following devices:
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> |
112 <a name="device-ui"></a>
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
120 **LED 1** shows the overall state of the device and its connectivity. The
121 following states are possible:
123 - _Short Flash On (50 ms on/950 ms off)_ — The device is in the
124 unprovisioned (unpaired) state and is waiting for a commissioning
125 application to connect.
127 - _Rapid Even Flashing (100 ms on/100 ms off)_ — The device is in the
128 unprovisioned state and a commissioning application is connected through
131 - _Short Flash Off (950ms on/50ms off)_ — The device is fully
132 provisioned, but does not yet have full Thread network or service
135 - _Solid On_ — The device is fully provisioned and has full Thread
136 network and service connectivity.
138 **LED 2** simulates the light bulb and shows the state of the lighting. The
139 following states are possible:
141 - _Solid On_ — The light bulb is on.
143 - _Off_ — The light bulb is off.
145 **Button 1** can be used for the following purposes:
147 - _Pressed for 6 s_ — 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
152 - _Pressed for less than 3 s_ — Initiates the OTA software update
153 process. This feature is not currently supported.
155 **Button 2** — Pressing the button once changes the lighting state to the
158 **Button 3** — Pressing the button once starts the Thread networking in
159 the test mode using the default configuration.
161 **Button 4** — Pressing the button once starts the NFC tag emulation and
162 enables Bluetooth LE advertising for the predefined period of time.
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).
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.
174 ## Setting up the environment
176 Before building the example, check out the CHIP repository and sync submodules
177 using the following command:
179 $ git submodule update --init
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.
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.
190 ### Using Docker container for setup
192 To use the Docker container for setup, complete the following steps:
194 1. If you do not have the nRF Connect SDK installed yet, create a directory for
195 it by running the following command:
199 2. Download the latest version of the nRF Connect SDK Docker image by running
200 the following command:
202 $ docker pull nordicsemi/nrfconnect-chip
204 3. Start Docker with the downloaded image by running the following command,
205 customized to your needs as described below:
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
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
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.
225 4. Update the nRF Connect SDK to the most recent supported revision, by running
226 the following command:
229 $ python3 scripts/setup/nrfconnect/update_ncs.py --update
231 Now you can proceed with the [Building](#building) instruction.
233 ### Using native shell for setup
235 To use the native shell for setup, complete the following steps:
237 1. Download and install the following additional software:
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/)
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.
248 If you have the SDK already installed, continue to the next step and update
249 the nRF Connect SDK after initializing environment variables.
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.
256 $ source nrfconnect-dir/zephyr/zephyr-env.sh
257 $ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
258 $ export GNUARMEMB_TOOLCHAIN_PATH=toolchain-dir
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
265 $ python3 scripts/setup/nrfconnect/update_ncs.py --update
267 Now you can proceed with the [Building](#building) instruction.
271 <a name="building"></a>
275 Complete the following steps, regardless of the method used for setting up the
278 1. Navigate to the example's directory:
280 $ cd examples/lighting-app/nrfconnect
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`:
286 $ west build -b build-target
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.
291 The output `zephyr.hex` file will be available in the `build/zephyr/` directory.
293 ### Removing build artifacts
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
301 ### Building with release configuration
303 To build the example with release configuration that disables the diagnostic
304 features like logs and command-line interface, run the following command:
306 $ west build -b build-target -- -DOVERLAY_CONFIG=third_party/connectedhomeip/config/nrfconnect/app/release.conf
308 Remember to replace _build-target_ with the build target name of the Nordic
309 Semiconductor's kit you own.
311 ### Building with Pigweed RPCs
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
319 $ west build -b build-target -- -DOVERLAY_CONFIG=rpc.overlay
323 <a name="configuring"></a>
325 ## Configuring the example
327 The Zephyr ecosystem is based on Kconfig files and the settings can be modified
328 using the menuconfig utility.
330 To open the menuconfig utility, run the following command from the example
333 $ west build -b build-target -t menuconfig
335 Remember to replace _build-target_ with the build target name of the Nordic
336 Semiconductor's kit you own.
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)
346 <a name="flashing"></a>
348 ## Flashing and debugging
350 To flash the application to the device, use the west tool and run the following
351 command from the example directory:
355 If you have multiple development kits connected, west will prompt you to pick
358 To debug the application on target, run the following command from the example
365 ## Testing the example
367 Check the [CLI tutorial](../../../docs/guides/nrfconnect_examples_cli.md) to
368 learn how to use command-line interface of the application.
370 ### Testing using CHIPTool
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.