ESPHome 2025.5.0
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
17namespace esphome {
18namespace airthings_wave_base {
19
21
22static const uint8_t ACCESS_CONTROL_POINT_COMMAND = 0x6d;
23static const auto CLIENT_CHARACTERISTIC_CONFIGURATION_DESCRIPTOR_UUID = espbt::ESPBTUUID::from_uint16(0x2902);
24
26 public:
27 AirthingsWaveBase() = default;
28
29 void update() override;
30
31 void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
32 esp_ble_gattc_cb_param_t *param) override;
33
35 void set_humidity(sensor::Sensor *humidity) { humidity_sensor_ = humidity; }
37 void set_tvoc(sensor::Sensor *tvoc) { tvoc_sensor_ = tvoc; }
39 battery_voltage_ = voltage;
40 this->read_battery_next_update_ = true;
41 }
42 void set_battery_update_interval(uint32_t interval) { battery_update_interval_ = interval; }
43
44 protected:
45 bool is_valid_voc_value_(uint16_t voc);
46
48 virtual void read_sensors(uint8_t *raw_value, uint16_t value_len) = 0;
49
55
56 uint16_t handle_;
59
60 uint16_t acp_handle_{0};
61 uint16_t cccd_handle_{0};
63
65 void response_pending_();
66 void response_received_();
68
69 // default to *not* reading battery voltage from the device; the
70 // set_* function for the battery sensor will set this to 'true'
72 bool request_battery_();
73 void read_battery_(uint8_t *raw_value, uint16_t value_len);
75
77 uint32_t unused1;
78 uint8_t unused2;
79 uint8_t illuminance;
80 uint8_t unused3[10];
81 uint16_t unused4[4];
82 uint16_t battery;
83 uint16_t unused5;
84 };
85};
86
87} // namespace airthings_wave_base
88} // namespace esphome
89
90#endif // USE_ESP32
This class simplifies creating components that periodically check a state.
Definition component.h:301
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:57
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t temperature
Definition sun_gtil2.cpp:12
uint8_t pressure
Definition tt21100.cpp:7