-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: zigbee: Add light switch sample
Add light switch sample Signed-off-by: Mariusz Poslinski <[email protected]>
- Loading branch information
Showing
11 changed files
with
746 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
42
samples/zigbee/light_switch/include/zb_mem_config_custom.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.