Project Connected Home over IP: Light bulb

This light bulb sample demonstrates the usage of the Project Connected Home over IP application layer to build a white dimmable light bulb device. This device works as a Project CHIP accessory, meaning it can be paired and controlled remotely over a Project CHIP network built on top of a low-power, 802.15.4 Thread network. You can use this sample as a reference for creating your own application.

Note

This sample is self-contained and can be tested on its own. However, it is required when testing the Project CHIP light switch sample.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF52840 DK

PCA10056

nrf52840dk_nrf52840

nrf52840dk_nrf52840

nRF5340 DK

PCA10095

nrf5340dk_nrf5340

nrf5340dk_nrf5340_cpuapp

For remote testing scenarios, you also need the following:

  • If you want to commission the light bulb device and control it remotely through a Thread network:

    • A smartphone compatible with Android for using the Android CHIPTool application as the CHIP controller.

  • If you want to use the test mode and control the light bulb using light switch:

Note

Project CHIP requires the GN tool. If you are updating from the nRF Connect SDK version earlier than v1.5.0, see Installing the required tools for installation instructions.

Overview

The sample uses buttons to test changing the light bulb and device states, and LEDs to show the state of these changes. It can be tested in the following ways:

  • Standalone, by using a single DK that runs the light bulb application.

  • Remotely over the Thread protocol, which requires more devices.

The remote control testing requires either commissioning by the Project CHIP controller device into a network or using the test mode. Both methods can be enabled after building and running the sample.

Remote testing in a network

By default, the Project CHIP device has Thread disabled, and it must be paired with the Project CHIP controller over Bluetooth LE to get configuration from it if you want to use the device within a Thread network. To do this, the device must be made discoverable manually (for security reasons) and the controller must get the commissioning information from the Project CHIP device and provision the device into the network. For details, see the Commissioning the device section.

Remote testing using test mode

Alternatively to the commissioning procedure, you can use the test mode, which allows to join a Thread network with default static parameters and static cryptographic keys. Use Button 3 to enable this mode after building and running the sample.

Note

The test mode is not compliant with Project CHIP and it only works together with Project CHIP controller and other devices which use the same default configuration.

Using the test mode allows you to control the light bulb remotely without using a smartphone compatible with Android. The light bulb device programmed with this sample can be used with the light switch device programmed with the Project CHIP light switch sample to create a simplified Thread network.

Configuration

See Configuring your application for information about how to permanently or temporarily change the configuration.

User interface

LED 1:

Shows the overall state of the device and its connectivity. The following states are possible:

  • Short Flash On (50 ms on/950 ms off) - The device is in the unprovisioned (unpaired) state and is waiting for a commissioning application to connect.

  • Rapid Even Flashing (100 ms on/100 ms off) - The device is in the unprovisioned state and a commissioning application is connected through Bluetooth LE.

  • Short Flash Off (950 ms on/50 ms off) - The device is fully provisioned, but does not yet have full Thread network or service connectivity.

  • Solid On - The device is fully provisioned and has full Thread network and service connectivity.

LED 2:

Shows the state of the light bulb. The following states are possible:

  • Solid On - The light bulb is on.

  • Off - The light bulb is off.

Button 1:

Initiates the factory reset of the device.

Button 2:

Changes the light bulb state to the opposite one.

Button 3:

Starts the Thread networking in the test mode using the default configuration.

When running application in light switch test mode it also starts publishing the light bulb service messages for a predefined period of time to advertise the light bulb device IP address to the light switch device (if used). If for some reason the light switch device is not able to receive messages during this predefined period of time, you can restart publishing service by pressing this button again.

Button 4:

Starts the the NFC tag emulation, enables Bluetooth LE advertising for the predefined period of time, and makes the device discoverable over Bluetooth LE. This button is used during the commissioning procedure.

SEGGER J-Link USB port:

Used for getting logs from the device or communicating with it through the command-line interface.

NFC port with antenna attached:

Optionally used for obtaining the commissioning information from the Project CHIP device to start the commissioning procedure.

Building and running

This sample can be found under samples/connectedhomeip/light_bulb in the nRF Connect SDK folder structure.

See Building and programming a sample application for information about how to build and program the application.

Testing

You can either test the sample’s basic features or use the light switch sample to test the light bulb’s communication with another device.

Testing basic features

After building the sample and programming it to your development kit, test its basic features by completing the following steps:

  1. Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

  2. Connect to the kit with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.

  3. Observe that LED 2 is off.

  4. Press Button 2 on the light bulb device. The LED 2 turns on and the following messages appear on the console:

    I: Turn On Action has been initiated
    I: Turn On Action has been completed
    
  5. Press Button 2 again. The LED 2 turns off and the following messages appear on the console:

    I: Turn Off Action has been initiated
    I: Turn Off Action has been completed
    
  6. Press Button 1 to initiate the factory reset of the device.

Testing communication with another device

After building this sample and the Project CHIP light switch sample and programming them to development kits, test communication between both devices by completing the following steps:

  1. Complete the following actions for both devices:

    1. Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

    2. Connect to the kit with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.

  2. On both devices, press Button 1 to reset them to factory settings.

  3. Pair both devices by completing the following steps:

    1. On the light switch device, press Button 3 to enable pairing on this device. The light switch becomes the Thread network Leader. The following messages appear in the console for the light switch device:

      I: Device is not commissioned to a Thread network. Starting with the default configuration
      I: Starting light bulb discovery
      
    2. On the light bulb device, press Button 3 to enable pairing on this device. The following messages appear on the console for the light bulb device:

      I: Device is not commissioned to a Thread network. Starting with the default configuration
      I: Started Publish service
      

      At this point, the light bulb is discovered by the light switch device and the following messages appear on the console for the light switch device:

      I: Stopping light bulb discovery
      I: Pairing with light bulb fdde:ad00:beef:0:7b0:750e:6d96:49e9
      
  4. On the light switch device, press Button 2 to turn off the light on the light bulb device. The following message appears on the console for the light switch device:

    I: Toggling the light
    

    LED 2 on the light bulb device turns off.

  5. On the light switch device, press Button 2 to turn on the light again. LED 2 on the light bulb device turns back on.

  6. On the light switch device, press Button 4 and hold it for a few seconds. Messages similar to the following one appear in the console:

    I: Setting brightness level to 7
    

    The brightness of LED 2 on the light bulb device changes while the button is pressed.

Enabling remote control

Remote control allows you to control the Project CHIP light bulb device from a Thread network.

You can use one of the following options to enable this option:

  • Commissioning the device, which allows you to set up testing environment and remotely control the sample over a Project-CHIP-enabled Thread network.

  • Remote testing using test mode, which allows you to test the sample functionalities in a Thread network with default parameters, without commissioning. Use Button 3 to enable this mode after building and running the sample.

Commissioning the device

To commission the device, go to the Commissioning nRF Connect Accessory using Android CHIPTool tutorial and complete the steps described there. As part of this tutorial, you will build and program OpenThread RCP firmware, configure Thread Border Router, build and install Android CHIPTool, commission the device, and send Project CHIP commands that cover scenarios described in the Testing section.

In Project CHIP, the commissioning procedure (called rendezvous) is done over Bluetooth LE between a Project CHIP device and the Project CHIP controller, where the controller has the commissioner role. When the procedure is finished, the device should be equipped with all information needed to securely operate in the Project CHIP network.

During the last part of the commissioning procedure (the provisioning operation), Thread network credentials are sent from the Project CHIP controller to the Project CHIP device. As a result, the device is able to join the Thread network and communicate with other Thread devices in the network.

Note

Currently, Project CHIP samples do not support storing Project CHIP operational credentials exchanged during commissioning in the non-volatile memory.

To start the commissioning procedure, the controller must get the commissioning information from the Project CHIP device. The data payload, which includes the device discriminator and setup PIN code, is encoded within a QR code, printed to the UART console, and can be shared using an NFC tag.

Dependencies

This sample uses Connected Home over IP library which includes the nRF Connect SDK platform integration layer:

In addition, the sample uses the following nRF Connect SDK components:

The sample depends on the following Zephyr libraries: