Browse Source

主动上报完成

master
zwsd 3 years ago
parent
commit
c78f71985b
  1. 11
      main/ble_gatts_table.c
  2. 2
      main/ble_gatts_table.h
  3. 33
      main/gatts_table_creat_demo.c

11
main/ble_gatts_table.c

@ -1,6 +1,8 @@
#include "ble_gatts_table.h" #include "ble_gatts_table.h"
static uint16_t *hid_conn_id; static uint16_t *hid_conn_id;
static esp_gatt_if_t *hid_gatts_if;
static uint16_t *hid_handle;
static uint8_t adv_config_done = 0; static uint8_t adv_config_done = 0;
@ -354,6 +356,10 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
{ {
ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret); ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
} }
else
{
*hid_gatts_if = gatts_if;
}
} }
break; break;
case ESP_GATTS_READ_EVT: case ESP_GATTS_READ_EVT:
@ -441,6 +447,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
// start sent the update connection parameters to the peer device. // start sent the update connection parameters to the peer device.
esp_ble_gap_update_conn_params(&conn_params); esp_ble_gap_update_conn_params(&conn_params);
*hid_conn_id = param->connect.conn_id; *hid_conn_id = param->connect.conn_id;
*hid_handle = heart_rate_handle_table[IDX_CHAR_VAL_A];
// *hid_conn_id = 100; // *hid_conn_id = 100;
break; break;
case ESP_GATTS_DISCONNECT_EVT: case ESP_GATTS_DISCONNECT_EVT:
@ -515,11 +522,13 @@ static void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_
} while (0); } while (0);
} }
void ble_init(uint16_t *conn_id_ble)
void ble_init(uint16_t *conn_id_ble, esp_gatt_if_t *gatts_if_ble, uint16_t *handle_ble)
{ {
esp_err_t ret; esp_err_t ret;
hid_conn_id = conn_id_ble; hid_conn_id = conn_id_ble;
hid_gatts_if = gatts_if_ble;
hid_handle = handle_ble;
/* Initialize NVS. */ /* Initialize NVS. */
ret = nvs_flash_init(); ret = nvs_flash_init();

2
main/ble_gatts_table.h

@ -54,4 +54,4 @@ struct gatts_profile_inst
esp_bt_uuid_t descr_uuid; esp_bt_uuid_t descr_uuid;
}; };
void ble_init(uint16_t *conn_id_ble);
void ble_init(uint16_t *conn_id_ble, esp_gatt_if_t *gatts_if_ble, uint16_t *handle_ble);

33
main/gatts_table_creat_demo.c

@ -7,22 +7,31 @@
*/ */
/**************************************************************************** /****************************************************************************
*
* This demo showcases creating a GATT database using a predefined attribute table.
* It acts as a GATT server and can send adv data, be connected by client.
* Run the gatt_client demo, the client demo will automatically connect to the gatt_server_service_table demo.
* Client demo will enable GATT server's notify after connection. The two devices will then exchange
* data.
*
****************************************************************************/
*
* This demo showcases creating a GATT database using a predefined attribute table.
* It acts as a GATT server and can send adv data, be connected by client.
* Run the gatt_client demo, the client demo will automatically connect to the gatt_server_service_table demo.
* Client demo will enable GATT server's notify after connection. The two devices will then exchange
* data.
*
****************************************************************************/
#include "ble_gatts_table.h" #include "ble_gatts_table.h"
uint16_t table_conn_id_m; uint16_t table_conn_id_m;
esp_gatt_if_t table_gatts_if_m;
uint16_t table_handle_m;
void app_main(void){
ble_init(&table_conn_id_m);
void app_main(void)
{
uint8_t temp[5] = {68, 69, 70, 71, 72};
ble_init(&table_conn_id_m, &table_gatts_if_m, &table_handle_m);
while(true){
ESP_LOGI("test","%d",table_conn_id_m);
while (true)
{
// ESP_LOGI("test", "%d,%d,%d", table_conn_id_m, table_gatts_if_m, table_handle_m);
if (table_handle_m != 0)
{
esp_ble_gatts_send_indicate(table_gatts_if_m, table_conn_id_m, table_handle_m, 5, temp, false);
}
} }
} }
Loading…
Cancel
Save