bt_gatt_server_console_init()

bt_gatt_server_console_init()

Description

This function initialises the GATT server console service, incorporating both TX and RX characteristics. It provides simple and secure communication between the script and external Bluetooth devices. It is advisable to position this service at either the beginning or the end of the GATT server configuration.

RX buffer is limited to 200 bytes.

After console service initialisation, the server must be started by using bt_gatt_server_start().

UUID

Reference

Permissions

Description

UUID

Reference

Permissions

Description

00000201-0000-1000-8000-00805F9B34FB

251

Write

Characteristic used for GATT client writes to server (script)

00000202-0000-1000-8000-00805F9B34FB

252

Read, notify (if enabled)

Characteristic used for GATT client reads from server (script)

Syntax

bt_gatt_server_console_init(subscription_type);

Parameters

Variable

Input

Variable

Input

subscription_type

Enables or disables subscription to the RX characteristic.

Available subscription types

Name

Value

Description

Name

Value

Description

GATT_CHRC_PROP_NONE

0x00

Disables subscriptions to RX characteristic.

GATT_CHRC_PROP_NOTIFY

0x10

Allows subscription to the RX characteristic to notify the GATT client when its value changes.

Returns

Return value

Return explanation

SCRIPT_OPERATION_SUCCESS

Successfully created the GATT console service.

SCRIPT_OPERATION_FAILED

Failed to create the GATT console service.

SCRIPT_NO_ACCESS

Bluetooth GATT server is not initialized.

SCRIPT_PARAM_INVALID

Invalid subscription type value.

Function call example

#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> #include <bluetooth> new gatt_rx_data[64]; forward public callback (event); public callback (event) { switch(event) { case BT_GATT_SERVER_RX: { new data_len = bt_gatt_server_receive(gatt_rx_data); if (gatt_rx_data[GATT_RX_HEADER_USER_REF_POS] == GATT_CONSOLE_REFERENCE) { gatt_console_rx(data_len); } } } return 0; } gatt_console_rx(msg_len) { /* Handle console rx code start */ /* Handle console rx code end */ } main() { bt_init(); bt_gatt_server_init(); bt_gatt_server_console_init(GATT_CHRC_PROP_NOTIFY); bt_gatt_server_start(); for(;;) { Delay(100); } }

Notes

Console messages are received in the BT_GATT_SERVER_RX callback with bt_gatt_server_read() function. Use UUID and/or user reference for identification.