Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::MQTTDevice Class Referenceabstract

#include <MQTTDevice.h>

Inheritance diagram for uniot::MQTTDevice:
[legend]

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
 

Constructor & Destructor Documentation

◆ MQTTDevice()

uniot::MQTTDevice::MQTTDevice ( )
inline

Constructs a new MQTTDevice instance.

◆ ~MQTTDevice()

uniot::MQTTDevice::~MQTTDevice ( )
virtual

Virtual destructor that handles cleanup and unregistration from MQTTKit.

Member Function Documentation

◆ getDeviceId()

const String & uniot::MQTTDevice::getDeviceId ( ) const

Gets the device identifier.

Return values
deviceId&A reference to the device ID string
sEmptyStringEmpty string if not connected to a kit.

◆ getOwnerId()

const String & uniot::MQTTDevice::getOwnerId ( ) const

Gets the owner identifier.

Return values
ownerId&A reference to the owner ID string
sEmptyStringEmpty string if not connected to a kit.

◆ handle()

virtual void uniot::MQTTDevice::handle ( const String & topic,
const Bytes & payload )
protectedpure virtual

Handles incoming MQTT messages.

Parameters
topicThe topic the message was received on.
payloadThe message payload.

Implementing classes must override this to process incoming messages.

Implemented in uniot::CallbackMQTTDevice, uniot::LispDevice, and uniot::TopDevice.

◆ isSubscribed()

bool uniot::MQTTDevice::isSubscribed ( const String & topic)

Checks if the device is subscribed to a given topic.

Parameters
topicThe topic to check for subscription.
Return values
trueThe device is subscribed to the topic.
falseThe device is not subscribed to the topic.

◆ isTopicMatch()

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.

Parameters
storedTopicThe topic string with possible wildcards (+ or #) the device is subscribed to.
incomingTopicThe concrete topic string from an incoming message.
Return values
trueThe topics match.
falseThe topics do not match.

◆ publish()

void uniot::MQTTDevice::publish ( const String & topic,
const Bytes & payload,
bool retained = false,
bool sign = false )

Publishes a message to a specific topic.

Parameters
topicThe complete topic to publish to.
payloadThe message payload.
retainedWhether the message should be retained by the broker.
signWhether to cryptographically sign the message.

◆ publishDevice()

void uniot::MQTTDevice::publishDevice ( const String & subTopic,
const Bytes & payload,
bool retained = false,
bool sign = false )

Publishes a message to a device-specific subtopic.

Parameters
subTopicThe subtopic to append to the device base path.
payloadThe message payload.
retainedWhether the message should be retained by the broker.
signWhether to cryptographically sign the message.

◆ publishEmptyDevice()

void uniot::MQTTDevice::publishEmptyDevice ( const String & subTopic)

Publishes an empty message to a device-specific subtopic with retained flag set.

Parameters
subTopicThe subtopic to append to the device base path.

This is commonly used to clear retained messages from the broker.

◆ publishGroup()

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.

Parameters
groupIdThe identifier of the group to publish to.
subTopicThe subtopic to append to the group base path.
payloadThe message payload.
retainedWhether the message should be retained by the broker.
signWhether to cryptographically sign the message.

◆ subscribe()

const String & uniot::MQTTDevice::subscribe ( const String & topic)

Subscribes to a specific MQTT topic.

Parameters
topicThe complete MQTT topic string to subscribe to.
Return values
String&Reference to the stored topic string.

◆ subscribeDevice()

const String & uniot::MQTTDevice::subscribeDevice ( const String & subTopic)

Subscribes to a device-specific subtopic.

Parameters
subTopicThe subtopic to append to the device base path.
Return values
String&A reference to the stored topic string.
sEmptyStringEmpty string if not connected to a kit.

◆ subscribeGroup()

const String & uniot::MQTTDevice::subscribeGroup ( const String & groupId,
const String & subTopic )

Subscribes to a group-specific subtopic.

Parameters
groupIdThe identifier of the group to subscribe to.
subTopicThe subtopic to append to the group base path.
Return values
String&A reference to the stored topic string.
sEmptyStringEmpty string if not connected to a kit.

◆ syncSubscriptions()

virtual void uniot::MQTTDevice::syncSubscriptions ( )
pure virtual

Reconstructs subscriptions after reconnection or credential changes.

Implementing classes should override this to set up all required subscriptions.

Note
Subscriptions that depend on credentials should be reconstructed here

Implemented in uniot::LispDevice, and uniot::TopDevice.

◆ unsubscribe()

bool uniot::MQTTDevice::unsubscribe ( const String & topic)

Unsubscribes from a specific topic.

Parameters
topicThe topic to unsubscribe from.
Return values
trueSuccessfully unsubscribed.
falseFailed to unsubscribe (e.g., not subscribed).

◆ unsubscribeFromAll()

void uniot::MQTTDevice::unsubscribeFromAll ( )

Unsubscribes from all subscribed topics.

Friends And Related Symbol Documentation

◆ MQTTKit

friend class MQTTKit
friend

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