ESPHome 2026.5.1
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
14
15using esp_ble_ibeacon_head_t = struct {
16 uint8_t flags[3];
17 uint8_t length;
18 uint8_t type;
19 uint8_t company_id[2];
20 uint8_t beacon_type[2];
21} __attribute__((packed));
22
24 uint8_t proximity_uuid[16];
25 uint16_t major;
26 uint16_t minor;
27 uint8_t measured_power;
28} __attribute__((packed));
29
30using esp_ble_ibeacon_t = struct {
31 esp_ble_ibeacon_head_t ibeacon_head;
32 esp_ble_ibeacon_vendor_t ibeacon_vendor;
33} __attribute__((packed));
34
35using namespace esp32_ble;
36
37class ESP32BLEBeacon : public Component {
38 public:
39 explicit ESP32BLEBeacon(const std::array<uint8_t, 16> &uuid) : uuid_(uuid) {}
40
41 void setup() override;
42 void dump_config() override;
43 float get_setup_priority() const override;
44
45 void set_major(uint16_t major) { this->major_ = major; }
46 void set_minor(uint16_t minor) { this->minor_ = minor; }
47 void set_min_interval(uint16_t val) { this->min_interval_ = val; }
48 void set_max_interval(uint16_t val) { this->max_interval_ = val; }
49 void set_measured_power(int8_t val) { this->measured_power_ = val; }
50#ifndef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID
51 void set_tx_power(esp_power_level_t val) { this->tx_power_ = val; }
52#endif
53 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
54
55 protected:
56 void on_advertise_();
57
58 std::array<uint8_t, 16> uuid_;
59 uint16_t major_{};
60 uint16_t minor_{};
61 uint16_t min_interval_{};
62 uint16_t max_interval_{};
64#ifndef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID
65 esp_power_level_t tx_power_{};
66#endif
67 esp_ble_adv_params_t ble_adv_params_;
68 bool advertising_{false};
69};
70
71} // namespace esphome::esp32_ble_beacon
72
73#endif
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
ESP32BLEBeacon(const std::array< uint8_t, 16 > &uuid)
void set_tx_power(esp_power_level_t val)
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
uint16_t type
uint16_t flags
mopeka_std_values val[3]
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
uint16_t length
Definition tt21100.cpp:0