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

how to change static key password

In my application,the end product is given to the user with a static passkey. We need to give the user the provision to change the passkey .currently i run the code of static passkey with default passkey set as "123456" but i want to change static passkey after bonding .

As per i have to change the value of  default passkey set so i am able to receive six digit value from write value command and able to write the variable in SpiFlash memory and when i have to read the variable from Spi flash memory  i have been read the variable  in gap_params_init,but when i run the code the system get hangs only reset button is working other PushButton which are running on  my code before  get hangs.

Below is my small code function where i read the variable from spiflash memory and put the variable (passkey) in  sd_ble_opt_set  function.

In another trial method i have used  sd_ble_opt_set function on my write value command function when i run my code it gives Fatal error .Can you guide how i can change the static key password after 1st  bonding.

/

**@brief Function for the GAP initialization.
*
* @details This function sets up all the necessary GAP (Generic Access Profile) parameters of the
* device including the device name, appearance, and the preferred connection parameters.
*/

static void gap_params_init(void)

{
ret_code_t err_code;
ble_gap_conn_params_t gap_conn_params;
ble_gap_conn_sec_mode_t sec_mode;

BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

err_code = sd_ble_gap_device_name_set(&sec_mode,
(const uint8_t *)DEVICE_NAME,
strlen(DEVICE_NAME));
APP_ERROR_CHECK(err_code);

memset(&gap_conn_params, 0, sizeof(gap_conn_params));

gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
gap_conn_params.slave_latency = SLAVE_LATENCY;
gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT;

err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
APP_ERROR_CHECK(err_code);

//=======================================

W25qxx_ReadPage(passkey1,8144,0,4); // 
m_static_pin_option.gap_opt.passkey.p_passkey = passkey;
err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &m_static_pin_option);
APP_ERROR_CHECK(err_code);

}


  • Hello,

    Please try to debug the application to find out what the error code sd_ble_opt_set() is returning.

    In another trial method i have used  sd_ble_opt_set function on my write value command function when i run my code it gives Fatal error .Can you guide how i can change the static key password after 1st  bonding.

     It's likely returning NRF_ERROR_INVALID_STATE. You should only set the static passkey once on startup.

    Note: if you use Segger embedded studio, make sure to select the "Debug" configuration. This will make the program produce a more detailed crash log.

    ...

  • Hello sir,

                 I am set the static passkey  only at once and  When i debug the code the following issue is occurring :

                 <error> app: ERROR 7 [NRF_ERROR_INVALID_PARAM] at ..\..\..\main.c:708

                  PC at: 0x0002CBC1

                  <error> app: End of error report

    since  in gap_params_init function  unable to read the flash memory it gives fatal error 7.

    Do you any example or suggestion how i change the static  passkey password.

                

       

  • Hello,

    What function are you calling at line 708 in main.c, is it the flash read function, or is it the sd_ble_opt_set() function? Also, I'm not familiar with this particular flash API, but looks like W25qxx_ReadPage() is only reading 4 bytes in your code, is that correct? The passkey must be 6 digits long according to the Bluetooth LE specification.

  • Hello sir,

                In line no  708 main.c  i have called sd_ble_opt_set() function .The spiflash here is i am using is W25q16 flash for storing the data.In w25qxx_ReadPage () i have changed  size from  4 bytes to 6 bytes the  same problem occur .Igap_params_init function unable to read the flash memory variable.My question how i can change the static key password by using gap_params_init  function as i call sd_ble_opt_set() function in another function it gives fatal error as ERROR 7 .

  • Hello,

    Have you verified that 6 bytes you read from flash correspond to a valid passkey? It shall be ASCII encoded and only have have digits between 0 and 9.

     

Related