Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zigbee: Add light switch sample #2226

Merged
merged 1 commit into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/nrf/ug_zigbee.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This library is available in `nrfxlib`_.

The OSIF subsystem acts as the linking layer between the ZBOSS stack and |NCS|.
It implements a series of functions used by ZBOSS and is included in the |NCS|'s Zigbee subsystem.
The files that handle the OSIF integration are located in :file:`subsys\zigbee\osif`.
The files that handle the OSIF integration are located in :file:`subsys/zigbee/osif`.

Configuration
*************
Expand Down
28 changes: 14 additions & 14 deletions samples/zigbee/light_bulb/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Zigbee: Light bulb

This Zigbee light bulb sample demonstrates a simple light bulb whose brightness can be regulated by a different device.

You can use this sample together with the :ref:`Zigbee network coordinator <zigbee_network_coordinator_sample>` and Zigbee light switch to set up a basic Zigbee network.
You can use this sample together with the :ref:`Zigbee network coordinator <zigbee_network_coordinator_sample>` and the :ref:`Zigbee light switch <zigbee_light_switch_sample>` to set up a basic Zigbee network.

Overview
********

The Zigbee light bulb sample assumes the Zigbee Router role and implements the Dimmable Light profile.
This profile allows to change the brightness level of a LED on the development kit that runs the light bulb sample.

In the default sample configuration, the changes to the light bulb brightness are reflected on LED 4.
In the default sample configuration, the changes to the light bulb brightness are reflected on **LED 4**.

Requirements
************
Expand All @@ -24,7 +24,7 @@ Requirements
* |nRF52833DK|

* The :ref:`Zigbee network coordinator <zigbee_network_coordinator_sample>` sample programmed on one separate device.
* The Zigbee light switch sample programmed on one or more separate devices.
* The :ref:`Zigbee light switch <zigbee_light_switch_sample>` sample programmed on one or more separate devices.

You can mix different development kits.

Expand Down Expand Up @@ -57,19 +57,19 @@ Testing
After programming the sample to your development kits, test it by performing the following steps:

1. Turn on the development kit that runs the network coordinator sample.
When LED 3 turns on, this development kit has become the coordinator of the Zigbee network and the network is established.
When **LED 3** turns on, this development kit has become the coordinator of the Zigbee network and the network is established.
#. Turn on the development kit that runs the light bulb sample.
When LED 3 turns on, the light bulb has become a Router inside the network.
When **LED 3** turns on, the light bulb has become a Router inside the network.

.. tip::
If LED 3 does not turn on, press Button 1 on the coordinator to reopen the network.
If **LED 3** does not turn on, press **Button 1** on the coordinator to reopen the network.

#. Turn on the development kit that runs the light switch sample.
When LED 3 turns on, the light switch has become an End Device, connected directly to the Coordinator.
#. Wait until LED 4 on the development kit that runs the light switch sample turns on.
When **LED 3** turns on, the light switch has become an End Device, connected directly to the Coordinator.
#. Wait until **LED 4** on the development kit that runs the light switch sample turns on.
This LED indicates that the switch found a light bulb to control.
#. Use buttons on the development kit that runs the light switch sample to control the light bulb, as described in the light switch sample's user interface section.
The result of using the buttons is reflected on the light bulb's LED 4.
The result of using the buttons is reflected on the light bulb's **LED 4**.


Dependencies
Expand All @@ -79,9 +79,9 @@ This sample uses the following |NCS| libraries:

* Zigbee subsystem:

* ``zb_nrf_platform.h``
* ``zigbee_helpers.h``
* ``zb_error_handler.h``
* :file:`zb_nrf_platform.h`
* :file:`zigbee_helpers.h`
* :file:`zb_error_handler.h`

* :ref:`dk_buttons_and_leds_readme`

Expand All @@ -91,7 +91,7 @@ This sample uses the following `nrfxlib`_ libraries:

In addition, it uses the following Zephyr libraries:

* ``include/zephyr.h``
* ``include/device.h``
* :file:`include/zephyr.h`
* :file:`include/device.h`
* :ref:`zephyr:logging_api`
* :ref:`zephyr:pwm_api`
19 changes: 19 additions & 0 deletions samples/zigbee/light_switch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

cmake_minimum_required(VERSION 3.13.1)

include($ENV{ZEPHYR_BASE}/../nrf/cmake/boilerplate.cmake)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project("Light Switch")

# NORDIC SDK APP START
target_sources(app PRIVATE
src/main.c
)
target_include_directories(app PRIVATE include)
# NORDIC SDK APP END
113 changes: 113 additions & 0 deletions samples/zigbee/light_switch/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
.. _zigbee_light_switch_sample:

Zigbee: Light switch
####################

The Zigbee light switch sample can be used to change the state of light sources on other devices within the same Zigbee network.

You can use this sample together with the :ref:`Zigbee network coordinator <zigbee_network_coordinator_sample>` and the :ref:`Zigbee light bulb <zigbee_light_bulb_sample>` to set up a basic Zigbee network.

Overview
********

The light switch sample demonstrates the Zigbee End Device role and implements the Dimmer Light Switch profile.

Once the light switch is successfully commissioned, it sends a broadcast message to find any devices with the implemented Level Control and On/Off clusters.
The light switch remembers the device network address from the first response and can be controlled with the development kit buttons.

Requirements
************

* One or more of the following development kits:

* |nRF52840DK|
* |nRF52833DK|

* The :ref:`zigbee_network_coordinator_sample` sample programmed on one separate device.
* The :ref:`zigbee_light_bulb_sample` sample programmed on one or more separate devices.

You can mix different development kits.

.. _zigbee_light_switch_user_interface:

User interface
**************

LED 3:
Indicates whether the device is connected to a Zigbee network.

LED 4:
Indicates that the light switch has found a light bulb to control.

Button 1:
When the light bulb has been turned off, pressing this button once turns it back on.
When pressed for a longer period of time, increases the brightness of the light bulb.

Button 2:
After the successful commissioning (light switch's **LED 3** turned on), pressing this button once turns off the light bulb connected to the network (light bulb's **LED 4**).
When pressed for a longer period of time, decreases the brightness of the **LED 4** of the connected light bulb.

.. note::
If the brightness level is decreased to the minimum, the effect of turning on the light bulb might not be noticeable.

Button 3:
When pressed while resetting the board, enables the Sleepy End Device behavior.

Button 4:
When pressed, toggles the Finding & Binding mode on the local endpoint on or off.


Building and running
********************

.. |sample path| replace:: :file:`samples/zigbee/light_switch`

|enable_zigbee_before_testing|

.. include:: /includes/build_and_run.txt

.. _zigbee_light_switch_testing:

Testing
=======

After programming the sample to your development kits, test it by performing the following steps:

1. Turn on the development kit that runs the network coordinator sample.
When **LED 3** turns on, this development kit has become the coordinator of the Zigbee network.
#. Turn on the development kit that runs the light bulb sample.
When **LED 3** turns on, the light bulb has become a Router inside the network.

.. tip::
If **LED 3** does not turn on, press **Button 1** on the coordinator to reopen the network.

#. Turn on the development kit that runs the light switch sample.
When **LED 3** turns on, the light switch has become an End Device, connected directly to the Coordinator.
#. Wait until **LED 4** on the light switch node turns on.
This LED indicates that the light switch found a light bulb to control.

You can now use buttons on the board to control the light bulb, as described in :ref:`zigbee_light_switch_user_interface`.

Dependencies
************

This sample uses the following |NCS| libraries:

* Zigbee subsystem:

* :file:`zb_nrf_platform.h`
* :file:`zigbee_helpers.h`
* :file:`zb_error_handler.h`

* :ref:`dk_buttons_and_leds_readme`

This sample uses the following `nrfxlib`_ libraries:

* ZBOSS Zigbee Stack

In addition, it uses the following Zephyr libraries:

* :file:`include/zephyr.h`
* :file:`include/device.h`
* :ref:`zephyr:logging_api`
* :ref:`zephyr:pwm_api`
32 changes: 32 additions & 0 deletions samples/zigbee/light_switch/app.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/delete-node/ &scratch_partition;
/delete-node/ &storage_partition;

&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

scratch_partition: partition@da000 {
label = "image-scratch";
reg = <0x000DA000 0x00015000>;
};
zboss_partition: partition@ef000 {
label = "zboss_nvram";
reg = <0x000EF000 0x00008000>;
};
prod_config_partition: partition@f7000 {
label = "product_config";
reg = <0x000F7000 0x00001000>;
};
storage_partition: partition@f8000 {
label = "storage";
reg = <0x000F8000 0x00008000>;
};
};
};
42 changes: 42 additions & 0 deletions samples/zigbee/light_switch/include/zb_mem_config_custom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
*/

#ifndef ZB_MEM_CONFIG_CUSTOM_H
#define ZB_MEM_CONFIG_CUSTOM_H 1


#define ZB_CONFIG_ROLE_ZED
#define ZB_CONFIG_OVERALL_NETWORK_SIZE 16

/**
* Light routing and application traffic from/to that device.
*/
#define ZB_CONFIG_LIGHT_TRAFFIC

/**
* Simple user's application at that device: not too many relations
* to other devices.
*/
#define ZB_CONFIG_APPLICATION_SIMPLE

/**
* Now common logic derives numerical parameters from the defined
* configuration.
*/
#include "zb_mem_config_common.h"

/**
* Now if you REALLY know what you do, you can study zb_mem_config_common.h
* and redefine some configuration parameters, like:
*/
#undef ZB_CONFIG_SCHEDULER_Q_SIZE
#define ZB_CONFIG_SCHEDULER_Q_SIZE 24


/* Memory context definitions */
#include "zb_mem_config_context.h"

#endif /* ZB_MEM_CONFIG_CUSTOM_H */
32 changes: 32 additions & 0 deletions samples/zigbee/light_switch/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

CONFIG_NCS_SAMPLES_DEFAULTS=y

CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_SERIAL=y
CONFIG_GPIO=y

# Make sure printk is not printing to the UART console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

CONFIG_HEAP_MEM_POOL_SIZE=2048

CONFIG_ZIGBEE=y
CONFIG_ZIGBEE_ROLE_END_DEVICE=y

# Enable bonding
CONFIG_NVS=y

# Enable DK LED and Buttons library
CONFIG_DK_LIBRARY=y

# This example requires more workqueue stack
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

# Cryptocell is not supported through CSPRNG driver API: NCSDK-4813
CONFIG_ENTROPY_CC310=n
9 changes: 9 additions & 0 deletions samples/zigbee/light_switch/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sample:
name: Zigbee Light switch
description: Zigbee dimmable light switch based on ZBOSS stack
tests:
test_build:
build_only: true
build_on_all: true
platform_whitelist: nrf52840dk_nrf52840
tags: ci_build
Loading