9 static const char *
const TAG =
"b_parasite";
12 ESP_LOGCONFIG(TAG,
"b_parasite");
15 LOG_SENSOR(
" ",
"Humidity", this->
humidity_);
22 ESP_LOGVV(TAG,
"parse_device(): unknown MAC address.");
25 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", device.
address_str().c_str());
27 if (service_datas.size() != 1) {
28 ESP_LOGE(TAG,
"Unexpected service_datas size (%d)", service_datas.size());
31 const auto &service_data = service_datas[0];
33 ESP_LOGVV(TAG,
"Service data:");
34 for (
const uint8_t byte : service_data.data) {
35 ESP_LOGVV(TAG,
"0x%02x", byte);
38 const auto &data = service_data.data;
40 const uint8_t protocol_version = data[0] >> 4;
41 if (protocol_version != 1 && protocol_version != 2) {
42 ESP_LOGE(TAG,
"Unsupported protocol version: %u", protocol_version);
47 bool has_illuminance = data[0] & 0x1;
50 uint8_t counter = data[1] & 0x0f;
52 ESP_LOGVV(TAG,
"Skipping already processed counter (%u)", counter);
57 uint16_t battery_millivolt = data[2] << 8 | data[3];
58 float battery_voltage = battery_millivolt / 1000.0f;
62 if (protocol_version == 1) {
63 uint16_t temp_millicelsius = data[4] << 8 | data[5];
64 temp_celsius = temp_millicelsius / 1000.0f;
66 int16_t temp_centicelsius = data[4] << 8 | data[5];
67 temp_celsius = temp_centicelsius / 100.0f;
71 uint16_t humidity = data[6] << 8 | data[7];
72 float humidity_percent = (100.0f * humidity) / (1 << 16);
75 uint16_t soil_moisture = data[8] << 8 | data[9];
76 float moisture_percent = (100.0f * soil_moisture) / (1 << 16);
79 float illuminance = has_illuminance ? data[16] << 8 | data[17] : 0.0f;
94 if (has_illuminance) {
97 ESP_LOGE(TAG,
"No lux information is present in the BLE packet");
sensor::Sensor * battery_voltage_
sensor::Sensor * illuminance_
sensor::Sensor * humidity_
std::string address_str() const
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
sensor::Sensor * soil_moisture_
void publish_state(float state)
Publish a new state to the front-end.
const std::vector< ServiceData > & get_service_datas() const
uint64_t address_uint64() const
int8_t last_processed_counter_
sensor::Sensor * temperature_
void dump_config() override
Implementation of SPI Controller mode.