bt_gatt_client_passkey_set()

bt_gatt_client_passkey_set()

Description

Sets passkey for connection pairing.

Syntax

bt_gatt_client_passkey_set(connection_id, passkey);

Parameters

Variable

Input

Variable

Input

connection_id

Connection id which was described in bt_gatt_client_connect function. Could be either 0 or 1.

passkey

A 6 digit passkey for pairing with desired connection.

Returns

Return value

Return explanation

SCRIPT_OPERATION_SUCCESS

Successfully set passkey for connection.

SCRIPT_OPERATION_FAILED

Failed to set passkey.

SCRIPT_NO_ACCESS

Bluetooth GATT client is not initialized.

Function call example

#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> #include <bluetooth> #define FIRST_CONNECTION 0 #define SECOND_CONNECTION 1 #define PAIR_PASSKEY 123456 main() { bt_init(); bt_gatt_client_init(); bt_gatt_client_passkey_set(SECOND_CONNECTION, PAIR_PASSKEY); for(;;) { Delay(100); } }

 

Debug example

This example initializes BLE, then initializes GATT Client module and sets passkey for a connection. Example uses debug_print function to print information log to Initialized peripheral.

#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> #include <bluetooth> #include <debug> #define RS232_SPEED 115200 #define WORD_LENGTH WORDLENGTH_8 #define STOP_BITS STOPBITS_1 #define PARITY PARITY_NONE #define FIRST_CONNECTION 0 #define SECOND_CONNECTION 1 #define PAIR_PASSKEY 123456 new return_code = SCRIPT_OPERATION_SUCCESS; main() { Init(RS232, RS232_SPEED, WORD_LENGTH, STOP_BITS, PARITY); debug_init(RS232); return_code = bt_init(); if (return_code != SCRIPT_OPERATION_SUCCESS) { // Handle failed bt_init here debug_print("bt_init failed\r\n"); } else { debug_print("bt_init succeeded\r\n"); } return_code = bt_gatt_client_init(); if (return_code != SCRIPT_OPERATION_SUCCESS) { // Handle failed bt_gatt_client_init here debug_print("bt_gatt_client_init failed\r\n"); } else { debug_print("bt_gatt_client_init succeeded\r\n"); } return_code = bt_gatt_client_passkey_set(SECOND_CONNECTION, PAIR_PASSKEY); if (return_code != SCRIPT_OPERATION_SUCCESS) { // Handle failed bt_gatt_client_passkey_set here debug_print("bt_gatt_client_passkey_set failed\r\n"); } else { debug_print("bt_gatt_client_passkey_set succeeded\r\n"); } for(;;) { Delay(1000); } }

 

Notes and Warnings

It is advised to send passkey before making a connection because some GATT servers might initiate pairing procedure upon connection.