ESPHome 2025.6.0
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#include <esp_bt.h>
9#include <esp_gap_ble_api.h>
10
11namespace esphome {
12namespace esp32_ble_beacon {
13
14using esp_ble_ibeacon_head_t = 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));
21
23 uint8_t proximity_uuid[16];
24 uint16_t major;
25 uint16_t minor;
26 uint8_t measured_power;
27} __attribute__((packed));
28
29using esp_ble_ibeacon_t = struct {
30 esp_ble_ibeacon_head_t ibeacon_head;
31 esp_ble_ibeacon_vendor_t ibeacon_vendor;
32} __attribute__((packed));
33
34using namespace esp32_ble;
35
36class ESP32BLEBeacon : public Component, public GAPEventHandler, public Parented<ESP32BLE> {
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(esp_power_level_t val) { this->tx_power_ = val; }
50 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
51
52 protected:
53 void on_advertise_();
54
55 std::array<uint8_t, 16> uuid_;
56 uint16_t major_{};
57 uint16_t minor_{};
58 uint16_t min_interval_{};
59 uint16_t max_interval_{};
61 esp_power_level_t tx_power_{};
62 esp_ble_adv_params_t ble_adv_params_;
63 bool advertising_{false};
64};
65
66} // namespace esp32_ble_beacon
67} // namespace esphome
68
69#endif
Helper class to easily give an object a parent of type T.
Definition helpers.h:539
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 @67::@68 __attribute__
uint8_t type
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