|
JBHaMqttDiscovery
|
Abstract MQTT transport interface. More...
#include <MqttTransport.h>
Public Member Functions | |
| virtual bool | connected () const =0 |
| Check whether the MQTT client is currently connected. | |
| virtual bool | publish (const char *topic, const uint8_t *payload, size_t len, bool retained, uint8_t qos)=0 |
| Publish an MQTT message. | |
| virtual void | setOnConnect (void(*cb)(void *), void *ctx)=0 |
| Register a callback invoked when the MQTT connection is established. | |
| virtual void | setServer (const char *host, uint16_t port, const char *user=nullptr, const char *pass=nullptr)=0 |
| Set MQTT server and credentials. | |
| virtual void | setServer (const std::string &host, uint16_t port, const std::string &user="", const std::string &pass="")=0 |
| Set MQTT server and credentials (std::string version). | |
| virtual void | tick () |
| Periodic processing hook (optional). | |
| void | setLogger (JBLogger *logger) |
| Set the logger for this transport. | |
Protected Attributes | |
| JBLogger * | log = nullptr |
Abstract MQTT transport interface.
This interface decouples the Home Assistant Discovery logic from the underlying MQTT client implementation.
It supports both:
The transport is responsible only for:
It does NOT:
|
pure virtual |
Check whether the MQTT client is currently connected.
Implemented in AsyncMqttClientTransport, and PubSubClientTransport.
|
pure virtual |
Publish an MQTT message.
| topic | MQTT topic (null-terminated string) |
| payload | Pointer to payload bytes (may be nullptr) |
| len | Payload length in bytes |
| retained | Whether the message should be retained |
| qos | Requested QoS level (best-effort for some clients) |
Implemented in AsyncMqttClientTransport, and PubSubClientTransport.
|
inline |
Set the logger for this transport.
| logger | Pointer to a JBLogger instance. |
|
pure virtual |
Register a callback invoked when the MQTT connection is established.
For asynchronous transports, this is wired directly to the MQTT client's onConnect handler.
For synchronous transports, this callback is invoked when a rising-edge connection transition is detected via tick().
| cb | Callback function |
| ctx | User context pointer passed back to the callback |
Implemented in AsyncMqttClientTransport, and PubSubClientTransport.
|
pure virtual |
Set MQTT server and credentials.
| host | MQTT host/IP |
| port | MQTT port |
| user | MQTT username (optional) |
| pass | MQTT password (optional) |
Implemented in AsyncMqttClientTransport, and PubSubClientTransport.
|
pure virtual |
Set MQTT server and credentials (std::string version).
| host | MQTT host/IP |
| port | MQTT port |
| user | MQTT username |
| pass | MQTT password |
Implemented in AsyncMqttClientTransport, and PubSubClientTransport.
|
inlinevirtual |
Periodic processing hook (optional).
This is required only for synchronous MQTT clients that do not provide a native connection callback.
The host firmware should call this regularly (e.g. from loop()) if using such a transport.
Reimplemented in PubSubClientTransport.