ESPHome  2022.6.2
esp32_ble_beacon.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #ifdef USE_ESP32
6 
7 #include <esp_gap_ble_api.h>
8 
9 namespace esphome {
10 namespace esp32_ble_beacon {
11 
12 // NOLINTNEXTLINE(modernize-use-using)
13 typedef struct {
14  uint8_t flags[3];
15  uint8_t length;
16  uint8_t type;
17  uint16_t company_id;
18  uint16_t beacon_type;
19 } __attribute__((packed)) esp_ble_ibeacon_head_t;
20 
21 // NOLINTNEXTLINE(modernize-use-using)
22 typedef struct {
23  uint8_t proximity_uuid[16];
24  uint16_t major;
25  uint16_t minor;
26  uint8_t measured_power;
27 } __attribute__((packed)) esp_ble_ibeacon_vendor_t;
28 
29 // NOLINTNEXTLINE(modernize-use-using)
30 typedef struct {
31  esp_ble_ibeacon_head_t ibeacon_head;
32  esp_ble_ibeacon_vendor_t ibeacon_vendor;
33 } __attribute__((packed)) esp_ble_ibeacon_t;
34 
35 class ESP32BLEBeacon : public Component {
36  public:
37  explicit ESP32BLEBeacon(const std::array<uint8_t, 16> &uuid) : uuid_(uuid) {}
38 
39  void setup() override;
40  void dump_config() override;
41  float get_setup_priority() const override;
42 
43  void set_major(uint16_t major) { this->major_ = major; }
44  void set_minor(uint16_t minor) { this->minor_ = minor; }
45 
46  protected:
47  static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
48  static void ble_core_task(void *params);
49  static void ble_setup();
50 
51  std::array<uint8_t, 16> uuid_;
52  uint16_t major_{};
53  uint16_t minor_{};
54 };
55 
56 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
58 
59 } // namespace esp32_ble_beacon
60 } // namespace esphome
61 
62 #endif
ESP32BLEBeacon(const std::array< uint8_t, 16 > &uuid)
uint8_t flags
Definition: bedjet_base.h:134
ESP32BLEBeacon * global_esp32_ble_beacon
enum esphome::EntityCategory __attribute__
Definition: a4988.cpp:4
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)