diff --git a/components/bthome_base/bthome_base_common.cpp b/components/bthome_base/bthome_base_common.cpp index b9685de..bb55405 100644 --- a/components/bthome_base/bthome_base_common.cpp +++ b/components/bthome_base/bthome_base_common.cpp @@ -5,7 +5,10 @@ */ #include + +#ifndef USE_ESP32 #include +#endif #include "bthome_base_common.h" #include "bthome_common_generated.h" @@ -50,8 +53,11 @@ namespace bthome_base // check range if (obj_meas_type >= sizeof(MEAS_TYPES_FLAGS) / sizeof(uint8_t)) return {}; - +#ifndef USE_ESP32 const uint8_t meas_type_flags = pgm_read_byte_near(MEAS_TYPES_FLAGS + obj_meas_type); +#else + const uint8_t meas_type_flags = MEAS_TYPES_FLAGS[obj_meas_type]; +#endif const uint8_t factor_raw = (meas_type_flags & 0b01100000) >> 5; BTHomeDataFormat retval = { .factor_raw = factor_raw, diff --git a/components/bthome_base/bthome_common_generated.h b/components/bthome_base/bthome_common_generated.h index 75a0b01..5494512 100644 --- a/components/bthome_base/bthome_common_generated.h +++ b/components/bthome_base/bthome_common_generated.h @@ -2,7 +2,11 @@ /* auto generated, do not edit */ #pragma once + +#ifndef USE_ESP32 #include +#endif + namespace bthome_base { @@ -88,7 +92,8 @@ typedef enum { BTHOME_BUTTON_TRIPLE_CLICK = 0x03, BTHOME_BUTTON_LONG_CLICK = 0x04, BTHOME_BUTTON_LONG_DOUBLE_CLICK = 0x05, - BTHOME_BUTTON_LONG_TRIPLE_CLICK = 0x06 + BTHOME_BUTTON_LONG_TRIPLE_CLICK = 0x06, + BTHOME_BUTTON_HOLD_CLICK = 0x80 } BTHome_Button_e; typedef enum { @@ -97,10 +102,14 @@ typedef enum { BTHOME_DIMMER_ROTATE_RIGHT = 0x02 } BTHome_Dimmer_e; -static const uint8_t PROGMEM MEAS_TYPES_FLAGS[] = { /* 8th bit Unused | 6-7th bits Factor | 4-5th bits DataType | 1-2-3rd bits DataLen */ +#ifndef USE_ESP32 +static const uint8_t PROGMEM MEAS_TYPES_FLAGS[] = { /* 8th bit Unused | 6-7th bits Factor | 4-5th bits DataType | 1-2-3rd bits DataLen */ +#else +static const uint8_t MEAS_TYPES_FLAGS[] = { /* 8th bit Unused | 6-7th bits Factor | 4-5th bits DataType | 1-2-3rd bits DataLen */ +#endif /* 0x00 */ 0b00000001, /* packet_id | uint8 (1 byte) | numeric * 1.0 */ /* 0x01 */ 0b00000001, /* battery | uint8 (1 byte) | numeric * 1.0 */ - /* 0x02 */ 0b01001010, /* temperature | sint16 (2 bytes) | numeric * 0.01 */ + /* 0x02 */ 0b01001010, /* temperature | sint16 (2 bytes) | numeric * 0.01 */ /* 0x03 */ 0b01000010, /* humidity | uint16 (2 bytes) | numeric * 0.01 */ /* 0x04 */ 0b01000011, /* pressure | uint24 (3 bytes) | numeric * 0.01 */ /* 0x05 */ 0b01000011, /* illuminance | uint24 (3 bytes) | numeric * 0.01 */ @@ -180,6 +189,18 @@ static const uint8_t PROGMEM MEAS_TYPES_FLAGS[] = { /* 8th bit Unused | 6-7th bi /* 0x4f */ 0b01100100, /* water | uint32 (4 bytes) | numeric * 0.001 */ /* 0x50 */ 0b00000100, /* timestamp | uint48 (4 bytes) | numeric * 1.0 */ /* 0x51 */ 0b01100010, /* acceleration | uint16 (2 bytes) | numeric * 0.001 */ + /* 0x52 */ 0b01100010, /* gyroscope | uint16 (2 bytes) | numeric * 0.001 */ + /* 0x53 */ 0b00000000, /* text */ + /* 0x54 */ 0b00000000, /* raw */ + /* 0x55 */ 0b01100100, /* volume storage | uint32 (4 bytes) | numeric * 0.001 */ + /* 0x56 */ 0b00000010, /* conductivity | uint16 (2 bytes) | numeric * 1.0 */ + /* 0x57 */ 0b00001001, /* temperature | sint8 (1 byte) | numeric 1.0 */ + /* 0x58 */ 0b00001001, /* temperature | sint8 (1 btes) | numeric * 0.35 !!!!! */ + /* 0x59 */ 0b00001001, /* count | sint8 (1 byte) | numeric 1.0 */ + /* 0x5a */ 0b00001010, /* count | sint16 (2 bytes) | numeric 1.0 */ + /* 0x5b */ 0b00001100, /* count | sint32 (4 bytes) | numeric * 1.0 */ + /* 0x5c */ 0b01001100, /* power | sint32 (4 bytes) | numeric * 0.01 */ + /* 0x5d */ 0b01101010, /* current | sint16 (2 bytes) | numeric * 0.001 */ }; } diff --git a/components/bthome_base/bthome_parser.cpp b/components/bthome_base/bthome_parser.cpp index 7ddbd15..b800c79 100644 --- a/components/bthome_base/bthome_parser.cpp +++ b/components/bthome_base/bthome_parser.cpp @@ -10,7 +10,10 @@ #include #include #include +#include +#ifndef USE_ESP32 #include +#endif #include "bthome_parser.h" #include "bthome_common_generated.h" @@ -66,6 +69,21 @@ namespace bthome_base uint8_t obj_data_start; float obj_data_factor; + if (log_cb) + { + char buffer [4]; + char msg [70]; + int n; + strcpy(msg, "rec BT payload is : "); + for (int i = 0; i < payload_length; ++i) + { + n=sprintf (buffer, "%.2x ", payload_data[i]); + strlcat(msg, buffer, sizeof(msg)); + } + log_cb(msg); + } + + while (payload_length >= next_obj_start + 1) { auto obj_start = next_obj_start; @@ -160,4 +178,4 @@ namespace bthome_base return true; } -} \ No newline at end of file +} diff --git a/components/bthome_base/const_generated.py b/components/bthome_base/const_generated.py index 018b7da..64bd7c8 100644 --- a/components/bthome_base/const_generated.py +++ b/components/bthome_base/const_generated.py @@ -175,6 +175,11 @@ "measurement_type": 0x3a, "event_id": 6 }, + "button_hold_click": { + "device_event_type": 0x3a80, + "measurement_type": 0x3a, + "event_id": 128 + }, "dimmer_none": { "device_event_type": 0x3c00, "measurement_type": 0x3c, @@ -436,5 +441,55 @@ "measurement_type": 0x52, "accuracy_decimals": 3, "unit_of_measurement": "°/s" + }, + "volume storage": { + "measurement_type": 0x55, + "accuracy_decimals": 3, + "unit_of_measurement": "l", + "device_class": "volume" + }, + "conductivity": { + "measurement_type": 0x56, + "accuracy_decimals": 0, + "unit_of_measurement": "µS/cm" + }, + "temperature": { + "measurement_type": 0x57, + "accuracy_decimals": 0, + "unit_of_measurement": "°C", + "device_class": "temperature" + }, + "temperature": { + "measurement_type": 0x58, + "accuracy_decimals": 0, + "unit_of_measurement": "°C", + "device_class": "temperature" + }, + "count": { + "measurement_type": 0x59, + "accuracy_decimals": 0, + "unit_of_measurement": "" + }, + "count": { + "measurement_type": 0x5a, + "accuracy_decimals": 0, + "unit_of_measurement": "" + }, + "count": { + "measurement_type": 0x5b, + "accuracy_decimals": 0, + "unit_of_measurement": "" + }, + "power": { + "measurement_type": 0x5c, + "accuracy_decimals": 2, + "unit_of_measurement": "W", + "device_class": "power" + }, + "current": { + "measurement_type": 0x5d, + "accuracy_decimals": 3, + "unit_of_measurement": "A", + "device_class": "current" } } diff --git a/components/bthome_ble_receiver/bthome_ble_receiver_hub.cpp b/components/bthome_ble_receiver/bthome_ble_receiver_hub.cpp index 5e8840f..158431f 100644 --- a/components/bthome_ble_receiver/bthome_ble_receiver_hub.cpp +++ b/components/bthome_ble_receiver/bthome_ble_receiver_hub.cpp @@ -88,13 +88,13 @@ namespace esphome // bthome_receiver_mac_reversed = data[1:7] // mac_readable = to_mac(bthome_receiver_mac_reversed[::-1]) payload_data += 7; - payload_length = -7; + payload_length -= 7; } else { // mac_readable = service_info.address; payload_data += 1; - payload_length = -1; + payload_length -= 1; } } @@ -106,4 +106,4 @@ namespace esphome } } -#endif \ No newline at end of file +#endif