ESPHome 2026.8.1
Loading...
Searching...
No Matches
exposure_notifications.cpp
Go to the documentation of this file.
3#include "esphome/core/log.h"
4
6
7using namespace ble_device_base;
8
9static const char *const TAG = "exposure_notifications";
10
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(&notification.address[0], device.address(), 6);
36 memcpy(&notification.rolling_proximity_identifier[0], &data[0], 16);
37 memcpy(&notification.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
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition automation.h:461
const std::vector< ESPBTUUID > & get_service_uuids() const
Definition ble_device.h:223
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
const std::vector< ServiceData > & get_service_datas() const
Definition ble_device.h:225
static ESPBTUUID from_uint16(uint16_t uuid)
bool parse_device(const ble_device_base::ESPBTDevice &device) override