ESPHome
2025.5.0
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/log.h
"
3
#include "
esphome/core/helpers.h
"
4
5
#ifdef USE_ESP32
6
7
namespace
esphome
{
8
namespace
exposure_notifications {
9
10
using namespace
esp32_ble_tracker;
11
12
static
const
char
*
const
TAG =
"exposure_notifications"
;
13
14
bool
ExposureNotificationTrigger::parse_device
(
const
ESPBTDevice
&device) {
15
// See also https://blog.google/documents/70/Exposure_Notification_-_Bluetooth_Specification_v1.2.2.pdf
16
if
(device.
get_service_uuids
().size() != 1)
17
return
false
;
18
19
// Exposure notifications have Service UUID FD 6F
20
ESPBTUUID
uuid = device.
get_service_uuids
()[0];
21
// constant service identifier
22
const
ESPBTUUID
expected_uuid =
ESPBTUUID::from_uint16
(0xFD6F);
23
if
(uuid != expected_uuid)
24
return
false
;
25
if
(device.
get_service_datas
().size() != 1)
26
return
false
;
27
28
// The service data should be 20 bytes
29
// First 16 bytes are the rolling proximity identifier (RPI)
30
// Then 4 bytes of encrypted metadata follow which can be used to get the transmit power level.
31
ServiceData
service_data = device.
get_service_datas
()[0];
32
if
(service_data.
uuid
!= expected_uuid)
33
return
false
;
34
auto
data = service_data.
data
;
35
if
(data.size() != 20)
36
return
false
;
37
ExposureNotification
notification{};
38
memcpy(¬ification.address[0], device.
address
(), 6);
39
memcpy(¬ification.rolling_proximity_identifier[0], &data[0], 16);
40
memcpy(¬ification.associated_encrypted_metadata[0], &data[16], 4);
41
notification.rssi = device.
get_rssi
();
42
this->
trigger
(notification);
43
return
true
;
44
}
45
46
}
// namespace exposure_notifications
47
}
// namespace esphome
48
49
#endif
esphome::Trigger< ExposureNotification >::trigger
void trigger(Ts... x)
Definition
automation.h:96
esphome::esp32_ble::ESPBTUUID
Definition
ble_uuid.h:14
esphome::esp32_ble::ESPBTUUID::from_uint16
static ESPBTUUID from_uint16(uint16_t uuid)
Definition
ble_uuid.cpp:16
esphome::esp32_ble_tracker::ESPBTDevice
Definition
esp32_ble_tracker.h:63
esphome::esp32_ble_tracker::ESPBTDevice::address
const uint8_t * address() const
Definition
esp32_ble_tracker.h:71
esphome::esp32_ble_tracker::ESPBTDevice::get_service_datas
const std::vector< ServiceData > & get_service_datas() const
Definition
esp32_ble_tracker.h:85
esphome::esp32_ble_tracker::ESPBTDevice::get_rssi
int get_rssi() const
Definition
esp32_ble_tracker.h:74
esphome::esp32_ble_tracker::ESPBTDevice::get_service_uuids
const std::vector< ESPBTUUID > & get_service_uuids() const
Definition
esp32_ble_tracker.h:81
esphome::exposure_notifications::ExposureNotificationTrigger::parse_device
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
Definition
exposure_notifications.cpp:14
exposure_notifications.h
helpers.h
log.h
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
esphome::esp32_ble_tracker::ServiceData
Definition
esp32_ble_tracker.h:36
esphome::esp32_ble_tracker::ServiceData::uuid
ESPBTUUID uuid
Definition
esp32_ble_tracker.h:37
esphome::esp32_ble_tracker::ServiceData::data
adv_data_t data
Definition
esp32_ble_tracker.h:38
esphome::exposure_notifications::ExposureNotification
Definition
exposure_notifications.h:13
Generated by
1.12.0