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 |
| The Bluetooth event will be stored in this variable |
Bluetooth event table
Event value | Event definition name in script | Event description |
|---|---|---|
1 |
| Bluetooth chip reset occured. |
2 |
| Bluetooth is ready to accept commands. |
3-5 | Reserved | - |
6 |
| Bluetooth chip has woken up after sleep. |
7 |
| A central device has established connection with the device. |
8 |
| A central device failed to establish connection with the device. |
9 |
| Central device disconnected. Common reasons include the other device ending the connection or moving out of range. |
10 |
| Central device successully completed paired with the device. |
11 |
| Central device failed to pair with the device. Common reasons include incorrect passkey, timeout. |
12 |
| Established connection with the peripheral device. |
13 |
| Failed to establish connection with the peripheral device. |
14 |
| Peripheral device disconnected. Common reasons include the other device ending the connection or moving out of range. |
15 |
| Completed pairing with the peripheral device. |
16 |
| 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);
}
}