bt_event_read()

bt_event_read()

Description

Retrieves the latest Bluetooth event and stores it into the provided variable. This function should be used after BT_EVENT_RECEIVED callback is triggered.

Syntax

bt_event_read(bt_event);

Parameters

Variable

Input

bt_event

The Bluetooth event will be stored in this variable

Bluetooth event table

Event value

Event definition name in script

Event description

Event value

Event definition name in script

Event description

1

BT_EVENT_RESET

Bluetooth chip reset occured.

2

BT_EVENT_STARTAPP

Bluetooth is ready to accept commands.

3-5

Reserved

-

6

BT_EVENT_WAKEUP

Bluetooth chip has woken up after sleep.

7

BT_EVENT_CENTRAL_DEV_CONNECTED

A central device has established connection with the device.

8

BT_EVENT_CENTRAL_DEV_CONN_FAIL

A central device failed to establish connection with the device.

9

BT_EVENT_CENTRAL_DEV_DISC

Central device disconnected. Common reasons include the other device ending the connection or moving out of range.

10

BT_EVENT_CENTRAL_DEV_PAIRED

Central device successully completed paired with the device.

11

BT_EVENT_CENTRAL_DEV_PAIR_FAIL

Central device failed to pair with the device. Common reasons include incorrect passkey, timeout.

12

BT_EVENT_PERIPH_DEV_CONNECTED

Established connection with the peripheral device.

13

BT_EVENT_PERIPH_DEV_CONN_FAIL

Failed to establish connection with the peripheral device.

14

BT_EVENT_PERIPH_DEV_DISC

Peripheral device disconnected. Common reasons include the other device ending the connection or moving out of range.

15

BT_EVENT_PERIPH_DEV_PAIRED

Completed pairing with the peripheral device.

16

BT_EVENT_PERIPH_DEV_PAIR_FAIL

Failed to pair with the peripheral device. Common reasons include incorrect passkey, timeout, or an incompatible pairing method.

In Bluetooth, a central device typically uses GATT client functionality, while a peripheral device uses GATT server functionality. When GATT multirole is enabled, both roles can use server and client features.

Returns

Return value

Return explanation

SCRIPT_OPERATION_SUCCESS

Successfully read the Bluetooth event.

SCRIPT_PARAM_INVALID

Invalid variable.

SCRIPT_NO_ACCESS

Bluetooth is not initialized.

Function call example

#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> #include <bluetooth> forward public callback(event); new bt_event = 0; public callback(event) { switch (event) { case BT_EVENT_RECEIVED: { bt_event_read(bt_event); } } return 0; } main() { bt_init(); /* Application specific BLE initialisation code start */ /* Application specific BLE initialisation code end */ for(;;) { if (bt_event == BT_EVENT_RESET) { /* BT reset code start */ /* BT reset code end */ } Delay(100); } }