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

#include <MQTTKit.h>

Inheritance diagram for uniot::MQTTKit:
[legend]

Public Member Functions

 MQTTKit (const Credentials &credentials, CBORExtender infoExtender=nullptr)
 Constructs an MQTTKit instance.
 
 ~MQTTKit ()
 Destructor - cleans up event listeners.
 
void setServer (const char *domain, uint16_t port)
 Sets the MQTT broker server address and port.
 
void addDevice (MQTTDevice &device)
 Adds a device to be managed by this MQTT kit.
 
void removeDevice (MQTTDevice &device)
 Removes a device from this MQTT kit.
 
const MQTTPathgetPath ()
 Gets the MQTT path helper object.
 
void renewSubscriptions ()
 Renews all device subscriptions.
 
virtual void pushTo (TaskScheduler &scheduler) override
 Registers MQTT tasks with the provided scheduler.
 
virtual void attach () override
 Attaches this kit (empty implementation)
 
virtual void onEventReceived (unsigned int topic, int msg) override
 Handles network and time events.
 
- Public Member Functions inherited from uniot::ISchedulerConnectionKit
virtual ~ISchedulerConnectionKit ()
 Virtual destructor for proper cleanup.
 
- Public Member Functions inherited from uniot::EventListener< unsigned int, int, Bytes >
virtual ~EventListener ()=default
 Virtual destructor.
 
virtual type_id getTypeId () const override
 Get the type ID of this class for RTTI.
 
EventListenerlistenToEvent (unsigned int topic)
 Subscribe to events of a specific topic.
 
EventListenerstopListeningToEvent (unsigned int topic)
 Unsubscribe from events of a specific topic.
 
bool isListeningToEvent (unsigned int topic)
 Check if this listener is subscribed to a specific topic.
 
virtual ~EventListener ()=default
 Virtual destructor.
 
virtual type_id getTypeId () const override
 Get the type ID of this class for RTTI.
 
EventListenerlistenToEvent (unsigned int topic)
 Subscribe to events of a specific topic.
 
EventListenerstopListeningToEvent (unsigned int topic)
 Unsubscribe from events of a specific topic.
 
bool isListeningToEvent (unsigned int topic)
 Check if this listener is subscribed to a specific topic.
 
- Public Member Functions inherited from uniot::EventEmitter< unsigned int, int, Bytes >
virtual ~EventEmitter ()=default
 Virtual destructor to ensure proper cleanup of derived classes.
 
void emitEvent (unsigned int topic, int msg)
 Emits an event to all registered event buses.
 
virtual ~EventEmitter ()=default
 Virtual destructor to ensure proper cleanup of derived classes.
 
void emitEvent (unsigned int topic, int msg)
 Emits an event to all registered event buses.
 
- Public Member Functions inherited from uniot::EventEntity< T_topic, T_msg, T_data >
virtual ~EventEntity ()
 Destructor - disconnects from all connected EventBus instances.
 
bool sendDataToChannel (T_topic channel, T_data data)
 Sends data to a specific channel on all connected EventBus instances.
 
void receiveDataFromChannel (T_topic channel, DataChannelCallback callback)
 Receives data from a specific channel on all connected EventBus instances.
 

Protected Member Functions

PubSubClient * client ()
 Gets access to the underlying PubSubClient.
 
- Protected Member Functions inherited from uniot::EventEntity< T_topic, T_msg, T_data >
bool connectUnique (EventBus< T_topic, T_msg, T_data > *eventBus)
 Connects to an EventBus instance if not already connected.
 

Friends

class MQTTDevice
 

Additional Inherited Members

- Public Types inherited from uniot::EventEntity< T_topic, T_msg, T_data >
using DataChannelCallback = std::function<void(unsigned int, bool, T_data)>
 Callback type for handling data received from channels.
 
- Protected Attributes inherited from uniot::EventEntity< T_topic, T_msg, T_data >
IterableQueue< EventBus< T_topic, T_msg, T_data > * > mEventBusQueue
 Queue of EventBus instances this entity is connected to.
 

Constructor & Destructor Documentation

◆ MQTTKit()

uniot::MQTTKit::MQTTKit ( const Credentials & credentials,
CBORExtender infoExtender = nullptr )
inline

Constructs an MQTTKit instance.

Parameters
credentialsThe credentials to use for MQTT authentication
infoExtenderOptional callback to extend status messages with additional data

◆ ~MQTTKit()

uniot::MQTTKit::~MQTTKit ( )
inline

Destructor - cleans up event listeners.

Member Function Documentation

◆ addDevice()

void uniot::MQTTKit::addDevice ( MQTTDevice & device)
inline

Adds a device to be managed by this MQTT kit.

The device will be initialized with this kit and its topics will be subscribed

Parameters
deviceThe device to add

◆ attach()

virtual void uniot::MQTTKit::attach ( )
inlineoverridevirtual

Attaches this kit (empty implementation)

Implements uniot::ISchedulerConnectionKit.

◆ client()

PubSubClient * uniot::MQTTKit::client ( )
inlineprotected

Gets access to the underlying PubSubClient.

Return values
mPubSubClientThe underlying PubSubClient instance

◆ getPath()

const MQTTPath & uniot::MQTTKit::getPath ( )
inline

Gets the MQTT path helper object.

Return values
mPathThe MQTT path helper object

◆ onEventReceived()

virtual void uniot::MQTTKit::onEventReceived ( unsigned int topic,
int msg )
inlineoverridevirtual

Handles network and time events.

Handles network connection events to enable/disable MQTT connections and time synchronization events to initialize MQTT tasks

Parameters
topicThe event topic
msgThe event message

Implements uniot::EventListener< unsigned int, int, Bytes >.

◆ pushTo()

virtual void uniot::MQTTKit::pushTo ( TaskScheduler & scheduler)
inlineoverridevirtual

Registers MQTT tasks with the provided scheduler.

Parameters
schedulerThe scheduler to register tasks with

Implements uniot::ISchedulerConnectionKit.

◆ removeDevice()

void uniot::MQTTKit::removeDevice ( MQTTDevice & device)
inline

Removes a device from this MQTT kit.

The device will be detached from this kit and its topic subscriptions will be removed

Parameters
deviceThe device to remove

◆ renewSubscriptions()

void uniot::MQTTKit::renewSubscriptions ( )
inline

Renews all device subscriptions.

Unsubscribes from all topics and then resubscribes to ensure subscriptions are current

◆ setServer()

void uniot::MQTTKit::setServer ( const char * domain,
uint16_t port )
inline

Sets the MQTT broker server address and port.

Parameters
domainThe server domain name or IP address
portThe server port

Friends And Related Symbol Documentation

◆ MQTTDevice

friend class MQTTDevice
friend

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