这是我的mac地址
C9:00:00:00:00:00
修改后发现mac地址不对,查看esp_base_Mac_addr_set的文档发现基本 MAC 必须是单播 MAC(第一个字节的最低有效位必须为零)。
请问有什么办法可以解决吗
在官方文档找到个esp_iface_mac_addr_set函数可以使用,但是需要esp-idf master环境下使用,arduino环境我更新到最新也用不了,安装了一天的esp-idf环境 结合官方列子可以用了,啥也不懂,不知道还要设置啥,反正这样子可以用了,给后面遇到这个问题的兄弟一个解决办法把
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include "nvs_flash.h"
#include "esp_mac.h"
#include "esp_bt.h"
#include "esp_gap_ble_api.h"
#include "esp_bt_main.h"
static uint8_t bleMac[6] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
// 0-30 前31组
uint8_t bleRaw[] = {0x02,0x01,0x06,0x17,0xFF,0x00,0x01,0xB5,0x00,0x02,0x25,0xEC,0xD7,0x44,0x00,0x00,0x01,0xAA,0x91,0x77,0x67,0xAF,0x01,0x10,0x00,0x00,0x00,0x03,0x03,0x3C,0xFE};
// 如果复制出来的raw超过31组 那么把它改为true并维护下面的数组
bool rawMoreThan31 = true;
// 31-end
uint8_t bleRaw32[] = {0x02,0x0A,0x00,0x1A,0x16,0x6B,0x74,0x09,0x74,0x6B,0x54,0x4B,0x1C,0xF0,0xF0,0x61,0xD8,0x42,0x3C,0x83,0x27,0x95,0x8F,0xD4,0xC2,0x13,0x20,0xA7,0xE7,0x01};
static esp_ble_adv_params_t ble_adv_params = {
.adv_int_min = 0x20,
.adv_int_max = 0x40,
.adv_type = ADV_TYPE_IND,
.own_addr_type = BLE_ADDR_TYPE_PUBLIC,
.channel_map = ADV_CHNL_ALL,
.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
};
void ble_ibeacon_init(void)
{
esp_bluedroid_init();
esp_bluedroid_enable();
}
void app_main(void)
{
ESP_ERROR_CHECK(nvs_flash_init());
//就是这个函数
esp_iface_mac_addr_set(bleMac,ESP_MAC_BT);
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
esp_bt_controller_init(&bt_cfg);
esp_bt_controller_enable(ESP_BT_MODE_BLE);
ble_ibeacon_init();
esp_ble_gap_start_advertising(&ble_adv_params);
// 简单粗暴直接底层api重新设置一下抓到的raw
esp_ble_gap_config_adv_data_raw(bleRaw, 31);
if (rawMoreThan31) {
esp_ble_gap_config_scan_rsp_data_raw(bleRaw32, sizeof(bleRaw32));
}
}