7namespace pvvx_mithermometer {
9static const char *
const TAG =
"pvvx_mithermometer";
12 ESP_LOGCONFIG(TAG,
"PVVX MiThermometer");
14 LOG_SENSOR(
" ",
"Humidity", this->
humidity_);
21 ESP_LOGVV(TAG,
"parse_device(): unknown MAC address.");
24 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
26 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", addr_str);
31 if (!res.has_value()) {
40 if (res->temperature.has_value() && this->temperature_ !=
nullptr)
42 if (res->humidity.has_value() && this->humidity_ !=
nullptr)
44 if (res->battery_level.has_value() && this->battery_level_ !=
nullptr)
46 if (res->battery_voltage.has_value() && this->battery_voltage_ !=
nullptr)
59 ESP_LOGVV(TAG,
"parse_header(): no service data UUID magic bytes.");
65 static uint8_t last_frame_count = 0;
66 if (last_frame_count ==
raw[13]) {
67 ESP_LOGVV(TAG,
"parse_header(): duplicate data packet received (%hhu).", last_frame_count);
70 last_frame_count =
raw[13];
90 const uint8_t *data =
message.data();
91 const int data_length = 15;
93 if (
message.size() != data_length) {
94 ESP_LOGVV(TAG,
"parse_message(): payload has wrong size (%d)!",
message.size());
99 const int16_t
temperature = int16_t(data[6]) | (int16_t(data[7]) << 8);
103 const int16_t humidity = uint16_t(data[8]) | (uint16_t(data[9]) << 8);
104 result.
humidity = humidity / 1.0e2f;
107 const int16_t battery_voltage = uint16_t(data[10]) | (uint16_t(data[11]) << 8);
118 ESP_LOGVV(TAG,
"report_results(): no results available.");
122 ESP_LOGD(TAG,
"Got PVVX MiThermometer (%s):",
address);
125 ESP_LOGD(TAG,
" Temperature: %.2f °C", *result->temperature);
128 ESP_LOGD(TAG,
" Humidity: %.2f %%", *result->humidity);
131 ESP_LOGD(TAG,
" Battery Level: %.0f %%", *result->battery_level);
133 if (result->battery_voltage.
has_value()) {
134 ESP_LOGD(TAG,
" Battery Voltage: %.3f V", *result->battery_voltage);
bool contains(uint8_t data1, uint8_t data2) const
uint64_t address_uint64() const
const char * address_str_to(std::span< char, MAC_ADDRESS_PRETTY_BUFFER_SIZE > buf) const
Format MAC address into provided buffer, returns pointer to buffer for convenience.
const std::vector< ServiceData > & get_service_datas() const
sensor::Sensor * battery_voltage_
sensor::Sensor * signal_strength_
void dump_config() override
bool parse_message_(const std::vector< uint8_t > &message, ParseResult &result)
sensor::Sensor * battery_level_
bool report_results_(const optional< ParseResult > &result, const char *address)
sensor::Sensor * temperature_
optional< ParseResult > parse_header_(const esp32_ble_tracker::ServiceData &service_data)
sensor::Sensor * humidity_
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
void publish_state(float state)
Publish a new state to the front-end.
Providing packet encoding functions for exchanging data with a remote host.
optional< float > battery_level
optional< float > humidity
optional< float > battery_voltage
optional< float > temperature