ESPHome
2024.10.2
esphome
esphome
components
ble_scanner
ble_scanner.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <ctime>
4
#include <string>
5
6
#include "
esphome/core/component.h
"
7
#include "
esphome/components/esp32_ble_tracker/esp32_ble_tracker.h
"
8
#include "
esphome/components/text_sensor/text_sensor.h
"
9
10
#ifdef USE_ESP32
11
12
namespace
esphome
{
13
namespace
ble_scanner {
14
15
class
BLEScanner
:
public
text_sensor::TextSensor
,
public
esp32_ble_tracker::ESPBTDeviceListener
,
public
Component
{
16
public
:
17
bool
parse_device
(
const
esp32_ble_tracker::ESPBTDevice
&device)
override
{
18
this->
publish_state
(
"{\"timestamp\":"
+
to_string
(::time(
nullptr
)) +
19
","
20
"\"address\":\""
+
21
device.
address_str
() +
22
"\","
23
"\"rssi\":"
+
24
to_string
(device.
get_rssi
()) +
25
","
26
"\"name\":\""
+
27
device.
get_name
() +
"\"}"
);
28
29
return
true
;
30
}
31
void
dump_config
()
override
;
32
float
get_setup_priority
()
const override
{
return
setup_priority::DATA
; }
33
};
34
35
}
// namespace ble_scanner
36
}
// namespace esphome
37
38
#endif
esphome::setup_priority::DATA
const float DATA
For components that import data from directly connected sensors like DHT.
Definition:
component.cpp:19
esp32_ble_tracker.h
esphome::Component
Definition:
component.h:68
esphome::esp32_ble_tracker::ESPBTDevice::address_str
std::string address_str() const
Definition:
esp32_ble_tracker.cpp:646
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition:
text_sensor.cpp:9
esphome::esp32_ble_tracker::ESPBTDeviceListener
Definition:
esp32_ble_tracker.h:120
esphome::ble_scanner::BLEScanner::get_setup_priority
float get_setup_priority() const override
Definition:
ble_scanner.h:32
esphome::text_sensor::TextSensor
Definition:
text_sensor.h:34
esphome::ble_scanner::BLEScanner
Definition:
ble_scanner.h:15
esphome::esp32_ble_tracker::ESPBTDevice::get_rssi
int get_rssi() const
Definition:
esp32_ble_tracker.h:74
esphome::ble_scanner::BLEScanner::dump_config
void dump_config() override
Definition:
ble_scanner.cpp:11
esphome::to_string
std::string to_string(int value)
Definition:
helpers.cpp:80
esphome::esp32_ble_tracker::ESPBTDevice
Definition:
esp32_ble_tracker.h:63
esphome
Implementation of SPI Controller mode.
Definition:
a01nyub.cpp:7
component.h
esphome::esp32_ble_tracker::ESPBTDevice::get_name
const std::string & get_name() const
Definition:
esp32_ble_tracker.h:75
esphome::ble_scanner::BLEScanner::parse_device
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
Definition:
ble_scanner.h:17
text_sensor.h
Generated by
1.8.13