Skip to content

Commit

Permalink
Added Settings Subsys to keep pairing info
Browse files Browse the repository at this point in the history
Signed-off-by: Joao Dullius <[email protected]>
  • Loading branch information
joaodullius committed Jan 3, 2023
1 parent e67a8c0 commit 682a4e8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
8 changes: 8 additions & 0 deletions simple_service/central_simple_service/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ CONFIG_BT_GATT_DM=y
CONFIG_BT_TINYCRYPT_ECC=y
CONFIG_HEAP_MEM_POOL_SIZE=2048

#Enable to Save BLE Settings
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y

# This example requires more workqueue stack
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

Expand Down
11 changes: 8 additions & 3 deletions simple_service/central_simple_service/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <bluetooth/gatt_dm.h>
#include <bluetooth/scan.h>

#include <zephyr/settings/settings.h>

#include <zephyr/logging/log.h>

#define LOG_MODULE_NAME ble_scanner
Expand Down Expand Up @@ -162,12 +164,13 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,

if (!err) {
LOG_WRN("Security changed: %s level %u", addr, level);
gatt_discover(conn);
} else {
LOG_ERR("Security failed: %s level %u err %d", addr,
level, err);
}

gatt_discover(conn);

}

BT_CONN_CB_DEFINE(conn_callbacks) = {
Expand Down Expand Up @@ -288,8 +291,6 @@ static void auth_passkey_entry(struct bt_conn *conn)
{
char addr[BT_ADDR_LE_STR_LEN];

default_conn = bt_conn_ref(conn);

bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

// Check for passkey entry event
Expand Down Expand Up @@ -403,6 +404,10 @@ void main(void)

LOG_INF("Bluetooth initialized");

if (IS_ENABLED(CONFIG_SETTINGS)) {
settings_load();
}

simple_service_client_init();
scan_init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,9 @@ int bt_simple_service_set_led(struct bt_simple_service *simple_service_c, const

return err;

}

bool bt_hogp_assign_check(const struct bt_simple_service *simple_service_c)
{
return simple_service_c->conn != NULL;
}
10 changes: 9 additions & 1 deletion simple_service/peripheral_simple_service/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MAX_CONN=1
CONFIG_BT_MAX_PAIRED=1
CONFIG_BT_SMP_SC_ONLY=y
CONFIG_BT_TINYCRYPT_ECC=y
CONFIG_BT_TINYCRYPT_ECC=y

#Enable to Save BLE Settings
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
6 changes: 6 additions & 0 deletions simple_service/peripheral_simple_service/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/hci.h>

#include <zephyr/settings/settings.h>

static uint8_t button_value = 0;

static bool notify_enabled;
Expand Down Expand Up @@ -337,6 +339,10 @@ void main(void)
}
LOG_INF("Bluetooth initialized");

if (IS_ENABLED(CONFIG_SETTINGS)) {
settings_load();
}

err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd,
ARRAY_SIZE(sd));
if (err) {
Expand Down

0 comments on commit 682a4e8

Please sign in to comment.