Code: Select all
esp_ble_gatts_create_attr_tab()
Code: Select all
esp_ble_gatts_start_service()
Code: Select all
static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
{
/* If event is register event, store the gatts_if for each profile */
if (event == ESP_GATTS_REG_EVT)
{
if (param->reg.status == ESP_GATT_OK)
{
printf("app id:%04d\n", param->reg.app_id);
heart_rate_profile_tab[PROFILE_APP_IDX].gatts_if = gatts_if;
}
else
{
ESP_LOGE(GATTS_TABLE_TAG, "reg app failed, app_id %04x, status %d",
param->reg.app_id,
param->reg.status);
return;
}
}
do
{
int idx;
for (idx = 0; idx < PROFILE_NUM; idx++)
{
/* ESP_GATT_IF_NONE, not specify a certain gatt_if, need to call every profile cb function */
if (gatts_if == ESP_GATT_IF_NONE || gatts_if == heart_rate_profile_tab[idx].gatts_if)
{
if (heart_rate_profile_tab[idx].gatts_cb)
{
heart_rate_profile_tab[idx].gatts_cb(event, gatts_if, param);
}
}
}
} while (0);
}