1 # Commissioning NXP K32W using Android CHIPTool
3 This article describes how to use
4 [CHIPTool](../../src/android/CHIPTool/README.md) for Android smartphones to
5 commission an NXP K32W061 DK6 running
6 [NXP K32W Lock/Light Example Application](../../examples/lock-light-app/k32w/README.md)
7 onto a CHIP-enabled Thread network.
11 - [Overview](#overview)
12 - [Requirements](#requirements)
13 - [Building and programming OpenThread RCP firmware](#building-rcp-firmware)
14 - [Configuring PC as Thread Border Router](#configuring-pc)
15 - [Building and programming NXP K32W Lock/Light Example Application](#building-example)
16 - [Building and installing Android CHIPTool](#building-chiptool)
17 - [Forming a Thread network on the Border Router](#form-thread)
18 - [Preparing accessory device](#preparing-accessory)
19 - [Commissioning accessory device](#commissioning-accessory)
20 - [Sending CHIP commands](#sending-chip-commands)
24 <a name="overview"></a>
28 The commissioning process is composed of the following main stages:
30 - K32W061 (CHIP accessory) device is put in BLE advertisment mode by pressing
31 the USERINTERFACE button;
32 - CHIPTool discovers the CHIP accessory over BLE;
33 - CHIPTool establishes a secure channel with the accessory using a SPAKE2+
35 - CHIP tool sends Thread provisioning data over the secure channel;
36 - The accessory device joins a CHIP-enabled Thread network using the provided
39 Bluetooth LE is only used during the commissioning phase. Afterwards, only the
40 IP connectivity between the smartphone and the accessory device is needed to
41 send operational messages. Since a typical smartphone does not have a Thread
42 radio built-in, extra effort is needed to prepare a fully-fledged testing
43 environment. This page describes how to build a Thread Border Router using a PC
44 with a spare Wi-Fi card and an
45 [OpenThread Radio Co-Processor](https://openthread.io/platforms/co-processor)
48 The following diagram shows the connectivity between network components required
49 to allow communication between devices running the CHIPTool and Lock/Light
52 ![nxp_hw_connectivity](../../examples/platform/k32w/doc/images/nxp_hw_connectivity.JPG)
56 <a name="requirements"></a>
60 You need the following hardware and software to build a Thread Border Router:
62 - 2 K32W061 DK6 boards
64 - One K32W061 DK6 is needed to run
65 [OpenThread Radio Co-Processor](https://openthread.io/platforms/co-processor)
66 firmware and can be replaced with another compatible device like K32W061
69 - Smartphone compatible with Android 8.0 or later
70 - PC with the following characteristics:
72 - Software: Ubuntu 20.04
73 - Hardware: A spare Wi-Fi card (WiFi driver needs to support AP mode).
75 While this page references Ubuntu 20.04, all the procedures can be completed
76 using other popular operating systems.
80 <a name="building-rcp-firmware"></a>
82 ## Building and programming OpenThread RCP firmware
84 OpenThread RCP firmware is required to allow the PC to communicate with Thread
85 devices. Run the commands mentioned in the following steps to build and program
86 the RCP firmware onto an K32W061 DK6:
88 1. Clone the OpenThread repository into the current directory (we recommand
89 using commit ced158e65a00dd5394c04548b7b187d3a3f11eef):
91 $ git clone https://github.com/openthread/openthread.git
93 2. Enter the _openthread_ directory:
97 3. Install OpenThread dependencies:
101 4. Set up the build environment:
105 5. Build OpenThread for the K32W061 DK6:
107 $ make -f examples/Makefile-k32w061
109 This creates an RCP image in the `bin/ot-rcp` directory.
111 6. Program the RCP firmware using the official
112 [OpenThread Flash Instructions](https://github.com/openthread/openthread/blob/master/examples/platforms/k32w/k32w061/README.md#flash-binaries).
114 7. Plug-in the K32W061 DK6 to the PC.
118 <a name="configuring-pc"></a>
120 ## Configuring PC as a Thread Border Router
122 To make your PC work as a Thread Border Router, complete the following tasks:
124 1. Set up Thread Border Router package by following steps
125 [3,4,5](https://openthread.io/guides/border-router/build) from the official
126 documentation. Use NETWORK_MANAGER=0 as the Wi-Fi AP will be set manually at
127 the next step. Also, we recommend using commit
128 83babaf236cad8471be28185d8d4351d37564919 for ot-br-posix repository.
129 2. Configure the Wi-Fi AP
131 - Install the required package:
133 $ sudo apt-get install hostapd
135 - Configure hostapd (create new file and add content):
137 $ sudo vim /etc/hostapd/hostapd.conf
147 ignore_broadcast_ssid=0
149 wpa_passphrase=12345678
154 - We need to tell hostapd to use our config file by editing the main
155 hostapd configuration file. Change the line that starts with
156 #DAEMON_CONF (remember to remove #):
157 \$ sudo vim /etc/default/hostapd
159 DAEMON_CONF="/etc/hostapd/hostapd.conf"
163 $ sudo systemctl unmask hostapd
164 $ sudo systemctl enable hostapd
168 - Install the required package:
170 $ sudo apt-get install dnsmasq
172 - Make a backup of the default config file:
174 $ sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.org
176 - Set the DHCP range:
178 $ sudo vim /etc/dnsmasq.conf
181 dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
183 - On System startup, dnsmasq will not wait for wlan0 interface to
184 initialize and will fail. We need to tell systemd to launch it after
185 networks get ready, so we will modify dnsmasq service file by specifing
186 the initialization order under the _After=_ and _Wants=_ sections:
188 $ sudo vim /lib/systemd/system/dnsmasq.service
192 After=... network-online.target
193 Wants=... network-online.target
195 - Force systemd to avoid using port 53 (used by dnsmasqd service):
197 $ sudo vim /etc/systemd/resolved.conf
201 4. Configure static IP for the Wi-Fi AP interface
203 - Modify the cloud-init file and add content to it (use spaces, not tabs,
206 $ sudo vim /etc/netplan/50-cloud-init.yaml
213 - The final configuration file should like like this (pay attention to the
229 - Install required package:
231 \$ sudo apt-get install radvd
233 - Configure RADVD for distributing the prefix _fd11:33_::/64 to the
234 devices connected to the AP, while announcing them that is also has a
235 route to _fd11:22::/64_
236 \$ sudo vim /etc/radvd.conf
241 MinRtrAdvInterval 30;
242 MaxRtrAdvInterval 60;
243 prefix fd11:33::1/64 {
253 - Enable radvd service:
254 $ sudo chmod u=rw,g=r,o=r /etc/radvd.conf
255 $ sudo systemctl enable
258 6. Configure routing:
260 - Create a configuration file for setting the routing behavior (forward
261 between Thread and Wi-Fi AP interfaces):
263 $ sudo vim configurations.sh
266 sudo iptables -A FORWARD -i wlan0 -o wpan0 -j ACCEPT
267 sudo iptables -A FORWARD -i wpan0 -o wlan0 -j ACCEPT
270 - Set the executable bit for the above file:
272 $ sudo chmod +x configurations.sh
274 - Configure the above script to be run each time the PC is restarted using
275 a systemd service configuration (change the path for _ExecStart_):
277 $ sudo vim /etc/systemd/system/br.service
283 ExecStart=/home/replace_with_real_path/configurations.sh
288 WantedBy=multi-user.target
293 $ sudo systemctl daemon-reload
294 $ sudo systemctl enable br.service
296 7. As a quick checkpoint, restart the PC and make sure that the mobile phone
297 can connect to the _OT-BR_ AP (password: 12345678). Also, check that it gets
298 assigned an IPv4 address in the range _192.168.4.0/24_ and an IPV6 address
299 with the prefix _fd11:33::/64_. Commands for debugging possible issues with
302 $ sudo service hostapd status
303 $ sudo service dnsmasq status
304 $ sudo service radvd status
305 $ sudo service br status
309 <a name="building-example"></a>
311 ## Building and programming NXP K32W Lock/Light Example Application
314 [NXP K32W Lock Example Application README](../../examples/lock-app/k32w/README.md)
315 to learn how to build and program the lock example onto an K32W061 DK6.
318 [NXP K32W Light Example Application README](../../examples/lighting-app/k32w/README.md)
319 to learn how to build and program the light example onto an K32W061 DK6.
323 <a name="building-chiptool"></a>
325 ## Building and installing Android CHIPTool
327 To build the CHIPTool application for your smartphone, read
328 [Android CHIPTool README](../../src/android/CHIPTool/README.md).
330 After building, install the application by completing the following steps:
332 1. Install the Android Debug Bridge (adb) package by running the following
335 $ sudo apt install android-tools-adb
337 2. Enable _USB debugging_ on the smartphone. See the
338 [Configure on-device developer options](https://developer.android.com/studio/debug/dev-options)
339 guide on the Android Studio hub for detailed information.
340 3. If the _Install via USB_ option is supported for your Android version, turn
342 4. Plug the smartphone into an USB port on your PC.
343 5. Run the following command to install the application, with _chip-dir_
344 replaced with the path to the CHIP source directory:
346 $ adb install -r chip-dir/src/android/CHIPTool/app/build/outputs/apk/debug/app-debug.apk
348 6. Navigate to settings on your smartphone and grant _Camera_ and _Location_
349 permissions to CHIPTool.
351 CHIPTool is now ready to be used for commissioning.
355 <a name="form-thread"></a>
357 ## Forming a Thread network on the Border Router
359 1. On the mobile phone connect to the _OT-BR_ Wi-Fi network.
361 2. Open a browser and type the IP address 192.168.4.1. The Thread Border Router
362 Web Management page will open.
364 3. Navigate to the _Form_ tab then push the _Form_ button using the default
366 ![nxp_form_nwk](../../examples/platform/k32w/doc/images/form_web.JPG)
368 4. The message _Form operation is successful_ should be display after a few
371 5. In case you ever want to reset these parameters issue this command from the
374 $ sudo ot-ctl factoryreset
376 6. Info: For debugging the Border Router, _ot-ctl_ offers an entry point to
377 [Thread CLI Commands](https://github.com/openthread/openthread/blob/master/src/cli/README.md).
379 7. In case there is any issue with the Web GUI check the logs on the Border
380 Router side / restart the daemon:
382 $ sudo service otbr-web status
384 In case the status is not _leader_ then restart the service:
386 $ sudo service otbr-web restart
388 ## Preparing accessory device
390 To prepare the accessory device for commissioning, complete the following steps:
392 1. Make sure that JP4 and JP7 jumpers are in leftmost position and a mini-USB
393 cable is connected between the LPC connector and PC
394 ![nxp_connectors](../../examples/platform/k32w/doc/images/k32w-dk6-connectors.jpg)
396 2. Use a terminal emulator (e.g.: Putty) to connect to the UART console of the
397 accessory device. Use a baudrate of 115200.
399 This will grant you access to the application logs.
401 3. Push _Button SW2_ on the accessory device and wait 6s for factory reset of
403 4. Find a message similar to the following one in the application logs:
405 I: 666[SVR] Copy/paste the below URL in a browser to see the QR Code:
406 https://dhrishi.github.io/connectedhomeip/qrcode.html?data=CH%3AI34DV%2A-00%200C9SS0
408 5. Open the URL in a web browser to have the commissioning QR code generated.
412 <a name="commissioning-accessory"></a>
414 ## Commissioning accessory device
416 To commission the accessory device onto the Thread network created in the
417 [Forming Thread network](#Forming-a-Thread-network) section, complete the
420 1. Enable _Bluetooth_ and _Location_ services on your smartphone;
421 2. Connect the smartphone to _OT-BR_ WiFi network;
422 3. Open the CHIPTool application on your smartphone;
423 4. Push the USERINTERFACE button on the K32W board. This will start the BLE
425 5. Tap the _PROVISION CHIP DEVICE WITH THREAD_ button and scan the commissioning
426 QR code. Several notifications will appear, informing you of commissioning
427 progress with scanning, connection, and pairing. At the end of this process,
428 the Thread network settings screen appears.
430 ![chiptool_main_screen](../../examples/platform/k32w/doc/images/chiptool_main_screen.png)
432 6. In the Thread network settings screen, use the default settings and tap the
433 _SAVE NETWORK_ button to send a Thread provisioning message to the accessory
434 device. You will see the "Network provisioning completed" message when the
435 accessory device successfully joins the Thread network.
437 ![chiptool_credentials](../../examples/platform/k32w/doc/images/thread_credentials.png)
441 <a name="sending-commands"></a>
443 ## Sending CHIP commands
445 1. Once the device is commissioned, the below screen appears. This means that
446 the provisioning is completed successfully and you are connected to the
449 ![on_off_cluster.png](../../examples/platform/k32w/doc/images/on_off_cluster.png)
451 2. Verify that the text box on the screen is not empty and contains the IPv6
452 address of the accessory device.
453 3. Tap the following buttons to change the lock/light state:
455 - _ON_ and _OFF_ buttons lock/turn on and unlock/turn off the door/light
457 - _TOGGLE_ changes the lock/light state to the opposite.
459 The _LED D3_ on the device turns on or off based on the changes of the