esp-idf 版本 5.1
esp32c6的例程ESP_SPP_SERVER,在修改设备名称时,发现修改之后没有变化。
需要修改的地方如下:
- SAMPLE_DEVICE_NAME
#define SPP_PROFILE_NUM 1 #define SPP_PROFILE_APP_IDX 0 #define ESP_SPP_APP_ID 0x56 #define SAMPLE_DEVICE_NAME "ESP_SPP_SER" //The Device Name Characteristics in GAP #define SPP_SVC_INST_ID 0
-
spp_adv_data
static const uint8_t spp_adv_data[20] = { /* Flags */ 0x02,0x01,0x06, /* Complete List of 16-bit Service Class UUIDs */ 0x03,0x03,0xF0,0xAB, /* Complete Local Name in advertising */ 0x0C,0x09, 'E', 'S', 'P', '_', 'S', 'P', 'P', '_', 'S', 'E', 'R' };
esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len) This function is called to set raw advertising data. User need to fill ADV data by self. 参数 raw_data – [in] : raw advertising data with the format: [Length 1][Data Type 1][Data 1][Length 2][Data Type 2][Data 2] … raw_data_len – [in] : raw advertising data length , less than 31 bytes 返回 ESP_OK : success other : failed
如官方手册所描述,spp_adv_data 的每一行数据由三部分组成,[Length 1][Data Type 1][Data 1][Length 2][Data Type 2][Data 2] ....,即第一个字节为长度,第二个是类型,剩下的是数据,在改变name的同事,这一行的长度也是需要修改的,长度是name字节的长度加1(一个字节的类型)。此处不修改是不能成功的。注意总长度不能超过31.
-
spp_mtu_size
static uint16_t spp_mtu_size = 20;
将spp_mtu_size的长度改为spp_adv_data的长度即可。