立即警报服务

[English]

立即警报服务**(Immediate Alert Service, IAS)是蓝牙 SIG 定义的 GATT 服务,通过 **Alert Level 特性使已连接的对端可请求本机立即发出提示(例如查找外设时的声音或振动)。

Alert Level 为单字节,取值对应 无警报弱警报强警报,即 ESP_BLE_IAS_ALERT_LEVEL_NO_ALERTESP_BLE_IAS_ALERT_LEVEL_MILD_ALERTESP_BLE_IAS_ALERT_LEVEL_HIGH_ALERT``(分别为 ``0x000x010x02)。

在应用中使用本服务时,建议按以下步骤操作:

  1. 在 menuconfig 中启用 CONFIG_BLE_IAS

  2. 使用 esp_ble_conn_init() 初始化 BLE 连接管理器(若工程需要,请先完成默认事件循环等相关准备)。

  3. 在连接管理器完成初始化之后,调用 esp_ble_ias_init() 将 IAS 注册到 GATT 服务端;在常见示例流程中,请在 esp_ble_conn_start() 之前执行该注册。

  4. esp_ble_ias_init() 之后 再调用 esp_ble_ias_register_alert_cb(),以便先完成服务注册,再安装在对端写入合法 Alert Level 时触发的处理函数。

本服务暂无独立示例工程,初始化方式可参考其它 BLE 服务 示例。

API 参考

Header File

Functions

esp_err_t esp_ble_ias_register_alert_cb(esp_ble_ias_alert_cb_t cb, void *priv)

Register a callback for Alert Level writes.

参数
  • cb[in] Callback function; pass NULL to unregister.

  • priv[in] Opaque pointer passed to cb.

返回

  • ESP_OK on success

esp_err_t esp_ble_ias_get_alert_level(uint8_t *level)

Read the last Alert Level written by a GATT client.

参数

level[out] The pointer to store the Alert Level (default ESP_BLE_IAS_ALERT_LEVEL_NO_ALERT).

返回

  • ESP_OK on success

  • ESP_ERR_INVALID_ARG if level is NULL

esp_err_t esp_ble_ias_init(void)

Register the Immediate Alert Service (0x1802) with esp_ble_conn_mgr.

返回

  • ESP_OK on success

  • ESP_FAIL on failure from esp_ble_conn_add_svc()

Macros

BLE_IAS_UUID16

Primary service: Immediate Alert Service (16-bit UUID)

BLE_IAS_CHR_UUID16_ALERT_LEVEL

Alert Level characteristic (16-bit UUID)

ESP_BLE_IAS_ALERT_LEVEL_NO_ALERT

No alert

ESP_BLE_IAS_ALERT_LEVEL_MILD_ALERT

Mild alert

ESP_BLE_IAS_ALERT_LEVEL_HIGH_ALERT

High alert

Type Definitions

typedef void (*esp_ble_ias_alert_cb_t)(uint8_t alert_level, void *priv)

Callback invoked when a connected client writes the Alert Level characteristic with a valid value.

Param alert_level

[in] Value written by the client. One of ESP_BLE_IAS_ALERT_LEVEL_NO_ALERT, ESP_BLE_IAS_ALERT_LEVEL_MILD_ALERT, or ESP_BLE_IAS_ALERT_LEVEL_HIGH_ALERT.

Param priv

[in] User context registered with esp_ble_ias_register_alert_cb.