mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
examples/bluetooth: Miscellaneous fixes in some of the examples
This closes: https://github.com/espressif/esp-idf/issues/2617 https://github.com/espressif/esp-idf/issues/2622 Signed-off-by: Hrishikesh Dhayagude <hrishi@espressif.com>
This commit is contained in:
parent
f55509bd3f
commit
55dfb79e91
@ -7,20 +7,17 @@
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* The demo shows BLE and classic Bluetooth coexistence. You can use BLE gatt server and classic bluetooth A2DP together.
|
||||
|
||||
* The BLE GATT SERVER part of demo creates GATT a service and then starts advertising, waiting to be connected by a GATT client.
|
||||
* After the program is started, the GATT client can discover a device named "ESP_COEX_BLE_DEMO". Once a connection is established,
|
||||
* GATT client can reaad or write data to the device. Or GATT client receive notification or indication data.
|
||||
* Attention: IF you test the demo with iphone, BLE gatt server adv name will change to "ESP_COEX_A2DP_DEMO" afte you connect it.
|
||||
|
||||
* The classic bluetooth A2DP part of the demo of API implementing Advanced Audio Distribution Profile to receive an audio stream.
|
||||
* After the program is started, other bluetooth devices such as smart phones can discover a device named "ESP_COEX_A2DP_DEMO".
|
||||
* Once a connection is established, audio data can be transmitted. This will be visible in the application log including a count
|
||||
* The demo shows BLE and classic Bluetooth coexistence. You can use BLE GATT server and classic bluetooth A2DP together.
|
||||
* The BLE GATT server part of the demo creates a GATT service and then starts advertising, waiting to be connected by a GATT client.
|
||||
* After the program is started, a GATT client can discover the device named "ESP_COEX_BLE_DEMO". Once the connection is established,
|
||||
* GATT client can read or write data to the device. It can also receive notification or indication data.
|
||||
* Attention: If you test the demo with iPhone, BLE GATT server adv name will change to "ESP_COEX_A2DP_DEMO" after you connect it.
|
||||
* The classic bluetooth A2DP part of the demo implements Advanced Audio Distribution Profile to receive an audio stream.
|
||||
* After the program is started, other bluetooth devices such as smart phones can discover the device named "ESP_COEX_A2DP_DEMO".
|
||||
* Once the connection is established, audio data can be transmitted. This will be visible in the application log including a count
|
||||
* of audio data packets.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@ -182,7 +179,7 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
}
|
||||
break;
|
||||
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
|
||||
ESP_LOGI(BT_BLE_COEX_TAG, "update connetion params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
|
||||
ESP_LOGI(BT_BLE_COEX_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
|
||||
param->update_conn_params.status,
|
||||
param->update_conn_params.min_int,
|
||||
param->update_conn_params.max_int,
|
||||
|
@ -6,14 +6,9 @@
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* This file is for gatt client. It can scan ble device, connect one device.
|
||||
* Run the gatt_server demo, the client demo will automatically connect to the gatt_server demo.
|
||||
* Client demo will enable gatt_server's notify after connection. Then the two devices will exchange
|
||||
* data.
|
||||
* This is the demo to test the BLE throughput. It should be used together with throughput_server demo.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@ -65,7 +60,7 @@ uint8_t write_data[GATTC_WRITE_LEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
|
||||
static bool is_connecet = false;
|
||||
|
||||
/* eclare static functions */
|
||||
/* Declare static functions */
|
||||
static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
|
||||
static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
|
||||
static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
|
||||
@ -219,7 +214,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_char_by_uuid error");
|
||||
}
|
||||
|
||||
/* Every service have only one char in our 'ESP_GATTS_DEMO' demo, so we used first 'char_elem_result' */
|
||||
/* Every service has only one char in our 'throughput_server' demo, so we use first 'char_elem_result' */
|
||||
if (count > 0 && (char_elem_result[0].properties & ESP_GATT_CHAR_PROP_BIT_NOTIFY)){
|
||||
gl_profile_tab[PROFILE_A_APP_ID].char_handle = char_elem_result[0].char_handle;
|
||||
esp_ble_gattc_register_for_notify (gattc_if, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, char_elem_result[0].char_handle);
|
||||
@ -264,7 +259,7 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
||||
ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_descr_by_char_handle error");
|
||||
}
|
||||
|
||||
/* Erery char have only one descriptor in our 'ESP_GATTS_DEMO' demo, so we used first 'descr_elem_result' */
|
||||
/* Every char has only one descriptor in our 'throughput_server' demo, so we use first 'descr_elem_result' */
|
||||
if (count > 0 && descr_elem_result[0].uuid.len == ESP_UUID_LEN_16 && descr_elem_result[0].uuid.uuid.uuid16 == ESP_GATT_UUID_CHAR_CLIENT_CONFIG){
|
||||
ret_status = esp_ble_gattc_write_char_descr( gattc_if,
|
||||
gl_profile_tab[PROFILE_A_APP_ID].conn_id,
|
||||
@ -429,7 +424,7 @@ static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *par
|
||||
ESP_LOGI(GATTC_TAG, "stop adv successfully");
|
||||
break;
|
||||
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
|
||||
ESP_LOGI(GATTC_TAG, "update connetion params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
|
||||
ESP_LOGI(GATTC_TAG, "update connection params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
|
||||
param->update_conn_params.status,
|
||||
param->update_conn_params.min_int,
|
||||
param->update_conn_params.max_int,
|
||||
|
@ -6,6 +6,12 @@
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* This is the demo to test the BLE throughput. It should be used together with throughput_client demo.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -68,11 +74,10 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
|
||||
#define PREPARE_BUF_MAX_SIZE 1024
|
||||
|
||||
uint8_t char1_str[] = {0x11,0x22,0x33};
|
||||
esp_gatt_char_prop_t a_property = 0;
|
||||
esp_gatt_char_prop_t b_property = 0;
|
||||
static uint8_t char1_str[] = {0x11,0x22,0x33};
|
||||
static esp_gatt_char_prop_t a_property = 0;
|
||||
|
||||
esp_attr_value_t gatts_demo_char1_val =
|
||||
static esp_attr_value_t gatts_demo_char1_val =
|
||||
{
|
||||
.attr_max_len = GATTS_DEMO_CHAR_VAL_LEN_MAX,
|
||||
.attr_len = sizeof(char1_str),
|
||||
|
@ -10,9 +10,9 @@
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* This file is for gatt client. It can scan ble device, connect one device.
|
||||
* This demo showcases BLE GATT client. It can scan BLE devices and connect to one device.
|
||||
* Run the gatt_server demo, the client demo will automatically connect to the gatt_server demo.
|
||||
* Client demo will enable gatt_server's notify after connection. Then the two devices will exchange
|
||||
* Client demo will enable gatt_server's notify after connection. The two devices will then exchange
|
||||
* data.
|
||||
*
|
||||
****************************************************************************/
|
||||
@ -46,7 +46,7 @@ static bool get_server = false;
|
||||
static esp_gattc_char_elem_t *char_elem_result = NULL;
|
||||
static esp_gattc_descr_elem_t *descr_elem_result = NULL;
|
||||
|
||||
/* eclare static functions */
|
||||
/* Declare static functions */
|
||||
static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
|
||||
static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
|
||||
static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param);
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "esp_gatts_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "example_ble_sec_gatts_demo.h"
|
||||
|
||||
#define GATTS_TABLE_TAG "SEC_GATTS_DEMO"
|
||||
@ -36,16 +35,8 @@
|
||||
|
||||
static uint8_t adv_config_done = 0;
|
||||
|
||||
uint8_t heart_str[] = {0x11,0x22,0x33};
|
||||
static uint16_t heart_rate_handle_table[HRS_IDX_NB];
|
||||
|
||||
uint16_t heart_rate_handle_table[HRS_IDX_NB];
|
||||
|
||||
esp_attr_value_t gatts_demo_char1_val =
|
||||
{
|
||||
.attr_max_len = GATTS_DEMO_CHAR_VAL_LEN_MAX,
|
||||
.attr_len = sizeof(heart_str),
|
||||
.attr_value = heart_str,
|
||||
};
|
||||
static uint8_t test_manufacturer[3]={'E', 'S', 'P'};
|
||||
|
||||
static uint8_t sec_service_uuid[16] = {
|
||||
|
@ -8,9 +8,9 @@
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* This file is for gatt server. It can send adv data, be connected by client.
|
||||
* This demo showcases BLE GATT server. It can send adv data, be connected by client.
|
||||
* Run the gatt_client demo, the client demo will automatically connect to the gatt_server demo.
|
||||
* Client demo will enable gatt_server's notify after connection. Then two devices will exchange
|
||||
* Client demo will enable gatt_server's notify after connection. The two devices will then exchange
|
||||
* data.
|
||||
*
|
||||
****************************************************************************/
|
||||
@ -31,7 +31,6 @@
|
||||
#include "esp_gatts_api.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_bt_main.h"
|
||||
#include "esp_gatt_common_api.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
@ -59,11 +58,11 @@ static void gatts_profile_b_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
|
||||
|
||||
#define PREPARE_BUF_MAX_SIZE 1024
|
||||
|
||||
uint8_t char1_str[] = {0x11,0x22,0x33};
|
||||
esp_gatt_char_prop_t a_property = 0;
|
||||
esp_gatt_char_prop_t b_property = 0;
|
||||
static uint8_t char1_str[] = {0x11,0x22,0x33};
|
||||
static esp_gatt_char_prop_t a_property = 0;
|
||||
static esp_gatt_char_prop_t b_property = 0;
|
||||
|
||||
esp_attr_value_t gatts_demo_char1_val =
|
||||
static esp_attr_value_t gatts_demo_char1_val =
|
||||
{
|
||||
.attr_max_len = GATTS_DEMO_CHAR_VAL_LEN_MAX,
|
||||
.attr_len = sizeof(char1_str),
|
||||
@ -107,7 +106,7 @@ static esp_ble_adv_data_t adv_data = {
|
||||
.p_manufacturer_data = NULL, //&test_manufacturer[0],
|
||||
.service_data_len = 0,
|
||||
.p_service_data = NULL,
|
||||
.service_uuid_len = 32,
|
||||
.service_uuid_len = sizeof(adv_service_uuid128),
|
||||
.p_service_uuid = adv_service_uuid128,
|
||||
.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
|
||||
};
|
||||
@ -123,7 +122,7 @@ static esp_ble_adv_data_t scan_rsp_data = {
|
||||
.p_manufacturer_data = NULL, //&test_manufacturer[0],
|
||||
.service_data_len = 0,
|
||||
.p_service_data = NULL,
|
||||
.service_uuid_len = 32,
|
||||
.service_uuid_len = sizeof(adv_service_uuid128),
|
||||
.p_service_uuid = adv_service_uuid128,
|
||||
.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
|
||||
};
|
||||
@ -222,8 +221,7 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
|
||||
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
|
||||
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
|
||||
ESP_LOGE(GATTS_TAG, "Advertising stop failed\n");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ESP_LOGI(GATTS_TAG, "Stop adv successfully\n");
|
||||
}
|
||||
break;
|
||||
|
@ -8,9 +8,10 @@
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* This file is for gatt server. It can send adv data, be connected by client.
|
||||
* 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_service_table's notify after connection. Then two devices will exchange
|
||||
* Client demo will enable GATT server's notify after connection. The two devices will then exchange
|
||||
* data.
|
||||
*
|
||||
****************************************************************************/
|
||||
@ -38,7 +39,7 @@
|
||||
#define SAMPLE_DEVICE_NAME "ESP_GATTS_DEMO"
|
||||
#define SVC_INST_ID 0
|
||||
|
||||
/* The max length of characteristic value. When the gatt client write or prepare write,
|
||||
/* The max length of characteristic value. When the GATT client performs a write or prepare write operation,
|
||||
* the data length must be less than GATTS_DEMO_CHAR_VAL_LEN_MAX.
|
||||
*/
|
||||
#define GATTS_DEMO_CHAR_VAL_LEN_MAX 500
|
||||
@ -116,7 +117,7 @@ static esp_ble_adv_data_t scan_rsp_data = {
|
||||
.p_manufacturer_data = NULL, //&test_manufacturer[0],
|
||||
.service_data_len = 0,
|
||||
.p_service_data = NULL,
|
||||
.service_uuid_len = 16,
|
||||
.service_uuid_len = sizeof(service_uuid),
|
||||
.p_service_uuid = service_uuid,
|
||||
.flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
|
||||
};
|
||||
@ -443,7 +444,7 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
|
||||
esp_log_buffer_hex(GATTS_TABLE_TAG, param->connect.remote_bda, 6);
|
||||
esp_ble_conn_update_params_t conn_params = {0};
|
||||
memcpy(conn_params.bda, param->connect.remote_bda, sizeof(esp_bd_addr_t));
|
||||
/* For the IOS system, please reference the apple official documents about the ble connection parameters restrictions. */
|
||||
/* For the iOS system, please refer to Apple official documents about the BLE connection parameters restrictions. */
|
||||
conn_params.latency = 0;
|
||||
conn_params.max_int = 0x20; // max_int = 0x20*1.25ms = 40ms
|
||||
conn_params.min_int = 0x10; // min_int = 0x10*1.25ms = 20ms
|
||||
|
Loading…
Reference in New Issue
Block a user