20 ESP_LOGVV(TAG,
"parse_device(): unknown MAC address.");
23 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
24 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", device.
address_str_to(addr_buf));
26 if (service_datas.size() != 1) {
27 ESP_LOGE(TAG,
"Unexpected service_datas size (%d)", service_datas.size());
30 const auto &service_data = service_datas[0];
32 ESP_LOGVV(TAG,
"Service data:");
33 for (
const uint8_t
byte : service_data.data) {
34 ESP_LOGVV(TAG,
"0x%02x",
byte);
37 const auto &data = service_data.data;
39 if (data.size() < 10) {
40 ESP_LOGW(TAG,
"Service data too short: %zu", data.size());
44 const uint8_t protocol_version = data[0] >> 4;
45 if (protocol_version != 1 && protocol_version != 2) {
46 ESP_LOGE(TAG,
"Unsupported protocol version: %u", protocol_version);
51 bool has_illuminance = data[0] & 0x1;
53 if (has_illuminance && data.size() < 18) {
54 ESP_LOGW(TAG,
"Service data too short for illuminance: %zu", data.size());
59 uint8_t counter = data[1] & 0x0f;
61 ESP_LOGVV(TAG,
"Skipping already processed counter (%u)", counter);
67 float battery_voltage = battery_millivolt / 1000.0f;
71 if (protocol_version == 1) {
73 temp_celsius = temp_millicelsius / 1000.0f;
76 temp_celsius = temp_centicelsius / 100.0f;
81 float humidity_percent = (100.0f * humidity) / (1 << 16);
85 float moisture_percent = (100.0f * soil_moisture) / (1 << 16);
103 if (has_illuminance) {
106 ESP_LOGE(TAG,
"No lux information is present in the BLE packet");