This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

static passkey s132

Hi,

I've allready read a lot about using a static passkey on the DevZone and I have tried tons of things, but I just can't get it to work.

What I want is to connect to my BLE peripheral, a NRF52832 with the S132 softdefice from an Android phone (using the nRF Connect app). I want to make sure that some services and characteristics can only be read or written when a password is entered.

In the most ideal way that would mean that in order to connect the user has to enter a predefined passkey (i.e. 123456). Only if the passkey is correct the user should be able to connect to the device.

I found that the term 'connect' is quite vague in BLE as there are 3 types, namely connecting, pairing and bonding. I don't know at what stage the user should enter a password but I'm guessing it is at bonding stage.

I tried to set a static passkey in the softdevice using this code:

// Set the static passkey for pairing
static_pin_option.gap_opt.passkey.p_passkey = static_passkey;
err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &static_pin_option);
APP_ERROR_CHECK(err_code);

Here the static_passkey is defined globally:

static uint8_t static_passkey[] = STATIC_PASSKEY;

where STATIC_PASSKEY is:

#define STATIC_PASSKEY					"123456"

This does not work as my Android phone can connect and bond to the device without entering the password, it is never prompted.

Can someone please help me out with this, I dont know what is the right way to go. Thanks :)

Related