ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
airthings_wave_base.h
Go to the documentation of this file.
1#pragma once
2
3// All information related to reading battery levels came from the sensors.airthings_wave
4// project by Sverre Hamre (https://github.com/sverrham/sensor.airthings_wave)
5
6#ifdef USE_ESP32
7
8#include <esp_gattc_api.h>
9#include <algorithm>
10#include <iterator>
15#include "esphome/core/log.h"
16
18
20
21static const uint8_t ACCESS_CONTROL_POINT_COMMAND = 0x6d;
22static const auto CLIENT_CHARACTERISTIC_CONFIGURATION_DESCRIPTOR_UUID = espbt::ESPBTUUID::from_uint16(0x2902);
23
25 public:
26 AirthingsWaveBase() = default;
27
28 void update() override;
29
30 void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
31 esp_ble_gattc_cb_param_t *param) override;
32
34 void set_humidity(sensor::Sensor *humidity) { humidity_sensor_ = humidity; }
36 void set_tvoc(sensor::Sensor *tvoc) { tvoc_sensor_ = tvoc; }
38 battery_voltage_ = voltage;
39 this->read_battery_next_update_ = true;
40 }
42
43 protected:
44 bool is_valid_voc_value_(uint16_t voc);
45
47 virtual void read_sensors(uint8_t *raw_value, uint16_t value_len) = 0;
48
54
55 uint16_t handle_;
58
59 uint16_t acp_handle_{0};
60 uint16_t cccd_handle_{0};
62
64 void response_pending_();
65 void response_received_();
67
68 // default to *not* reading battery voltage from the device; the
69 // set_* function for the battery sensor will set this to 'true'
71 bool request_battery_();
72 void read_battery_(uint8_t *raw_value, uint16_t value_len);
74
77 uint8_t unused2;
78 uint8_t illuminance;
79 uint8_t unused3[10];
80 uint16_t unused4[4];
81 uint16_t battery;
82 uint16_t unused5;
83 };
84};
85
86} // namespace esphome::airthings_wave_base
87
88#endif // USE_ESP32
This class simplifies creating components that periodically check a state.
Definition component.h:585
void read_battery_(uint8_t *raw_value, uint16_t value_len)
void set_temperature(sensor::Sensor *temperature)
virtual void read_sensors(uint8_t *raw_value, uint16_t value_len)=0
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
Base-class for all sensors.
Definition sensor.h:47
static void uint32_t
uint16_t temperature
Definition sun_gtil2.cpp:12
uint8_t pressure
Definition tt21100.cpp:7