14 #include <esp_bt_defs.h> 15 #include <esp_gap_ble_api.h> 16 #include <esp_gattc_api.h> 18 #include <freertos/FreeRTOS.h> 19 #include <freertos/semphr.h> 25 namespace esp32_ble_tracker {
27 using namespace esp32_ble;
43 ESPBLEiBeacon() { memset(&this->beacon_data_, 0,
sizeof(this->beacon_data_)); }
56 uint8_t proximity_uuid[16];
65 void parse_scan_rst(
const esp_ble_gap_cb_param_t::ble_scan_result_evt_param ¶m);
67 std::string address_str()
const;
69 uint64_t address_uint64()
const;
71 const uint8_t *
address()
const {
return address_; }
75 const std::string &
get_name()
const {
return this->name_; }
87 const esp_ble_gap_cb_param_t::ble_scan_result_evt_param &
get_scan_result()
const {
return scan_result_; }
89 bool resolve_irk(
const uint8_t *irk)
const;
92 for (
auto &it : this->manufacturer_datas_) {
101 void parse_adv_(
const esp_ble_gap_cb_param_t::ble_scan_result_evt_param ¶m);
103 esp_bd_addr_t address_{
106 esp_ble_addr_type_t address_type_{BLE_ADDR_TYPE_PUBLIC};
109 std::vector<int8_t> tx_powers_{};
112 std::vector<ESPBTUUID> service_uuids_{};
113 std::vector<ServiceData> manufacturer_datas_{};
114 std::vector<ServiceData> service_datas_{};
115 esp_ble_gap_cb_param_t::ble_scan_result_evt_param scan_result_{};
123 virtual bool parse_device(
const ESPBTDevice &device) = 0;
124 virtual bool parse_devices(esp_ble_gap_cb_param_t::ble_scan_result_evt_param *advertisements,
size_t count) {
171 virtual bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
172 esp_ble_gattc_cb_param_t *param) = 0;
173 virtual void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) = 0;
174 virtual void connect() = 0;
175 virtual void disconnect() = 0;
197 void setup()
override;
198 void dump_config()
override;
199 float get_setup_priority()
const override;
201 void loop()
override;
205 void recalculate_advertisement_parser_types();
207 void print_bt_device_info(
const ESPBTDevice &device);
212 void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
213 esp_ble_gattc_cb_param_t *param)
override;
214 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
override;
215 void ble_before_disabled_event_handler()
override;
220 void start_scan_(
bool first);
224 void gap_scan_result_(
const esp_ble_gap_cb_param_t::ble_scan_result_evt_param ¶m);
226 void gap_scan_set_param_complete_(
const esp_ble_gap_cb_param_t::ble_scan_param_cmpl_evt_param ¶m);
228 void gap_scan_start_complete_(
const esp_ble_gap_cb_param_t::ble_scan_start_cmpl_evt_param ¶m);
230 void gap_scan_stop_complete_(
const esp_ble_gap_cb_param_t::ble_scan_stop_cmpl_evt_param ¶m);
249 bool ble_was_disabled_{
true};
250 bool raw_advertisements_{
false};
251 bool parse_advertisements_{
false};
254 size_t scan_result_index_{0};
256 const static u_int8_t SCAN_RESULT_BUFFER_SIZE = 32;
258 const static u_int8_t SCAN_RESULT_BUFFER_SIZE = 16;
261 esp_bt_status_t scan_start_failed_{ESP_BT_STATUS_SUCCESS};
262 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
constexpr14 T byteswap(T n)
std::vector< uint64_t > already_discovered_
Vector of addresses that have already been printed in print_bt_device_info.
int8_t get_signal_power()
Implementation of SPI Controller mode.
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)
const std::string & get_name() const
void set_scan_interval(uint32_t scan_interval)
static ESPBTUUID from_raw_reversed(const uint8_t *data)
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