|
esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
|
Scans for, connects to, and talks GATT to BLE devices through the device's Bluetooth proxy. More...
#include <bluetooth_proxy.hpp>


Public Types | |
| using | AdvertisementHandler = std::function< void(const BleAdvertisement &)> |
| using | RawAdvertisementHandler = std::function< void(const std::vector< BleRawAdvertisement > &)> |
| using | ScannerStateHandler = std::function< void(const BleScannerState &)> |
| using | ConnectionHandler = std::function< void(const BleConnection &)> |
| using | ConnectionsFreeHandler = std::function< void(const BleConnectionsFree &)> |
| using | GattReadHandler = std::function< void(const BleGattRead &)> |
| using | GattNotifyDataHandler = std::function< void(const BleGattNotifyData &)> |
| using | GattServicesHandler = std::function< void(const BleGattServices &)> |
| using | GattServicesDoneHandler = std::function< void(std::uint64_t address)> |
| using | GattErrorHandler = std::function< void(const BleGattError &)> |
| using | ReadResultHandler = std::function< void(const BleGattReadResult &)> |
| using | WriteResultHandler = std::function< void(const BleGattWriteResult &)> |
| using | ServicesResultHandler = std::function< void(const BleGattServicesResult &)> |
Public Member Functions | |
| BluetoothProxy (Client &client) | |
| void | subscribe_advertisements (AdvertisementHandler handler, std::uint32_t flags=0) |
| Subscribe to parsed BLE advertisements. | |
| void | on_raw_advertisements (RawAdvertisementHandler handler) |
| Subscribe to raw (unparsed) BLE advertisement batches. | |
| void | unsubscribe_advertisements () const |
| Stop receiving BLE advertisements. | |
| void | set_scanner_mode (BluetoothScannerMode mode) const |
| Set the scanner mode (passive or active). | |
| void | on_scanner_state (ScannerStateHandler handler) |
| Register a callback for scanner state changes. | |
| void | request_connection (std::uint64_t address, bool with_cache=true) const |
Ask the proxy to connect to address. | |
| void | disconnect (std::uint64_t address) const |
Disconnect from address. | |
| void | subscribe_connections_free () const |
| Subscribe to the number of free connection slots. | |
| void | on_connection (ConnectionHandler handler) |
| Register a callback for connection state changes. | |
| void | on_connections_free (ConnectionsFreeHandler handler) |
| Register a callback for free-connection-slot updates. | |
| void | read (std::uint64_t address, std::uint32_t handle, ReadResultHandler done) |
Read a GATT characteristic value; done fires once with the result. | |
| void | write (std::uint64_t address, std::uint32_t handle, const std::string &data, bool response, WriteResultHandler done) |
Write a GATT characteristic value; done fires once with the result. | |
| void | get_services (std::uint64_t address, ServicesResultHandler done) |
Discover the full GATT service table; done fires once when complete. | |
| void | read (std::uint64_t address, std::uint32_t handle) const |
| Read a GATT characteristic value (response via on_read / on_error). | |
| void | write (std::uint64_t address, std::uint32_t handle, const std::string &data, bool response=true) const |
Write a GATT characteristic value. response requests a write response. | |
| void | notify (std::uint64_t address, std::uint32_t handle, bool enable) const |
| Enable or disable notifications for a GATT characteristic. | |
| void | get_services (std::uint64_t address) const |
| Request the GATT service table (responses via on_services / on_services_done). | |
| void | on_read (GattReadHandler handler) |
| Register a callback for characteristic read results. | |
| void | on_notify_data (GattNotifyDataHandler handler) |
| Register a callback for characteristic notification payloads. | |
| void | on_services (GattServicesHandler handler) |
| Register a callback for batches of GATT services. | |
| void | on_services_done (GattServicesDoneHandler handler) |
| Register a callback fired when the GATT service table is fully sent. | |
| void | on_error (GattErrorHandler handler) |
| Register a callback for GATT operation errors. | |
Public Member Functions inherited from esphome::api::Subsystem | |
| Subsystem (Client &client) | |
Additional Inherited Members | |
Protected Attributes inherited from esphome::api::Subsystem | |
| Client & | client_ |
Scans for, connects to, and talks GATT to BLE devices through the device's Bluetooth proxy.
| using esphome::api::BluetoothProxy::AdvertisementHandler = std::function<void(const BleAdvertisement&)> |
| using esphome::api::BluetoothProxy::ConnectionHandler = std::function<void(const BleConnection&)> |
| using esphome::api::BluetoothProxy::ConnectionsFreeHandler = std::function<void(const BleConnectionsFree&)> |
| using esphome::api::BluetoothProxy::GattErrorHandler = std::function<void(const BleGattError&)> |
| using esphome::api::BluetoothProxy::GattNotifyDataHandler = std::function<void(const BleGattNotifyData&)> |
| using esphome::api::BluetoothProxy::GattReadHandler = std::function<void(const BleGattRead&)> |
| using esphome::api::BluetoothProxy::GattServicesDoneHandler = std::function<void(std::uint64_t address)> |
| using esphome::api::BluetoothProxy::GattServicesHandler = std::function<void(const BleGattServices&)> |
| using esphome::api::BluetoothProxy::RawAdvertisementHandler = std::function<void(const std::vector<BleRawAdvertisement>&)> |
| using esphome::api::BluetoothProxy::ReadResultHandler = std::function<void(const BleGattReadResult&)> |
| using esphome::api::BluetoothProxy::ScannerStateHandler = std::function<void(const BleScannerState&)> |
| using esphome::api::BluetoothProxy::ServicesResultHandler = std::function<void(const BleGattServicesResult&)> |
| using esphome::api::BluetoothProxy::WriteResultHandler = std::function<void(const BleGattWriteResult&)> |
|
inlineexplicit |
| void esphome::api::BluetoothProxy::disconnect | ( | std::uint64_t | address | ) | const |
Disconnect from address.
| void esphome::api::BluetoothProxy::get_services | ( | std::uint64_t | address | ) | const |
Request the GATT service table (responses via on_services / on_services_done).
| void esphome::api::BluetoothProxy::get_services | ( | std::uint64_t | address, |
| ServicesResultHandler | done | ||
| ) |
Discover the full GATT service table; done fires once when complete.
| void esphome::api::BluetoothProxy::notify | ( | std::uint64_t | address, |
| std::uint32_t | handle, | ||
| bool | enable | ||
| ) | const |
Enable or disable notifications for a GATT characteristic.
| void esphome::api::BluetoothProxy::on_connection | ( | ConnectionHandler | handler | ) |
Register a callback for connection state changes.
| void esphome::api::BluetoothProxy::on_connections_free | ( | ConnectionsFreeHandler | handler | ) |
Register a callback for free-connection-slot updates.
| void esphome::api::BluetoothProxy::on_error | ( | GattErrorHandler | handler | ) |
Register a callback for GATT operation errors.
| void esphome::api::BluetoothProxy::on_notify_data | ( | GattNotifyDataHandler | handler | ) |
Register a callback for characteristic notification payloads.
| void esphome::api::BluetoothProxy::on_raw_advertisements | ( | RawAdvertisementHandler | handler | ) |
Subscribe to raw (unparsed) BLE advertisement batches.
| void esphome::api::BluetoothProxy::on_read | ( | GattReadHandler | handler | ) |
Register a callback for characteristic read results.
| void esphome::api::BluetoothProxy::on_scanner_state | ( | ScannerStateHandler | handler | ) |
Register a callback for scanner state changes.
| void esphome::api::BluetoothProxy::on_services | ( | GattServicesHandler | handler | ) |
Register a callback for batches of GATT services.
| void esphome::api::BluetoothProxy::on_services_done | ( | GattServicesDoneHandler | handler | ) |
Register a callback fired when the GATT service table is fully sent.
| void esphome::api::BluetoothProxy::read | ( | std::uint64_t | address, |
| std::uint32_t | handle | ||
| ) | const |
Read a GATT characteristic value (response via on_read / on_error).
| void esphome::api::BluetoothProxy::read | ( | std::uint64_t | address, |
| std::uint32_t | handle, | ||
| ReadResultHandler | done | ||
| ) |
Read a GATT characteristic value; done fires once with the result.
| void esphome::api::BluetoothProxy::request_connection | ( | std::uint64_t | address, |
| bool | with_cache = true |
||
| ) | const |
Ask the proxy to connect to address.
with_cache selects the V3-with-cache vs V3-without-cache request type.
| void esphome::api::BluetoothProxy::set_scanner_mode | ( | BluetoothScannerMode | mode | ) | const |
Set the scanner mode (passive or active).
| void esphome::api::BluetoothProxy::subscribe_advertisements | ( | AdvertisementHandler | handler, |
| std::uint32_t | flags = 0 |
||
| ) |
Subscribe to parsed BLE advertisements.
handler receives each one. flags is passed through to the device (0 by default).
| void esphome::api::BluetoothProxy::subscribe_connections_free | ( | ) | const |
Subscribe to the number of free connection slots.
| void esphome::api::BluetoothProxy::unsubscribe_advertisements | ( | ) | const |
Stop receiving BLE advertisements.
| void esphome::api::BluetoothProxy::write | ( | std::uint64_t | address, |
| std::uint32_t | handle, | ||
| const std::string & | data, | ||
| bool | response, | ||
| WriteResultHandler | done | ||
| ) |
Write a GATT characteristic value; done fires once with the result.
| void esphome::api::BluetoothProxy::write | ( | std::uint64_t | address, |
| std::uint32_t | handle, | ||
| const std::string & | data, | ||
| bool | response = true |
||
| ) | const |
Write a GATT characteristic value. response requests a write response.