mirror of
https://github.com/esphome/esphome.git
synced 2025-11-19 00:05:43 +00:00
iBeacon support for ble_presence (#1627)
This commit is contained in:
@@ -108,6 +108,16 @@ def as_hex(value):
|
||||
|
||||
|
||||
def as_hex_array(value):
|
||||
value = value.replace("-", "")
|
||||
cpp_array = [
|
||||
f"0x{part}" for part in [value[i : i + 2] for i in range(0, len(value), 2)]
|
||||
]
|
||||
return cg.RawExpression(
|
||||
"(uint8_t*)(const uint8_t[16]){{{}}}".format(",".join(cpp_array))
|
||||
)
|
||||
|
||||
|
||||
def as_reversed_hex_array(value):
|
||||
value = value.replace("-", "")
|
||||
cpp_array = [
|
||||
f"0x{part}" for part in [value[i : i + 2] for i in range(0, len(value), 2)]
|
||||
@@ -193,7 +203,7 @@ async def to_code(config):
|
||||
elif len(conf[CONF_SERVICE_UUID]) == len(bt_uuid32_format):
|
||||
cg.add(trigger.set_service_uuid32(as_hex(conf[CONF_SERVICE_UUID])))
|
||||
elif len(conf[CONF_SERVICE_UUID]) == len(bt_uuid128_format):
|
||||
uuid128 = as_hex_array(conf[CONF_SERVICE_UUID])
|
||||
uuid128 = as_reversed_hex_array(conf[CONF_SERVICE_UUID])
|
||||
cg.add(trigger.set_service_uuid128(uuid128))
|
||||
if CONF_MAC_ADDRESS in conf:
|
||||
cg.add(trigger.set_address(conf[CONF_MAC_ADDRESS].as_hex))
|
||||
@@ -205,7 +215,7 @@ async def to_code(config):
|
||||
elif len(conf[CONF_MANUFACTURER_ID]) == len(bt_uuid32_format):
|
||||
cg.add(trigger.set_manufacturer_uuid32(as_hex(conf[CONF_MANUFACTURER_ID])))
|
||||
elif len(conf[CONF_MANUFACTURER_ID]) == len(bt_uuid128_format):
|
||||
uuid128 = as_hex_array(conf[CONF_MANUFACTURER_ID])
|
||||
uuid128 = as_reversed_hex_array(conf[CONF_MANUFACTURER_ID])
|
||||
cg.add(trigger.set_manufacturer_uuid128(uuid128))
|
||||
if CONF_MAC_ADDRESS in conf:
|
||||
cg.add(trigger.set_address(conf[CONF_MAC_ADDRESS].as_hex))
|
||||
|
||||
@@ -434,6 +434,14 @@ void ESPBTDevice::parse_scan_rst(const esp_ble_gap_cb_param_t::ble_scan_result_e
|
||||
}
|
||||
for (auto &data : this->manufacturer_datas_) {
|
||||
ESP_LOGVV(TAG, " Manufacturer data: %s", hexencode(data.data).c_str());
|
||||
if (this->get_ibeacon().has_value()) {
|
||||
auto ibeacon = this->get_ibeacon().value();
|
||||
ESP_LOGVV(TAG, " iBeacon data:");
|
||||
ESP_LOGVV(TAG, " UUID: %s", ibeacon.get_uuid().to_string().c_str());
|
||||
ESP_LOGVV(TAG, " Major: %u", ibeacon.get_major());
|
||||
ESP_LOGVV(TAG, " Minor: %u", ibeacon.get_minor());
|
||||
ESP_LOGVV(TAG, " TXPower: %d", ibeacon.get_signal_power());
|
||||
}
|
||||
}
|
||||
for (auto &data : this->service_datas_) {
|
||||
ESP_LOGVV(TAG, " Service data:");
|
||||
|
||||
Reference in New Issue
Block a user