13 #include <esp_gap_ble_api.h> 14 #include <esp_gattc_api.h> 15 #include <esp_bt_defs.h> 17 #include <freertos/FreeRTOS.h> 18 #include <freertos/semphr.h> 24 namespace esp32_ble_tracker {
26 using namespace esp32_ble;
42 ESPBLEiBeacon() { memset(&this->beacon_data_, 0,
sizeof(this->beacon_data_)); }
46 uint16_t
get_major() {
return ((this->beacon_data_.major & 0xFF) << 8) | (this->beacon_data_.major >> 8); }
47 uint16_t
get_minor() {
return ((this->beacon_data_.minor & 0xFF) << 8) | (this->beacon_data_.minor >> 8); }
55 uint8_t proximity_uuid[16];
64 void parse_scan_rst(
const esp_ble_gap_cb_param_t::ble_scan_result_evt_param ¶m);
66 std::string address_str()
const;
68 uint64_t address_uint64()
const;
70 const uint8_t *
address()
const {
return address_; }
74 const std::string &
get_name()
const {
return this->name_; }
86 const esp_ble_gap_cb_param_t::ble_scan_result_evt_param &
get_scan_result()
const {
return scan_result_; }
89 for (
auto &it : this->manufacturer_datas_) {
98 void parse_adv_(
const esp_ble_gap_cb_param_t::ble_scan_result_evt_param ¶m);
100 esp_bd_addr_t address_{
103 esp_ble_addr_type_t address_type_{BLE_ADDR_TYPE_PUBLIC};
106 std::vector<int8_t> tx_powers_{};
109 std::vector<ESPBTUUID> service_uuids_{};
110 std::vector<ServiceData> manufacturer_datas_{};
111 std::vector<ServiceData> service_datas_{};
112 esp_ble_gap_cb_param_t::ble_scan_result_evt_param scan_result_{};
120 virtual bool parse_device(
const ESPBTDevice &device) = 0;
121 virtual bool parse_devices(esp_ble_gap_cb_param_t::ble_scan_result_evt_param *advertisements,
size_t count) {
168 virtual bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
169 esp_ble_gattc_cb_param_t *param) = 0;
170 virtual void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) = 0;
171 virtual void connect() = 0;
189 void setup()
override;
190 void dump_config()
override;
191 float get_setup_priority()
const override;
193 void loop()
override;
197 void recalculate_advertisement_parser_types();
199 void print_bt_device_info(
const ESPBTDevice &device);
204 void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
205 esp_ble_gattc_cb_param_t *param)
override;
206 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
override;
210 void start_scan_(
bool first);
214 void gap_scan_result_(
const esp_ble_gap_cb_param_t::ble_scan_result_evt_param ¶m);
216 void gap_scan_set_param_complete_(
const esp_ble_gap_cb_param_t::ble_scan_param_cmpl_evt_param ¶m);
218 void gap_scan_start_complete_(
const esp_ble_gap_cb_param_t::ble_scan_start_cmpl_evt_param ¶m);
220 void gap_scan_stop_complete_(
const esp_ble_gap_cb_param_t::ble_scan_stop_cmpl_evt_param ¶m);
239 bool raw_advertisements_{
false};
240 bool parse_advertisements_{
false};
243 size_t scan_result_index_{0};
245 const static u_int8_t SCAN_RESULT_BUFFER_SIZE = 32;
247 const static u_int8_t SCAN_RESULT_BUFFER_SIZE = 16;
248 #endif // CONFIG_SPIRAM 250 esp_bt_status_t scan_start_failed_{ESP_BT_STATUS_SUCCESS};
251 esp_bt_status_t scan_set_param_failed_{ESP_BT_STATUS_SUCCESS};
optional< ESPBLEiBeacon > get_ibeacon() const
struct esphome::sen5x::Sen5xBaselines PACKED
void set_scan_active(bool scan_active)
virtual void on_scan_end()
const std::vector< int8_t > & get_tx_powers() const
const optional< uint16_t > & get_appearance() const
const std::vector< ServiceData > & get_manufacturer_datas() const
const std::vector< ESPBTUUID > & get_service_uuids() const
esp_ble_scan_params_t scan_params_
A structure holding the ESP BLE scan parameters.
SemaphoreHandle_t scan_end_lock_
ESP32BLETracker * global_esp32_ble_tracker
virtual void set_state(ClientState st)
void set_parent(ESP32BLETracker *parent)
ClientState state() const
esp_ble_gap_cb_param_t::ble_scan_result_evt_param * scan_result_buffer_
const std::vector< ServiceData > & get_service_datas() const
esp_ble_addr_type_t get_address_type() const
const esp_ble_gap_cb_param_t::ble_scan_result_evt_param & get_scan_result() const
virtual AdvertisementParserType get_advertisement_parser_type()
const uint8_t * address() const
uint8_t scan_start_fail_count_
SemaphoreHandle_t scan_result_lock_
uint32_t scan_duration_
The interval in seconds to perform scans.
std::vector< uint8_t > adv_data_t
std::vector< uint64_t > already_discovered_
Vector of addresses that have already been printed in print_bt_device_info.
int8_t get_signal_power()
virtual bool parse_devices(esp_ble_gap_cb_param_t::ble_scan_result_evt_param *advertisements, size_t count)
void set_scan_duration(uint32_t scan_duration)
static ESPBTUUID from_raw(const uint8_t *data)
const std::string & get_name() const
void set_scan_interval(uint32_t scan_interval)
void set_scan_window(uint32_t scan_window)
static optional< ESPBLEiBeacon > from_manufacturer_data(const ServiceData &data)
void set_scan_continuous(bool scan_continuous)
std::vector< ESPBTDeviceListener * > listeners_
std::vector< ESPBTClient * > clients_
Client parameters.
Helper class to easily give an object a parent of type T.
const optional< uint8_t > & get_ad_flag() const