ESPHome  2024.4.0
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 #include <esp_bt.h>
9 
10 namespace esphome {
11 namespace esp32_ble_beacon {
12 
13 // NOLINTNEXTLINE(modernize-use-using)
14 typedef struct {
15  uint8_t flags[3];
16  uint8_t length;
17  uint8_t type;
18  uint8_t company_id[2];
19  uint8_t beacon_type[2];
20 } __attribute__((packed)) esp_ble_ibeacon_head_t;
21 
22 // NOLINTNEXTLINE(modernize-use-using)
23 typedef struct {
24  uint8_t proximity_uuid[16];
25  uint16_t major;
26  uint16_t minor;
27  uint8_t measured_power;
28 } __attribute__((packed)) esp_ble_ibeacon_vendor_t;
29 
30 // NOLINTNEXTLINE(modernize-use-using)
31 typedef struct {
32  esp_ble_ibeacon_head_t ibeacon_head;
33  esp_ble_ibeacon_vendor_t ibeacon_vendor;
34 } __attribute__((packed)) esp_ble_ibeacon_t;
35 
36 class ESP32BLEBeacon : public Component {
37  public:
38  explicit ESP32BLEBeacon(const std::array<uint8_t, 16> &uuid) : uuid_(uuid) {}
39 
40  void setup() override;
41  void dump_config() override;
42  float get_setup_priority() const override;
43 
44  void set_major(uint16_t major) { this->major_ = major; }
45  void set_minor(uint16_t minor) { this->minor_ = minor; }
46  void set_min_interval(uint16_t val) { this->min_interval_ = val; }
47  void set_max_interval(uint16_t val) { this->max_interval_ = val; }
48  void set_measured_power(int8_t val) { this->measured_power_ = val; }
49  void set_tx_power(int8_t val) { this->tx_power_ = val; }
50 
51  protected:
52  static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
53  static void ble_core_task(void *params);
54  static void ble_setup();
55 
56  std::array<uint8_t, 16> uuid_;
57  uint16_t major_{};
58  uint16_t minor_{};
59  uint16_t min_interval_{};
60  uint16_t max_interval_{};
61  int8_t measured_power_{};
62  int8_t tx_power_{};
63 };
64 
65 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
67 
68 } // namespace esp32_ble_beacon
69 } // namespace esphome
70 
71 #endif
mopeka_std_values val[4]
ESP32BLEBeacon(const std::array< uint8_t, 16 > &uuid)
ESP32BLEBeacon * global_esp32_ble_beacon
enum esphome::EntityCategory __attribute__
const uint32_t flags
Definition: stm32flash.h:85
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)