Skip to content

Commit

Permalink
Merge pull request #12 from rosek86/dev
Browse files Browse the repository at this point in the history
Update LBS example
  • Loading branch information
rosek86 authored Dec 23, 2023
2 parents 6ad3191 + 191b442 commit 41a5e9a
Show file tree
Hide file tree
Showing 17 changed files with 726 additions and 5 deletions.
4 changes: 0 additions & 4 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@
/tsconfig.prod.json
/gatt-profiles.json
/assigned-numbers
/.prettierignore
/.prettierrc
/.eslintignore
/.eslintrc
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## [1.1.3] - 2023-12-23

- Update LBS example

## [1.1.2] - 2023-12-23

- Improve connection stability
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class App extends NbleGapCentral {
return; // ignore
}
console.log(e);
} finally {
console.log("Disconnecting...");
await this.disconnect(event.connectionHandle).catch(() => {});
}
Expand Down
1 change: 1 addition & 0 deletions examples/le-central-lbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class App extends NbleGapCentral {
return; // ignore
}
console.log(e);
} finally {
console.log("Disconnecting...");
await this.disconnect(event.connectionHandle).catch(() => {});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bluetooth-hci",
"version": "1.1.2",
"version": "1.1.3",
"description": "Bluetooth HCI host implementation",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
Expand Down
6 changes: 6 additions & 0 deletions zephyr/peripheral_lbs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# editors
*.swp
*~

# build
/build*/
17 changes: 17 additions & 0 deletions zephyr/peripheral_lbs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(peripheral_lbs)

# NORDIC SDK APP START
target_sources(app PRIVATE
src/main.c
)

# NORDIC SDK APP END
zephyr_library_include_directories(.)
24 changes: 24 additions & 0 deletions zephyr/peripheral_lbs/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

source "Kconfig.zephyr"

menu "Nordic LED-Button BLE GATT service sample"

config BT_LBS_SECURITY_ENABLED
bool "Enable security"
default y
select BT_SMP
select BT_SETTINGS
select FLASH
select FLASH_PAGE_LAYOUT
select FLASH_MAP
select NVS
select SETTINGS
help
"Enable BLE security for the LED-Button service"

endmenu
10 changes: 10 additions & 0 deletions zephyr/peripheral_lbs/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

source "${ZEPHYR_BASE}/share/sysbuild/Kconfig"

config NRF_DEFAULT_BLUETOOTH
default y
168 changes: 168 additions & 0 deletions zephyr/peripheral_lbs/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
.. _peripheral_lbs:

Bluetooth: Peripheral LBS
#########################

.. contents::
:local:
:depth: 2

The peripheral LBS sample demonstrates how to use the :ref:`lbs_readme`.

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

The sample supports the following development kits:

.. table-from-sample-yaml::

.. include:: /includes/tfm.txt

The sample also requires a smartphone or tablet running a compatible application.
The `Testing`_ instructions refer to `nRF Connect for Mobile`_, but you can also use other similar applications (for example, `nRF Blinky`_ or `nRF Toolbox`_).

.. note::
|thingy53_sample_note|

Overview
********

When connected, the sample sends the state of **Button 1** on the development kit to the connected device, such as a phone or tablet.
The mobile application on the device can display the received button state and control the state of **LED 3** on the development kit.

You can also use this sample to control the color of the RGB LED on the nRF52840 Dongle or Thingy:53.

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

The user interface of the sample depends on the hardware platform you are using.

nRF52840 Dongle
===============

Green LED:
Blinks, toggling on/off every second, when the main loop is running and the device is advertising.

RGB LED:
The RGB LED channels are used independently to display the following information:

* Red - If Dongle is connected.
* Green - If user set the LED using Nordic LED Button Service.

Button 1:
Send a notification with the button state: "pressed" or "released".

Thingy:53
=========

RGB LED:
The RGB LED channels are used independently to display the following information:

* Red - If the main loop is running (that is, the device is advertising).
The LED blinks with a period of two seconds, duty cycle 50%.
* Green - If the device is connected.
* Blue - If user set the LED using Nordic LED Button Service.

For example, if Thingy:53 is connected over Bluetooth, the LED color toggles between green and yellow.
The green LED channel is kept on and the red LED channel is blinking.

Button 1:
Send a notification with the button state: "pressed" or "released".

Development kits
================

LED 1:
Blinks when the main loop is running (that is, the device is advertising) with a period of two seconds, duty cycle 50%.

LED 2:
Lit when the development kit is connected.

LED 3:
Lit when the development kit is controlled remotely from the connected device.

Button 1:
Send a notification with the button state: "pressed" or "released".

Building and running
********************
.. |sample path| replace:: :file:`samples/bluetooth/peripheral_lbs`

.. include:: /includes/build_and_run_ns.txt

Minimal build
=============

You can build the sample with a minimum configuration as a demonstration of how to reduce code size and RAM usage, using the ``-DCONF_FILE='prj_minimal.conf'`` flag in your build.

See :ref:`cmake_options` for instructions on how to add this option to your build.
For example, when building on the command line, you can add the option as follows:

.. code-block:: console
west build samples/bluetooth/peripheral_lbs -- -DCONF_FILE='prj_minimal.conf'
.. _peripheral_lbs_testing:

Testing
=======

After programming the sample to your dongle or development kit, test it by performing the following steps:

1. Start the `nRF Connect for Mobile`_ application on your smartphone or tablet.
#. Power on the development kit or insert your dongle into the USB port.
#. Connect to the device from the application.
The device is advertising as ``Nordic_LBS``.
The services of the connected device are shown.
#. In **Nordic LED Button Service**, enable notifications for the **Button** characteristic.
#. Press **Button 1** on the device.
#. Observe that notifications with the following values are displayed:

* ``Button released`` when **Button 1** is released.
* ``Button pressed`` when **Button 1** is pressed.

#. Write the following values to the LED characteristic in the **Nordic LED Button Service**.
Depending on the hardware platform, this produces results described in the table.

+------------------------+---------+----------------------------------------------+
| Hardware platform | Value | Effect |
+========================+=========+==============================================+
| Development kit | ``OFF`` | Switch the **LED3** off. |
+ +---------+----------------------------------------------+
| | ``ON`` | Switch the **LED3** on. |
+------------------------+---------+----------------------------------------------+
| nRF52840 Dongle | ``OFF`` | Switch the green channel of the RGB LED off. |
+ +---------+----------------------------------------------+
| | ``ON`` | Switch the green channel of the RGB LED on. |
+------------------------+---------+----------------------------------------------+
| Thingy:53 | ``OFF`` | Switch the blue channel of the RGB LED off. |
+ +---------+----------------------------------------------+
| | ``ON`` | Switch the blue channel of the RGB LED on. |
+------------------------+---------+----------------------------------------------+

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

This sample uses the following |NCS| libraries:

* :ref:`lbs_readme`
* :ref:`dk_buttons_and_leds_readme`

In addition, it uses the following Zephyr libraries:

* :file:`include/zephyr/types.h`
* :file:`lib/libc/minimal/include/errno.h`
* :file:`include/sys/printk.h`
* :file:`include/sys/byteorder.h`
* :ref:`GPIO Interface <zephyr:api_peripherals>`
* :ref:`zephyr:bluetooth_api`:

* :file:`include/bluetooth/bluetooth.h`
* :file:`include/bluetooth/hci.h`
* :file:`include/bluetooth/conn.h`
* :file:`include/bluetooth/uuid.h`
* :file:`include/bluetooth/gatt.h`

The sample also uses the following secure firmware component:

* :ref:`Trusted Firmware-M <ug_tfm>`
5 changes: 5 additions & 0 deletions zephyr/peripheral_lbs/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VERSION_MAJOR = 2
VERSION_MINOR = 5
PATCHLEVEL = 0
VERSION_TWEAK = 0
EXTRAVERSION =
19 changes: 19 additions & 0 deletions zephyr/peripheral_lbs/boards/thingy53_nrf5340_cpuapp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2021 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
################################################################################
# Application overlay - Thingy:53 DFU

CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096

# Use deferred logging
CONFIG_NCS_SAMPLES_DEFAULTS=n
CONFIG_LOG=y
CONFIG_ASSERT=y
CONFIG_ASSERT_NO_COND_INFO=y
CONFIG_ASSERT_NO_MSG_INFO=y
CONFIG_HW_STACK_PROTECTION=y
19 changes: 19 additions & 0 deletions zephyr/peripheral_lbs/boards/thingy53_nrf5340_cpuapp_ns.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Copyright (c) 2021 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
################################################################################
# Application overlay - Thingy:53 DFU

CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096

# Use deferred logging
CONFIG_NCS_SAMPLES_DEFAULTS=n
CONFIG_LOG=y
CONFIG_ASSERT=y
CONFIG_ASSERT_NO_COND_INFO=y
CONFIG_ASSERT_NO_MSG_INFO=y
CONFIG_HW_STACK_PROTECTION=y
17 changes: 17 additions & 0 deletions zephyr/peripheral_lbs/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
CONFIG_NCS_SAMPLES_DEFAULTS=y

CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Nordic_LBS"

# Enable the LBS service
CONFIG_BT_LBS=y
CONFIG_BT_LBS_POLL_BUTTON=y
CONFIG_DK_LIBRARY=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
Loading

0 comments on commit 41a5e9a

Please sign in to comment.