我正在使用 ESP-idf 对我的 ESP32 板进行编程。我的目标是让它扫描特定的 BLE(低功耗蓝牙)设备。我想出了如何通过使用“Espressif”提供的名为“ibeacon_demo.c”的示例之一进行扫描,事情是我不知道如何提取任何搜索到的设备的地址并将其作为字符串所以我可以将它与我的 BLE 设备地址进行比较。
ibeacon_demo.c: https ://github.com/pycom/pycom-esp-idf/blob/master/examples/bluetooth/ble_ibeacon/main/ibeacon_demo.c
我很确定在此声明中必须做一些事情:
if (esp_ble_is_ibeacon_packet(scan_result->scan_rst.ble_adv, scan_result->scan_rst.adv_data_len)){
esp_ble_ibeacon_t *ibeacon_data = (esp_ble_ibeacon_t*)(scan_result->scan_rst.ble_adv);
ESP_LOGI(DEMO_TAG, "----------iBeacon Found----------");
esp_log_buffer_hex("IBEACON_DEMO: Device address:", scan_result->scan_rst.bda, BD_ADDR_LEN );
esp_log_buffer_hex("IBEACON_DEMO: Proximity UUID:", ibeacon_data->ibeacon_vendor.proximity_uuid, ESP_UUID_LEN_128);
uint16_t major = ENDIAN_CHANGE_U16(ibeacon_data->ibeacon_vendor.major);
uint16_t minor = ENDIAN_CHANGE_U16(ibeacon_data->ibeacon_vendor.minor);
ESP_LOGI(DEMO_TAG, "Major: 0x%04x (%d)", major, major);
ESP_LOGI(DEMO_TAG, "Minor: 0x%04x (%d)", minor, minor);
ESP_LOGI(DEMO_TAG, "Measured power (RSSI at a 1m distance):%d dbm", ibeacon_data->ibeacon_vendor.measured_power);
ESP_LOGI(DEMO_TAG, "RSSI of packet:%d dbm", scan_result->scan_rst.rssi);
}
这是我使用“ibeacon_demo.c”的示例的 API 参考 [ https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/bluetooth/esp_gap_ble.html#_CPPv428esp_ble_gap_update_whitelistb13esp_bd_addr_t22esp_ble_wl_addr_type_t][1 ]