ESPHome
2026.8.1
Loading...
Searching...
No Matches
esphome
components
exposure_notifications
exposure_notifications.cpp
Go to the documentation of this file.
1
#include "
exposure_notifications.h
"
2
#include "
esphome/core/helpers.h
"
3
#include "
esphome/core/log.h
"
4
5
namespace
esphome::exposure_notifications
{
6
7
using namespace
ble_device_base;
8
9
static
const
char
*
const
TAG =
"exposure_notifications"
;
10
11
bool
ExposureNotificationTrigger::parse_device
(
const
ESPBTDevice
&device) {
12
// See also https://blog.google/documents/70/Exposure_Notification_-_Bluetooth_Specification_v1.2.2.pdf
13
if
(device.
get_service_uuids
().size() != 1)
14
return
false
;
15
16
// Exposure notifications have Service UUID FD 6F
17
ESPBTUUID
uuid = device.
get_service_uuids
()[0];
18
// constant service identifier
19
const
ESPBTUUID
expected_uuid =
ESPBTUUID::from_uint16
(0xFD6F);
20
if
(uuid != expected_uuid)
21
return
false
;
22
if
(device.
get_service_datas
().size() != 1)
23
return
false
;
24
25
// The service data should be 20 bytes
26
// First 16 bytes are the rolling proximity identifier (RPI)
27
// Then 4 bytes of encrypted metadata follow which can be used to get the transmit power level.
28
ServiceData
service_data = device.
get_service_datas
()[0];
29
if
(service_data.
uuid
!= expected_uuid)
30
return
false
;
31
auto
data = service_data.
data
;
32
if
(data.size() != 20)
33
return
false
;
34
ExposureNotification
notification{};
35
memcpy(¬ification.address[0], device.
address
(), 6);
36
memcpy(¬ification.rolling_proximity_identifier[0], &data[0], 16);
37
memcpy(¬ification.associated_encrypted_metadata[0], &data[16], 4);
38
notification.rssi = device.
get_rssi
();
39
this->
trigger
(notification);
40
return
true
;
41
}
42
43
}
// namespace esphome::exposure_notifications
esphome::Trigger< ExposureNotification >::trigger
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition
automation.h:461
esphome::ble_device_base::ESPBTDevice
Definition
ble_device.h:178
esphome::ble_device_base::ESPBTDevice::get_service_uuids
const std::vector< ESPBTUUID > & get_service_uuids() const
Definition
ble_device.h:223
esphome::ble_device_base::ESPBTDevice::address
const uint8_t * address() const
Raw MAC bytes in printable (MSB-first) order — matches the historical esp32 layout (ESP-IDF bda order...
Definition
ble_device.h:201
esphome::ble_device_base::ESPBTDevice::get_service_datas
const std::vector< ServiceData > & get_service_datas() const
Definition
ble_device.h:225
esphome::ble_device_base::ESPBTDevice::get_rssi
int get_rssi() const
Definition
ble_device.h:218
esphome::ble_device_base::ESPBTUUID
Definition
ble_device.h:55
esphome::ble_device_base::ESPBTUUID::from_uint16
static ESPBTUUID from_uint16(uint16_t uuid)
Definition
ble_device.cpp:29
esphome::exposure_notifications::ExposureNotificationTrigger::parse_device
bool parse_device(const ble_device_base::ESPBTDevice &device) override
Definition
exposure_notifications.cpp:11
exposure_notifications.h
helpers.h
log.h
esphome::exposure_notifications
Definition
exposure_notifications.cpp:5
esphome::ble_device_base::ServiceData
Definition
ble_device.h:120
esphome::ble_device_base::ServiceData::data
adv_data_t data
Definition
ble_device.h:122
esphome::ble_device_base::ServiceData::uuid
ESPBTUUID uuid
Definition
ble_device.h:121
esphome::exposure_notifications::ExposureNotification
Definition
exposure_notifications.h:10
Generated by
1.12.0