6 namespace radon_eye_rd200 {
8 static const char *
const TAG =
"radon_eye_rd200";
11 esp_ble_gattc_cb_param_t *param) {
13 case ESP_GATTC_OPEN_EVT: {
14 if (param->open.status == ESP_GATT_OK) {
15 ESP_LOGI(TAG,
"Connected successfully!");
20 case ESP_GATTC_DISCONNECT_EVT: {
21 ESP_LOGW(TAG,
"Disconnected!");
25 case ESP_GATTC_SEARCH_CMPL_EVT: {
29 ESP_LOGW(TAG,
"No sensor read characteristic found at service %s char %s",
service_uuid_.
to_string().c_str(),
37 if (write_chr ==
nullptr) {
38 ESP_LOGW(TAG,
"No sensor write characteristic found at service %s char %s",
service_uuid_.
to_string().c_str(),
52 case ESP_GATTC_READ_CHAR_EVT: {
53 if (param->read.conn_id != this->parent()->get_conn_id())
55 if (param->read.status != ESP_GATT_OK) {
56 ESP_LOGW(TAG,
"Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
59 if (param->read.handle == this->read_handle_) {
72 ESP_LOGD(TAG,
"Invalid read");
78 ESP_LOGV(TAG,
"result bytes: %02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X %02X%02X %02X%02X",
79 value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9],
80 value[10], value[11], value[12], value[13], value[14], value[15], value[16], value[17], value[18],
83 if (value[0] != 0x50) {
89 constexpr
float convert_to_bwpm3 = 37.0;
92 radon_value.
chars[0] = value[2];
93 radon_value.
chars[1] = value[3];
94 radon_value.
chars[2] = value[4];
95 radon_value.
chars[3] = value[5];
96 float radon_now = radon_value.
number * convert_to_bwpm3;
101 radon_value.
chars[0] = value[6];
102 radon_value.
chars[1] = value[7];
103 radon_value.
chars[2] = value[8];
104 radon_value.
chars[3] = value[9];
105 float radon_day = radon_value.
number * convert_to_bwpm3;
107 radon_value.
chars[0] = value[10];
108 radon_value.
chars[1] = value[11];
109 radon_value.
chars[2] = value[12];
110 radon_value.
chars[3] = value[13];
111 float radon_month = radon_value.
number * convert_to_bwpm3;
114 ESP_LOGV(TAG,
"Radon Long Term based on month");
117 ESP_LOGV(TAG,
"Radon Long Term based on day");
121 ESP_LOGV(TAG,
" Measurements (Bq/m³) now: %0.03f, day: %0.03f, month: %0.03f", radon_now, radon_day, radon_month);
123 ESP_LOGV(TAG,
" Measurements (pCi/L) now: %0.03f, day: %0.03f, month: %0.03f", radon_now / convert_to_bwpm3,
124 radon_day / convert_to_bwpm3, radon_month / convert_to_bwpm3);
137 ESP_LOGW(TAG,
"Reconnecting to device");
141 ESP_LOGW(TAG,
"Connection in progress");
147 ESP_LOGV(TAG,
"writing 0x50 to write service");
149 auto status = esp_ble_gattc_write_char_descr(this->
parent()->get_gattc_if(), this->
parent()->get_conn_id(),
151 ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
153 ESP_LOGW(TAG,
"Error sending write request for sensor, status=%d",
status);
158 auto status = esp_ble_gattc_read_char(this->
parent()->get_gattc_if(), this->
parent()->get_conn_id(),
161 ESP_LOGW(TAG,
"Error sending read request for sensor, status=%d",
status);
172 service_uuid_(esp32_ble_tracker::ESPBTUUID::from_raw(SERVICE_UUID)),
esp32_ble_tracker::ESPBTUUID service_uuid_
This class simplifies creating components that periodically check a state.
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
esp32_ble_tracker::ESPBTUUID sensors_read_characteristic_uuid_
sensor::Sensor * radon_sensor_
void request_read_values_()
void set_enabled(bool enabled)
void publish_state(float state)
Publish a new state to the front-end.
esp32_ble_tracker::ESPBTUUID sensors_write_characteristic_uuid_
void dump_config() override
sensor::Sensor * radon_long_term_sensor_
std::string to_string() const
bool is_valid_radon_value_(float radon)
BLECharacteristic * get_characteristic(espbt::ESPBTUUID service, espbt::ESPBTUUID chr)
Implementation of SPI Controller mode.
void write_query_message_()
void read_sensors_(uint8_t *value, uint16_t value_len)
espbt::ClientState node_state