Skip to content

Commit f40d115

Browse files
committed
samples: custom_connect: new sample
This sample provides following custom functionality: * BT scanning is handled by application, with additional filters (Bluetooth device name and RSSI) * sync pouch 2x during each BT connection with 5s delay between syncs; this simulates other BT communication that might happen in application code Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
1 parent fe30c42 commit f40d115

13 files changed

Lines changed: 723 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(gateway_custom_connect)
6+
7+
target_include_directories(app PRIVATE include ${CMAKE_CURRENT_BINARY_DIR})
8+
9+
target_sources(app PRIVATE
10+
src/main.c
11+
src/scan.c
12+
)

samples/custom_connect/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2025 Golioth, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
configdefault MBEDTLS_USE_PSA_CRYPTO
5+
default n
6+
7+
configdefault BT_CTLR_DATA_LENGTH_MAX
8+
default 251
9+
10+
source "${ZEPHYR_GOLIOTH_FIRMWARE_SDK_MODULE_DIR}/examples/zephyr/common/Kconfig.defconfig"
11+
12+
source "Kconfig.zephyr"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright (c) 2025 Golioth, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
menu "Gateway configuration"
5+
6+
config POUCH_GATEWAY_CLOUD
7+
bool "Send pouches to cloud"
8+
default y
9+
help
10+
Disabling cloud communication allows to test Bluetooth gateway
11+
functionality without relying on communication with backend. All
12+
pouches received from Bluetooth nodes are dropped in that case.
13+
14+
config GOLIOTH_COAP_HOST_URI
15+
string "CoAP server URI"
16+
default "coaps://coap.golioth.io"
17+
help
18+
The URI of the CoAP server.
19+
20+
endmenu
21+
22+
menu "BabbleSim components"
23+
depends on SOC = "native"
24+
25+
config BSIM_HANDBRAKE
26+
bool "Handbrake"
27+
default y if POUCH_GATEWAY_CLOUD
28+
29+
endmenu
30+
31+
menu "BabbleSim peripherals"
32+
depends on SOC = "native"
33+
34+
config PERIPHERAL_ZEPHYR
35+
bool "Zephyr"
36+
help
37+
Zephyr peripheral sample.
38+
39+
config PERIPHERAL_ZEPHYR_NUM
40+
int "Number of Zephyr peripherals"
41+
default 1
42+
depends on PERIPHERAL_ZEPHYR
43+
44+
config PERIPHERAL_PERIODIC_UPLINK
45+
bool "Periodic uplink"
46+
help
47+
Periodic uplink sample.
48+
49+
config PERIPHERAL_PERIODIC_UPLINK_NUM
50+
int "Number of periodic uplink peripherals"
51+
default 1
52+
depends on PERIPHERAL_PERIODIC_UPLINK
53+
54+
config PERIPHERAL_BLE_GATT_EXAMPLE
55+
bool "BLE GATT example"
56+
default y
57+
help
58+
BLE GATT sample.
59+
60+
config PERIPHERAL_BLE_GATT_EXAMPLE_NUM
61+
int "Number of BLE GATT example peripherals"
62+
default 1
63+
depends on PERIPHERAL_BLE_GATT_EXAMPLE
64+
65+
endmenu
66+
67+
config PERIPHERAL_MOUNT_CREDS
68+
bool "Mount credentials under /creds directory"
69+
help
70+
Mount credentials located ${BUILD_DIR}/creds under /creds mountpoint in Zephyr.
71+
72+
choice BOOTLOADER
73+
default BOOTLOADER_MCUBOOT if SOC != "native"
74+
endchoice
75+
76+
source "share/sysbuild/Kconfig"

samples/custom_connect/prj.conf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
CONFIG_POUCH_GATEWAY=y
2+
3+
CONFIG_BT=y
4+
CONFIG_BT_CENTRAL=y
5+
CONFIG_BT_MAX_CONN=16
6+
CONFIG_BT_GATT_CLIENT=y
7+
CONFIG_BT_GATT_CACHING=n
8+
CONFIG_BT_GATT_AUTO_UPDATE_MTU=y
9+
CONFIG_BT_L2CAP_TX_MTU=247
10+
CONFIG_BT_BUF_ACL_TX_SIZE=251
11+
CONFIG_BT_BUF_ACL_RX_SIZE=251
12+
13+
CONFIG_COAP_INIT_ACK_TIMEOUT_MS=3000
14+
15+
CONFIG_LOG=y
16+
17+
# Settings subsystem
18+
CONFIG_FCB=y
19+
CONFIG_FLASH=y
20+
CONFIG_FLASH_MAP=y
21+
22+
CONFIG_SETTINGS=y
23+
CONFIG_SETTINGS_FCB=y
24+
25+
# Application
26+
CONFIG_GOLIOTH_SAMPLE_COMMON=y
27+
CONFIG_GOLIOTH_SAMPLE_SETTINGS_SHELL=y
28+
29+
# Golioth Firmware SDK with all dependencies
30+
CONFIG_GOLIOTH_FIRMWARE_SDK=y
31+
CONFIG_GOLIOTH_GATEWAY=y
32+
33+
# Golioth logging backend
34+
CONFIG_LOG_MODE_DEFERRED=y
35+
CONFIG_LOG_BACKEND_GOLIOTH=y
36+
37+
# Application
38+
CONFIG_MAIN_STACK_SIZE=2048
39+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
40+
41+
# Pouch BLE GATT Transport
42+
CONFIG_POUCH_TRANSPORT_BLE_GATT_COMMON=y
43+
44+
CONFIG_ZVFS_EVENTFD_MAX=11

samples/custom_connect/sample.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sample:
2+
name: Pouch Gateway with custom connect
3+
tests:
4+
bluetooth-gateway.sample.custom_connect:
5+
tags: bluetooth
6+
harness: pytest
7+
harness_config:
8+
pytest_dut_scope: module
9+
sysbuild: true
10+
platform_allow:
11+
- nrf52_bsim
12+
integration_platforms:
13+
- nrf52_bsim
14+
extra_args:
15+
- SB_CONFIG_PERIPHERAL_MOUNT_CREDS=y
16+
- peripheral_ble_gatt_example_0_CONFIG_PICOLIBC=y
17+
- peripheral_ble_gatt_example_0_CONFIG_FILE_SYSTEM_NSIM_MOUNT=y
18+
- peripheral_ble_gatt_example_0_CONFIG_EXAMPLE_SYNC_PERIOD_S=2
19+
timeout: 120
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Use offloaded sockets using host BSD sockets
2+
CONFIG_ETH_DRIVER=n
3+
CONFIG_ETH_NATIVE_POSIX=n
4+
CONFIG_NET_DRIVERS=y
5+
CONFIG_NET_SOCKETS=y
6+
CONFIG_NET_SOCKETS_OFFLOAD=y
7+
CONFIG_NET_NATIVE_OFFLOADED_SOCKETS=y
8+
CONFIG_HEAP_MEM_POOL_SIZE=1024
9+
10+
# Use embedded libc to use Zephyr's eventfd instead of host eventfd
11+
CONFIG_PICOLIBC=y
12+
13+
# Static networking
14+
CONFIG_NET_CONFIG_LOG_LEVEL_DBG=y
15+
CONFIG_NET_CONFIG_SETTINGS=y
16+
CONFIG_NET_CONFIG_NEED_IPV4=y
17+
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
18+
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
19+
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Use offloaded sockets using host BSD sockets
2+
CONFIG_ETH_DRIVER=n
3+
CONFIG_ETH_NATIVE_POSIX=n
4+
CONFIG_NET_DRIVERS=y
5+
CONFIG_NET_SOCKETS=y
6+
CONFIG_NET_SOCKETS_OFFLOAD=y
7+
CONFIG_NET_NATIVE_OFFLOADED_SOCKETS=y
8+
CONFIG_HEAP_MEM_POOL_SIZE=1024
9+
10+
# Use embedded libc to use Zephyr's eventfd instead of host eventfd
11+
CONFIG_PICOLIBC=y
12+
13+
# Static networking
14+
CONFIG_NET_CONFIG_LOG_LEVEL_DBG=y
15+
CONFIG_NET_CONFIG_SETTINGS=y
16+
CONFIG_NET_CONFIG_NEED_IPV4=y
17+
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
18+
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
19+
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2025 Golioth, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# General config
5+
CONFIG_HEAP_MEM_POOL_SIZE=65536
6+
CONFIG_NEWLIB_LIBC=y
7+
8+
# Networking
9+
CONFIG_NET_SOCKETS_OFFLOAD=y
10+
CONFIG_NET_IPV6=y
11+
CONFIG_NET_IPV6_NBR_CACHE=n
12+
CONFIG_NET_IPV6_MLD=n
13+
14+
# Increase native TLS socket implementation, so that it is chosen instead of
15+
# offloaded nRF91 sockets
16+
CONFIG_NET_SOCKETS_TLS_PRIORITY=35
17+
18+
# Modem library
19+
CONFIG_NRF_MODEM_LIB=y
20+
21+
# LTE connectivity with network connection manager
22+
CONFIG_NRF_MODEM_LIB_NET_IF=y
23+
CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_START=y
24+
CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_CONNECT=n
25+
CONFIG_NET_CONNECTION_MANAGER=y
26+
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024
27+
28+
# Add Logs for LTE Link Handler
29+
CONFIG_GOLIOTH_SAMPLE_NRF91_LTE_MONITOR=y
30+
31+
# Disable options y-selected by NCS for no good reason
32+
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED=n
33+
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=n
34+
CONFIG_MBEDTLS_PK_PARSE_EC_EXTENDED=n
35+
36+
# MbedTLS configuration to support p-384 curve. These options
37+
# enable using the MbedTLS built-in support for operations not
38+
# supported by the default nRF Oberon crypto backend
39+
CONFIG_NORDIC_SECURITY_BACKEND=n
40+
CONFIG_MBEDTLS_LEGACY_CRYPTO_C=y
41+
42+
# Add Network Info Support
43+
CONFIG_MODEM_INFO=y
44+
45+
# Generate MCUboot compatible images
46+
CONFIG_BOOTLOADER_MCUBOOT=y
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2025 Golioth, Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# General config
5+
CONFIG_HEAP_MEM_POOL_SIZE=65536
6+
CONFIG_NEWLIB_LIBC=y
7+
8+
# Networking
9+
CONFIG_NET_SOCKETS_OFFLOAD=y
10+
CONFIG_NET_IPV6=y
11+
CONFIG_NET_IPV6_NBR_CACHE=n
12+
CONFIG_NET_IPV6_MLD=n
13+
14+
# Increase native TLS socket implementation, so that it is chosen instead of
15+
# offloaded nRF91 sockets
16+
CONFIG_NET_SOCKETS_TLS_PRIORITY=35
17+
18+
# Modem library
19+
CONFIG_NRF_MODEM_LIB=y
20+
21+
# LTE connectivity with network connection manager
22+
CONFIG_NRF_MODEM_LIB_NET_IF=y
23+
CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_START=y
24+
CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_CONNECT=n
25+
CONFIG_NET_CONNECTION_MANAGER=y
26+
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024
27+
28+
# Add Logs for LTE Link Handler
29+
CONFIG_GOLIOTH_SAMPLE_NRF91_LTE_MONITOR=y
30+
31+
# Disable options y-selected by NCS for no good reason
32+
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED=n
33+
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=n
34+
CONFIG_MBEDTLS_PK_PARSE_EC_EXTENDED=n
35+
36+
# MbedTLS configuration to support p-384 curve. These options
37+
# enable using the MbedTLS built-in support for operations not
38+
# supported by the default nRF Oberon crypto backend
39+
CONFIG_NORDIC_SECURITY_BACKEND=n
40+
CONFIG_MBEDTLS_LEGACY_CRYPTO_C=y
41+
42+
# Add Network Info Support
43+
CONFIG_MODEM_INFO=y
44+
45+
# Generate MCUboot compatible images
46+
CONFIG_BOOTLOADER_MCUBOOT=y

0 commit comments

Comments
 (0)