22 ESP_LOGVV(TAG,
"parse_device(): unknown MAC address.");
25 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
26 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", device.
address_str_to(addr_buf));
28 if (service_datas.size() != 1) {
29 ESP_LOGE(TAG,
"Unexpected service_datas size (%d)", service_datas.size());
32 const auto &service_data = service_datas[0];
34 ESP_LOGVV(TAG,
"Service data:");
35 for (
const uint8_t
byte : service_data.data) {
36 ESP_LOGVV(TAG,
"0x%02x",
byte);
39 const auto &data = service_data.data;
41 const uint8_t protocol_version = data[0] >> 4;
42 if (protocol_version != 1 && protocol_version != 2) {
43 ESP_LOGE(TAG,
"Unsupported protocol version: %u", protocol_version);
48 bool has_illuminance = data[0] & 0x1;
51 uint8_t counter = data[1] & 0x0f;
53 ESP_LOGVV(TAG,
"Skipping already processed counter (%u)", counter);
58 uint16_t battery_millivolt = data[2] << 8 | data[3];
59 float battery_voltage = battery_millivolt / 1000.0f;
63 if (protocol_version == 1) {
64 uint16_t temp_millicelsius = data[4] << 8 | data[5];
65 temp_celsius = temp_millicelsius / 1000.0f;
67 int16_t temp_centicelsius = data[4] << 8 | data[5];
68 temp_celsius = temp_centicelsius / 100.0f;
72 uint16_t humidity = data[6] << 8 | data[7];
73 float humidity_percent = (100.0f * humidity) / (1 << 16);
76 uint16_t soil_moisture = data[8] << 8 | data[9];
77 float moisture_percent = (100.0f * soil_moisture) / (1 << 16);
80 float illuminance = has_illuminance ? data[16] << 8 | data[17] : 0.0f;
95 if (has_illuminance) {
98 ESP_LOGE(TAG,
"No lux information is present in the BLE packet");