esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
esphome::api::BluetoothProxy Class Reference

Scans for, connects to, and talks GATT to BLE devices through the device's Bluetooth proxy. More...

#include <bluetooth_proxy.hpp>

Inheritance diagram for esphome::api::BluetoothProxy:
Inheritance graph
[legend]
Collaboration diagram for esphome::api::BluetoothProxy:
Collaboration graph
[legend]

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
Clientclient_
 

Detailed Description

Scans for, connects to, and talks GATT to BLE devices through the device's Bluetooth proxy.

Member Typedef Documentation

◆ AdvertisementHandler

◆ ConnectionHandler

◆ ConnectionsFreeHandler

◆ GattErrorHandler

using esphome::api::BluetoothProxy::GattErrorHandler = std::function<void(const BleGattError&)>

◆ GattNotifyDataHandler

◆ GattReadHandler

using esphome::api::BluetoothProxy::GattReadHandler = std::function<void(const BleGattRead&)>

◆ GattServicesDoneHandler

using esphome::api::BluetoothProxy::GattServicesDoneHandler = std::function<void(std::uint64_t address)>

◆ GattServicesHandler

◆ RawAdvertisementHandler

using esphome::api::BluetoothProxy::RawAdvertisementHandler = std::function<void(const std::vector<BleRawAdvertisement>&)>

◆ ReadResultHandler

◆ ScannerStateHandler

◆ ServicesResultHandler

◆ WriteResultHandler

Constructor & Destructor Documentation

◆ BluetoothProxy()

esphome::api::BluetoothProxy::BluetoothProxy ( Client client)
inlineexplicit

Member Function Documentation

◆ disconnect()

void esphome::api::BluetoothProxy::disconnect ( std::uint64_t  address) const

Disconnect from address.

◆ get_services() [1/2]

void esphome::api::BluetoothProxy::get_services ( std::uint64_t  address) const

Request the GATT service table (responses via on_services / on_services_done).

◆ get_services() [2/2]

void esphome::api::BluetoothProxy::get_services ( std::uint64_t  address,
ServicesResultHandler  done 
)

Discover the full GATT service table; done fires once when complete.

◆ notify()

void esphome::api::BluetoothProxy::notify ( std::uint64_t  address,
std::uint32_t  handle,
bool  enable 
) const

Enable or disable notifications for a GATT characteristic.

◆ on_connection()

void esphome::api::BluetoothProxy::on_connection ( ConnectionHandler  handler)

Register a callback for connection state changes.

◆ on_connections_free()

void esphome::api::BluetoothProxy::on_connections_free ( ConnectionsFreeHandler  handler)

Register a callback for free-connection-slot updates.

◆ on_error()

void esphome::api::BluetoothProxy::on_error ( GattErrorHandler  handler)

Register a callback for GATT operation errors.

◆ on_notify_data()

void esphome::api::BluetoothProxy::on_notify_data ( GattNotifyDataHandler  handler)

Register a callback for characteristic notification payloads.

◆ on_raw_advertisements()

void esphome::api::BluetoothProxy::on_raw_advertisements ( RawAdvertisementHandler  handler)

Subscribe to raw (unparsed) BLE advertisement batches.

◆ on_read()

void esphome::api::BluetoothProxy::on_read ( GattReadHandler  handler)

Register a callback for characteristic read results.

◆ on_scanner_state()

void esphome::api::BluetoothProxy::on_scanner_state ( ScannerStateHandler  handler)

Register a callback for scanner state changes.

◆ on_services()

void esphome::api::BluetoothProxy::on_services ( GattServicesHandler  handler)

Register a callback for batches of GATT services.

◆ on_services_done()

void esphome::api::BluetoothProxy::on_services_done ( GattServicesDoneHandler  handler)

Register a callback fired when the GATT service table is fully sent.

◆ read() [1/2]

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).

◆ read() [2/2]

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.

◆ request_connection()

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.

◆ set_scanner_mode()

void esphome::api::BluetoothProxy::set_scanner_mode ( BluetoothScannerMode  mode) const

Set the scanner mode (passive or active).

◆ subscribe_advertisements()

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).

◆ subscribe_connections_free()

void esphome::api::BluetoothProxy::subscribe_connections_free ( ) const

Subscribe to the number of free connection slots.

◆ unsubscribe_advertisements()

void esphome::api::BluetoothProxy::unsubscribe_advertisements ( ) const

Stop receiving BLE advertisements.

◆ write() [1/2]

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.

◆ write() [2/2]

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.


The documentation for this class was generated from the following file: