ESPHome 2026.5.1
Loading...
Searching...
No Matches
exposure_notifications.cpp
Go to the documentation of this file.
3#include "esphome/core/log.h"
4
5#ifdef USE_ESP32
6
8
9using namespace esp32_ble_tracker;
10
11static const char *const TAG = "exposure_notifications";
12
14 // See also https://blog.google/documents/70/Exposure_Notification_-_Bluetooth_Specification_v1.2.2.pdf
15 if (device.get_service_uuids().size() != 1)
16 return false;
17
18 // Exposure notifications have Service UUID FD 6F
19 ESPBTUUID uuid = device.get_service_uuids()[0];
20 // constant service identifier
21 const ESPBTUUID expected_uuid = ESPBTUUID::from_uint16(0xFD6F);
22 if (uuid != expected_uuid)
23 return false;
24 if (device.get_service_datas().size() != 1)
25 return false;
26
27 // The service data should be 20 bytes
28 // First 16 bytes are the rolling proximity identifier (RPI)
29 // Then 4 bytes of encrypted metadata follow which can be used to get the transmit power level.
30 ServiceData service_data = device.get_service_datas()[0];
31 if (service_data.uuid != expected_uuid)
32 return false;
33 auto data = service_data.data;
34 if (data.size() != 20)
35 return false;
36 ExposureNotification notification{};
37 memcpy(&notification.address[0], device.address(), 6);
38 memcpy(&notification.rolling_proximity_identifier[0], &data[0], 16);
39 memcpy(&notification.associated_encrypted_metadata[0], &data[16], 4);
40 notification.rssi = device.get_rssi();
41 this->trigger(notification);
42 return true;
43}
44
45} // namespace esphome::exposure_notifications
46
47#endif
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition automation.h:482
static ESPBTUUID from_uint16(uint16_t uuid)
Definition ble_uuid.cpp:17
const std::vector< ServiceData > & get_service_datas() const
const std::vector< ESPBTUUID > & get_service_uuids() const
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override