Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::CallbackMQTTDevice Class Reference

#include <CallbackMQTTDevice.h>

Inheritance diagram for uniot::CallbackMQTTDevice:
[legend]

Public Types

using Handler = std::function<void(MQTTDevice *device, const String &topic, const Bytes &payload)>
 Function type for MQTT message handlers.
 

Public Member Functions

 CallbackMQTTDevice (Handler handler)
 Constructs a CallbackMQTTDevice with the specified message handler.
 
- Public Member Functions inherited from uniot::MQTTDevice
 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

void handle (const String &topic, const Bytes &payload) override
 Handles incoming MQTT messages by delegating to the callback function.
 

Protected Attributes

Handler mHandler
 The user-provided message handler function.
 

Member Typedef Documentation

◆ Handler

using uniot::CallbackMQTTDevice::Handler = std::function<void(MQTTDevice *device, const String &topic, const Bytes &payload)>

Function type for MQTT message handlers.

Parameters
devicePointer to the MQTT device that received the message
topicThe MQTT topic the message was received on
payloadThe message payload as bytes

Constructor & Destructor Documentation

◆ CallbackMQTTDevice()

uniot::CallbackMQTTDevice::CallbackMQTTDevice ( Handler handler)
inline

Constructs a CallbackMQTTDevice with the specified message handler.

Parameters
handlerThe callback function that will process incoming MQTT messages

Member Function Documentation

◆ handle()

void uniot::CallbackMQTTDevice::handle ( const String & topic,
const Bytes & payload )
inlineoverrideprotectedvirtual

Handles incoming MQTT messages by delegating to the callback function.

This method overrides the base class implementation to log the topic and invoke the user-provided handler function.

Parameters
topicThe MQTT topic the message was received on
payloadThe message payload as bytes

Implements uniot::MQTTDevice.

Member Data Documentation

◆ mHandler

Handler uniot::CallbackMQTTDevice::mHandler
protected

The user-provided message handler function.


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