Project Connected Home over IP: Light switch

This light switch sample demonstrates the usage of the Project Connected Home over IP application layer to build a basic controller device for the CHIP light bulb sample. This device works as a Project CHIP controller, meaning that it can control a light bulb 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.

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 this sample to work, you also need the Project CHIP light bulb sample programmed to another supported development kit.

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 light switch must be put into the test mode and paired with a light bulb device to be able to send Project CHIP light bulb control commands such as toggling the light and setting its brightness level.

Test mode

Unlike other samples, such as Project CHIP door lock, the light switch sample does not support Project CHIP commissioning over Bluetooth LE. To make the light switch and the light bulb devices able to communicate with each other, they must be initialized with the same static Thread network parameters and static Project CHIP cryptographic keys.

Pressing Button 3 activates the test mode before enabling the pairing phase on the device.

Pairing

After the test mode is activated and both devices are initialized with the same network parameters, the pairing phase starts. During this phase, the light bulb device periodically sends multicast messages with static content. Once such a message is intercepted by the light switch device, the light switch is made aware of the IP address of the nearby light bulb device and the pairing is done.

User interface

LED 1:

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

  • Solid Off - The device is not paired with any light bulb device.

  • Short Flash On (100 ms on/900 ms off) - The device is in the pairing phase.

  • Solid On - The device is paired with a light bulb device.

Button 1:

Initiates the factory reset of the device.

Button 2:

Toggles the light on the paired light bulb device.

Button 3:

Enables pairing for 10 seconds. It also starts the Thread networking in the test mode if the Thread network is not yet initialized.

Button 4:

Brightens the light on the paired light bulb device. The brightness level is increased gradually while the button is being pressed. When the button is pressed for too long, the brightness level wraps around and becomes the lowest possible.

SEGGER J-Link USB port:

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

Building and running

This sample can be found under samples/connectedhomeip/light_switch 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

After building this and CHIP light bulb samples, and programming them to your development kits, test communication between both devices by performing 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.

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: