ESPHome 2025.12.0-dev
Loading...
Searching...
No Matches
esp32_ble_beacon.h
Go to the documentation of this file.
1#pragma once
2
5
6#ifdef USE_ESP32
7
8#ifndef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID
9#include <esp_bt.h>
10#endif
11#include <esp_gap_ble_api.h>
12
13namespace esphome {
14namespace esp32_ble_beacon {
15
16using esp_ble_ibeacon_head_t = struct {
17 uint8_t flags[3];
18 uint8_t length;
19 uint8_t type;
20 uint8_t company_id[2];
21 uint8_t beacon_type[2];
22} __attribute__((packed));
23
25 uint8_t proximity_uuid[16];
26 uint16_t major;
27 uint16_t minor;
28 uint8_t measured_power;
29} __attribute__((packed));
30
31using esp_ble_ibeacon_t = struct {
32 esp_ble_ibeacon_head_t ibeacon_head;
33 esp_ble_ibeacon_vendor_t ibeacon_vendor;
34} __attribute__((packed));
35
36using namespace esp32_ble;
37
38class ESP32BLEBeacon : public Component, public GAPEventHandler, public Parented<ESP32BLE> {
39 public:
40 explicit ESP32BLEBeacon(const std::array<uint8_t, 16> &uuid) : uuid_(uuid) {}
41
42 void setup() override;
43 void dump_config() override;
44 float get_setup_priority() const override;
45
46 void set_major(uint16_t major) { this->major_ = major; }
47 void set_minor(uint16_t minor) { this->minor_ = minor; }
48 void set_min_interval(uint16_t val) { this->min_interval_ = val; }
49 void set_max_interval(uint16_t val) { this->max_interval_ = val; }
50 void set_measured_power(int8_t val) { this->measured_power_ = val; }
51 void set_tx_power(esp_power_level_t val) { this->tx_power_ = val; }
52 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
53
54 protected:
55 void on_advertise_();
56
57 std::array<uint8_t, 16> uuid_;
58 uint16_t major_{};
59 uint16_t minor_{};
60 uint16_t min_interval_{};
61 uint16_t max_interval_{};
63 esp_power_level_t tx_power_{};
64 esp_ble_adv_params_t ble_adv_params_;
65 bool advertising_{false};
66};
67
68} // namespace esp32_ble_beacon
69} // namespace esphome
70
71#endif
Helper class to easily give an object a parent of type T.
Definition helpers.h:918
ESP32BLEBeacon(const std::array< uint8_t, 16 > &uuid)
void set_tx_power(esp_power_level_t val)
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override
struct @65::@66 __attribute__
uint16_t type
uint16_t flags
mopeka_std_values val[4]
struct { uint8_t flags[3]; uint8_t length; uint8_t type; uint8_t company_id[2]; uint8_t beacon_type[2];} __attribute__((packed)) esp_ble_ibeacon_head_t
struct { esp_ble_ibeacon_head_t ibeacon_head; esp_ble_ibeacon_vendor_t ibeacon_vendor;} __attribute__((packed)) esp_ble_ibeacon_t
struct { uint8_t proximity_uuid[16]; uint16_t major; uint16_t minor; uint8_t measured_power;} __attribute__((packed)) esp_ble_ibeacon_vendor_t
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t length
Definition tt21100.cpp:0