ESPHome
2026.5.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
#ifdef USE_ESP32
6
7
namespace
esphome::exposure_notifications
{
8
9
using namespace
esp32_ble_tracker;
10
11
static
const
char
*
const
TAG =
"exposure_notifications"
;
12
13
bool
ExposureNotificationTrigger::parse_device
(
const
ESPBTDevice
&device) {
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(¬ification.address[0], device.
address
(), 6);
38
memcpy(¬ification.rolling_proximity_identifier[0], &data[0], 16);
39
memcpy(¬ification.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
esphome::Trigger< ExposureNotification >::trigger
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Definition
automation.h:482
esphome::esp32_ble::ESPBTUUID
Definition
ble_uuid.h:20
esphome::esp32_ble::ESPBTUUID::from_uint16
static ESPBTUUID from_uint16(uint16_t uuid)
Definition
ble_uuid.cpp:17
esphome::esp32_ble_tracker::ESPBTDevice
Definition
esp32_ble_tracker.h:78
esphome::esp32_ble_tracker::ESPBTDevice::address
const uint8_t * address() const
Definition
esp32_ble_tracker.h:92
esphome::esp32_ble_tracker::ESPBTDevice::get_service_datas
const std::vector< ServiceData > & get_service_datas() const
Definition
esp32_ble_tracker.h:106
esphome::esp32_ble_tracker::ESPBTDevice::get_rssi
int get_rssi() const
Definition
esp32_ble_tracker.h:95
esphome::esp32_ble_tracker::ESPBTDevice::get_service_uuids
const std::vector< ESPBTUUID > & get_service_uuids() const
Definition
esp32_ble_tracker.h:102
esphome::exposure_notifications::ExposureNotificationTrigger::parse_device
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
Definition
exposure_notifications.cpp:13
exposure_notifications.h
helpers.h
log.h
esphome::exposure_notifications
Definition
exposure_notifications.cpp:7
esphome::esp32_ble_tracker::ServiceData
Definition
esp32_ble_tracker.h:49
esphome::esp32_ble_tracker::ServiceData::uuid
ESPBTUUID uuid
Definition
esp32_ble_tracker.h:50
esphome::esp32_ble_tracker::ServiceData::data
adv_data_t data
Definition
esp32_ble_tracker.h:51
esphome::exposure_notifications::ExposureNotification
Definition
exposure_notifications.h:12
Generated by
1.12.0