9 static const char *
const TAG =
"ruuvi_ble";
12 const uint8_t data_type = adv_data[0];
13 const auto *data = &adv_data[1];
16 if (adv_data.size() != 14)
19 const uint8_t temp_sign = (data[1] >> 7) & 1;
20 const float temp_val = (data[1] & 0x7F) + (data[2] / 100.0f);
21 const float temperature = temp_sign == 0 ? temp_val : -1 * temp_val;
23 const float humidity = data[0] * 0.5f;
24 const float pressure = (uint16_t(data[3] << 8) + uint16_t(data[4]) + 50000.0f) / 100.0f;
25 const float acceleration_x = (int16_t(data[5] << 8) + int16_t(data[6])) / 1000.0f;
26 const float acceleration_y = (int16_t(data[7] << 8) + int16_t(data[8])) / 1000.0f;
27 const float acceleration_z = (int16_t(data[9] << 8) + int16_t(data[10])) / 1000.0f;
28 const float battery_voltage = (uint16_t(data[11] << 8) + uint16_t(data[12])) / 1000.0f;
37 sqrtf(acceleration_x * acceleration_x + acceleration_y * acceleration_y + acceleration_z * acceleration_z);
43 if (adv_data.size() != 24)
46 const float temperature = (int16_t(data[0] << 8) + int16_t(data[1])) * 0.005f;
47 const float humidity = (uint16_t(data[2] << 8) | uint16_t(data[3])) / 400.0f;
48 const float pressure = ((uint16_t(data[4] << 8) | uint16_t(data[5])) + 50000.0f) / 100.0f;
49 const float acceleration_x = (int16_t(data[6] << 8) + int16_t(data[7])) / 1000.0f;
50 const float acceleration_y = (int16_t(data[8] << 8) + int16_t(data[9])) / 1000.0f;
51 const float acceleration_z = (int16_t(data[10] << 8) + int16_t(data[11])) / 1000.0f;
53 const uint16_t power_info = (uint16_t(data[12] << 8) | data[13]);
54 const float battery_voltage = ((power_info >> 5) + 1600.0f) / 1000.0f;
55 const float tx_power = ((power_info & 0x1F) * 2.0f) - 40.0f;
57 const float movement_counter = float(data[14]);
58 const float measurement_sequence_number = float(uint16_t(data[15] << 8) | uint16_t(data[16]));
61 result.
humidity = data[2] == 0xFF && data[3] == 0xFF ? NAN : humidity;
63 result.
acceleration_x = data[6] == 0xFF && data[7] == 0xFF ? NAN : acceleration_x;
64 result.
acceleration_y = data[8] == 0xFF && data[9] == 0xFF ? NAN : acceleration_y;
65 result.
acceleration_z = data[10] == 0xFF && data[11] == 0xFF ? NAN : acceleration_z;
68 : sqrtf(acceleration_x * acceleration_x + acceleration_y * acceleration_y +
69 acceleration_z * acceleration_z);
70 result.
battery_voltage = (power_info >> 5) == 0x7FF ? NAN : battery_voltage;
71 result.
tx_power = (power_info & 0x1F) == 0x1F ? NAN : tx_power;
85 bool is_ruuvi = it.uuid.contains(0x99, 0x04);
102 ESP_LOGD(TAG,
"Got RuuviTag (%s):", device.
address_str().c_str());
104 if (res->humidity.has_value()) {
105 ESP_LOGD(TAG,
" Humidity: %.2f%%", *res->humidity);
107 if (res->temperature.has_value()) {
108 ESP_LOGD(TAG,
" Temperature: %.2f°C", *res->temperature);
110 if (res->pressure.has_value()) {
111 ESP_LOGD(TAG,
" Pressure: %.2fhPa", *res->pressure);
113 if (res->acceleration.has_value()) {
114 ESP_LOGD(TAG,
" Acceleration: %.3fG", *res->acceleration);
116 if (res->acceleration_x.has_value()) {
117 ESP_LOGD(TAG,
" Acceleration X: %.3fG", *res->acceleration_x);
119 if (res->acceleration_y.has_value()) {
120 ESP_LOGD(TAG,
" Acceleration Y: %.3fG", *res->acceleration_y);
122 if (res->acceleration_z.has_value()) {
123 ESP_LOGD(TAG,
" Acceleration Z: %.3fG", *res->acceleration_z);
125 if (res->battery_voltage.has_value()) {
126 ESP_LOGD(TAG,
" Battery Voltage: %.3fV", *res->battery_voltage);
128 if (res->tx_power.has_value()) {
129 ESP_LOGD(TAG,
" TX Power: %.0fdBm", *res->tx_power);
131 if (res->movement_counter.has_value()) {
132 ESP_LOGD(TAG,
" Movement Counter: %.0f", *res->movement_counter);
134 if (res->measurement_sequence_number.has_value()) {
135 ESP_LOGD(TAG,
" Measurement Sequence Number: %.0f", *res->measurement_sequence_number);
optional< float > movement_counter
optional< float > battery_voltage
optional< float > acceleration
optional< float > tx_power
optional< float > acceleration_x
std::string address_str() const
const std::vector< ServiceData > & get_manufacturer_datas() const
optional< float > acceleration_y
optional< float > acceleration_z
optional< float > humidity
optional< float > measurement_sequence_number
optional< RuuviParseResult > parse_ruuvi(const esp32_ble_tracker::ESPBTDevice &device)
optional< float > temperature
std::vector< uint8_t > adv_data_t
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
optional< float > pressure
Implementation of SPI Controller mode.
bool parse_ruuvi_data_byte(const esp32_ble_tracker::adv_data_t &adv_data, RuuviParseResult &result)