Last Updated on : 2024-11-20 08:51:48download
This topic describes the APIs used to implement device pairing over Bluetooth.
typedef struct {
CHAR_T name[DEVICE_NAME_LEN];
ty_bt_mode_t mode;
UCHAR_T link_num;
TY_BT_MSG_CB cb;
tuya_ble_data_buf_t adv;
tuya_ble_data_buf_t scan_rsp;
}ty_bt_param_t;
Functional specification
The Bluetooth initialization parameters.
Member description
| Member | Description |
|---|---|
| name | The name of the Bluetooth device. |
| mode | The Bluetooth communication roles: TY_BT_MODE_PERIPHERAL TY_BT_MODE_CENTRALTY_BT_MODE_MESH_PROVISIONERTY_BT_MODE_MESH_DEVICE |
| link_num | The maximum number of clients that can be connected to the network, defaulting to 1. |
| cb | The event and data callback. |
| adv | The advertising data. |
| scan_rsp | The scan response data. |
OPERATE_RET tuya_adapter_bt_port_init(ty_bt_param_t *p);
Functional description
Initializes the Bluetooth host. This API should allow multiple calls to it. For example, after you call tuya_adapter_bt_port_deinit to turn off Bluetooth, you can call tuya_adapter_bt_port_init again to initialize Bluetooth. This API is implemented by you.
Parameter description
| Parameter name | Description |
|---|---|
| p | For more information, see ty_bt_param_t. |
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_port_deinit(VOID);
Functional description
Disables Bluetooth initialization. This API is implemented by you. For Bluetooth gateways, you do not need to take care of this API.
Parameter description
None
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_gap_disconnect(VOID);
Functional description
Enables the Bluetooth device to act as a peripheral device and initiate a disconnection. This API is implemented by you. For Bluetooth gateways, you do not need to take care of this API.
Parameter description
None
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_send(BYTE_T *data, UINT8_T len);
Functional description
Transmits data over Bluetooth. This API is implemented by you.
Parameter description
| Parameter name | Description |
|---|---|
| data | Data |
| len | Data length. |
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_adv_reset(tuya_ble_data_buf_t *adv, tuya_ble_data_buf_t *scan_resp);
Functional description
Resets the Bluetooth advertising and the scan response. This API is implemented by you.
Parameter description
| Parameter name | Description |
|---|---|
| adv | The advertising data. |
| scan_resp | The scan response data. |
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_adv_start(VOID);
Functional description
Starts Bluetooth advertising. This API is implemented by you.
Parameter description
None
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_adv_stop(VOID);
Functional description
Stops Bluetooth advertising. This API is implemented by you.
Parameter description
None
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_get_rssi(SCHAR_T *rssi);
Functional description
Gets the Bluetooth signal strength. This API is implemented by you.
Parameter description
| Parameter name | Description |
|---|---|
| rssi | The pointer to the signal strength. |
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_scan_assign(INOUT ty_bt_scan_info_t *info);
Functional description
Scans for a specific Bluetooth device and gets its Bluetooth information. This API is implemented by you. For Bluetooth gateways, you do not need to take care of this API.
Parameter description
| Parameter name | Description |
|---|---|
| info | The Bluetooth information. |
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_scan_init(IN TY_BT_SCAN_ADV_CB scan_adv_cb);
Functional description
Initializes Bluetooth scanning. This API is implemented by you. For Bluetooth gateways, you do not need to take care of this API.
Parameter description
| Parameter name | Description |
|---|---|
| scan_adv_cb | Bluetooth advertising callback. |
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_scan_start(VOID_T);
Functional description
Starts Bluetooth scanning. This API is implemented by you. For Bluetooth gateways, you do not need to take care of this API.
Parameter description
None
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
OPERATE_RET tuya_adapter_bt_scan_stop(VOID_T);
Functional description
Stops Bluetooth scanning. This API is implemented by you. For Bluetooth gateways, you do not need to take care of this API.
Parameter description
None
Return value
| Return value | Description |
|---|---|
| OPRT_OK | Success |
| Error code | The error code on a failed operation. |
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback