ESPHome 2025.12.1
Loading...
Searching...
No Matches
ble_sensor.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <vector>
9
10#ifdef USE_ESP32
11#include <esp_gattc_api.h>
12
13namespace esphome::ble_client {
14
16
18 public:
19 void loop() override;
20 void update() override;
21 void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
22 esp_ble_gattc_cb_param_t *param) override;
23 void dump_config() override;
24 void set_service_uuid16(uint16_t uuid) { this->service_uuid_ = espbt::ESPBTUUID::from_uint16(uuid); }
25 void set_service_uuid32(uint32_t uuid) { this->service_uuid_ = espbt::ESPBTUUID::from_uint32(uuid); }
26 void set_service_uuid128(uint8_t *uuid) { this->service_uuid_ = espbt::ESPBTUUID::from_raw(uuid); }
27 void set_char_uuid16(uint16_t uuid) { this->char_uuid_ = espbt::ESPBTUUID::from_uint16(uuid); }
28 void set_char_uuid32(uint32_t uuid) { this->char_uuid_ = espbt::ESPBTUUID::from_uint32(uuid); }
29 void set_char_uuid128(uint8_t *uuid) { this->char_uuid_ = espbt::ESPBTUUID::from_raw(uuid); }
30 void set_descr_uuid16(uint16_t uuid) { this->descr_uuid_ = espbt::ESPBTUUID::from_uint16(uuid); }
31 void set_descr_uuid32(uint32_t uuid) { this->descr_uuid_ = espbt::ESPBTUUID::from_uint32(uuid); }
32 void set_descr_uuid128(uint8_t *uuid) { this->descr_uuid_ = espbt::ESPBTUUID::from_raw(uuid); }
33 void set_data_to_value(float (*lambda)(const std::vector<uint8_t> &)) {
34 this->data_to_value_func_ = lambda;
35 this->has_data_to_value_ = true;
36 }
37 void set_enable_notify(bool notify) { this->notify_ = notify; }
38 uint16_t handle;
39
40 protected:
41 float parse_data_(uint8_t *value, uint16_t value_len);
42 bool has_data_to_value_{false};
43 float (*data_to_value_func_)(const std::vector<uint8_t> &){};
44 bool notify_;
48};
49
50} // namespace esphome::ble_client
51#endif
This class simplifies creating components that periodically check a state.
Definition component.h:474
void set_data_to_value(float(*lambda)(const std::vector< uint8_t > &))
Definition ble_sensor.h:33
void set_service_uuid32(uint32_t uuid)
Definition ble_sensor.h:25
espbt::ESPBTUUID service_uuid_
Definition ble_sensor.h:45
void set_service_uuid16(uint16_t uuid)
Definition ble_sensor.h:24
void set_service_uuid128(uint8_t *uuid)
Definition ble_sensor.h:26
void set_char_uuid128(uint8_t *uuid)
Definition ble_sensor.h:29
void set_descr_uuid16(uint16_t uuid)
Definition ble_sensor.h:30
float(* data_to_value_func_)(const std::vector< uint8_t > &)
Definition ble_sensor.h:43
void set_char_uuid32(uint32_t uuid)
Definition ble_sensor.h:28
float parse_data_(uint8_t *value, uint16_t value_len)
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
void set_descr_uuid32(uint32_t uuid)
Definition ble_sensor.h:31
espbt::ESPBTUUID descr_uuid_
Definition ble_sensor.h:47
espbt::ESPBTUUID char_uuid_
Definition ble_sensor.h:46
void set_enable_notify(bool notify)
Definition ble_sensor.h:37
void set_char_uuid16(uint16_t uuid)
Definition ble_sensor.h:27
void set_descr_uuid128(uint8_t *uuid)
Definition ble_sensor.h:32
Base-class for all sensors.
Definition sensor.h:43