![]() |
|
Uniot Core
|
| 0.8.1 |
#include <MQTTDevice.h>
Public Member Functions | |
| MQTTDevice () | |
| Constructs a new MQTTDevice instance. | |
| virtual | ~MQTTDevice () |
| Virtual destructor that handles cleanup and unregistration from MQTTKit. | |
| const String & | getDeviceId () const |
| Gets the device identifier. | |
| const String & | getOwnerId () const |
| Gets the owner identifier. | |
| const String & | subscribe (const String &topic) |
| Subscribes to a specific MQTT topic. | |
| const String & | subscribeDevice (const String &subTopic) |
| Subscribes to a device-specific subtopic. | |
| const String & | subscribeGroup (const String &groupId, const String &subTopic) |
| Subscribes to a group-specific subtopic. | |
| bool | unsubscribe (const String &topic) |
| Unsubscribes from a specific topic. | |
| virtual void | syncSubscriptions ()=0 |
| Reconstructs subscriptions after reconnection or credential changes. | |
| void | unsubscribeFromAll () |
| Unsubscribes from all subscribed topics. | |
| bool | isSubscribed (const String &topic) |
| Checks if the device is subscribed to a given topic. | |
| bool | isTopicMatch (const String &storedTopic, const String &incomingTopic) const |
| Determines if a stored topic matches an incoming topic string using MQTT wildcards. | |
| void | publish (const String &topic, const Bytes &payload, bool retained=false, bool sign=false) |
| Publishes a message to a specific topic. | |
| void | publishDevice (const String &subTopic, const Bytes &payload, bool retained=false, bool sign=false) |
| Publishes a message to a device-specific subtopic. | |
| void | publishGroup (const String &groupId, const String &subTopic, const Bytes &payload, bool retained=false, bool sign=false) |
| Publishes a message to a group-specific subtopic. | |
| void | publishEmptyDevice (const String &subTopic) |
| Publishes an empty message to a device-specific subtopic with retained flag set. | |
Protected Member Functions | |
| virtual void | handle (const String &topic, const Bytes &payload)=0 |
| Handles incoming MQTT messages. | |
Friends | |
| class | MQTTKit |
|
inline |
Constructs a new MQTTDevice instance.
|
virtual |
Virtual destructor that handles cleanup and unregistration from MQTTKit.
| const String & uniot::MQTTDevice::getDeviceId | ( | ) | const |
Gets the device identifier.
| deviceId& | A reference to the device ID string |
| sEmptyString | Empty string if not connected to a kit. |
| const String & uniot::MQTTDevice::getOwnerId | ( | ) | const |
Gets the owner identifier.
| ownerId& | A reference to the owner ID string |
| sEmptyString | Empty string if not connected to a kit. |
|
protectedpure virtual |
Handles incoming MQTT messages.
| topic | The topic the message was received on. |
| payload | The message payload. |
Implementing classes must override this to process incoming messages.
Implemented in uniot::CallbackMQTTDevice, uniot::LispDevice, and uniot::TopDevice.
| bool uniot::MQTTDevice::isSubscribed | ( | const String & | topic | ) |
Checks if the device is subscribed to a given topic.
| topic | The topic to check for subscription. |
| true | The device is subscribed to the topic. |
| false | The device is not subscribed to the topic. |
| bool uniot::MQTTDevice::isTopicMatch | ( | const String & | storedTopic, |
| const String & | incomingTopic ) const |
Determines if a stored topic matches an incoming topic string using MQTT wildcards.
Implements MQTT topic matching with support for + (single-level) and # (multi-level) wildcards.
| storedTopic | The topic string with possible wildcards (+ or #) the device is subscribed to. |
| incomingTopic | The concrete topic string from an incoming message. |
| true | The topics match. |
| false | The topics do not match. |
| void uniot::MQTTDevice::publish | ( | const String & | topic, |
| const Bytes & | payload, | ||
| bool | retained = false, | ||
| bool | sign = false ) |
Publishes a message to a specific topic.
| topic | The complete topic to publish to. |
| payload | The message payload. |
| retained | Whether the message should be retained by the broker. |
| sign | Whether to cryptographically sign the message. |
| void uniot::MQTTDevice::publishDevice | ( | const String & | subTopic, |
| const Bytes & | payload, | ||
| bool | retained = false, | ||
| bool | sign = false ) |
Publishes a message to a device-specific subtopic.
| subTopic | The subtopic to append to the device base path. |
| payload | The message payload. |
| retained | Whether the message should be retained by the broker. |
| sign | Whether to cryptographically sign the message. |
| void uniot::MQTTDevice::publishEmptyDevice | ( | const String & | subTopic | ) |
Publishes an empty message to a device-specific subtopic with retained flag set.
| subTopic | The subtopic to append to the device base path. |
This is commonly used to clear retained messages from the broker.
| void uniot::MQTTDevice::publishGroup | ( | const String & | groupId, |
| const String & | subTopic, | ||
| const Bytes & | payload, | ||
| bool | retained = false, | ||
| bool | sign = false ) |
Publishes a message to a group-specific subtopic.
| groupId | The identifier of the group to publish to. |
| subTopic | The subtopic to append to the group base path. |
| payload | The message payload. |
| retained | Whether the message should be retained by the broker. |
| sign | Whether to cryptographically sign the message. |
| const String & uniot::MQTTDevice::subscribe | ( | const String & | topic | ) |
Subscribes to a specific MQTT topic.
| topic | The complete MQTT topic string to subscribe to. |
| String& | Reference to the stored topic string. |
| const String & uniot::MQTTDevice::subscribeDevice | ( | const String & | subTopic | ) |
Subscribes to a device-specific subtopic.
| subTopic | The subtopic to append to the device base path. |
| String& | A reference to the stored topic string. |
| sEmptyString | Empty string if not connected to a kit. |
| const String & uniot::MQTTDevice::subscribeGroup | ( | const String & | groupId, |
| const String & | subTopic ) |
Subscribes to a group-specific subtopic.
| groupId | The identifier of the group to subscribe to. |
| subTopic | The subtopic to append to the group base path. |
| String& | A reference to the stored topic string. |
| sEmptyString | Empty string if not connected to a kit. |
|
pure virtual |
Reconstructs subscriptions after reconnection or credential changes.
Implementing classes should override this to set up all required subscriptions.
Implemented in uniot::LispDevice, and uniot::TopDevice.
| bool uniot::MQTTDevice::unsubscribe | ( | const String & | topic | ) |
Unsubscribes from a specific topic.
| topic | The topic to unsubscribe from. |
| true | Successfully unsubscribed. |
| false | Failed to unsubscribe (e.g., not subscribed). |
| void uniot::MQTTDevice::unsubscribeFromAll | ( | ) |
Unsubscribes from all subscribed topics.
|
friend |