MQTTKit
The MQTTKit
class manages connections to the MQTT broker, oversees multiple MQTTDevice
instances, handles message publishing and subscribing, and ensures secure and efficient communication through COSE message handling. By integrating with network and time synchronization events, MQTTKit
provides a robust and reliable foundation for MQTT-based interactions.
Methods:
MQTTKit(const Credentials &credentials, CBORExtender infoExtender = nullptr)
Constructs anMQTTKit
instance with the specified credentials and an optional CBOR extender for additional information.credentials
(const Credentials &
): Reference to aCredentials
object containing device and owner identifiers.infoExtender
(CBORExtender
, optional): A function to extend CBOR messages with additional information.
~MQTTKit()
Destructs theMQTTKit
instance, handling cleanup and deregistration of all associated devices.void setServer(const char *domain, uint16_t port)
Sets the MQTT broker server's domain and port for establishing connections.void addDevice(MQTTDevice &device)
Registers anMQTTDevice
instance with theMQTTKit
, enabling it to participate in MQTT communications.void removeDevice(MQTTDevice &device)
Deregisters anMQTTDevice
instance from theMQTTKit
, removing it from MQTT communications.const MQTTPath &getPath()
Retrieves theMQTTPath
instance used for constructing MQTT topic paths.void renewSubscriptions()
Re-subscribes all registered devices to their respective MQTT topics, ensuring that subscriptions are up-to-date.virtual void pushTo(TaskScheduler &scheduler) override
Integrates theMQTTKit
's MQTT task with the provided task scheduler, enabling periodic execution of MQTT operations.virtual void attach() override
Placeholder method for attaching theMQTTKit
to the scheduler or system. Currently not implemented.virtual void onEventReceived(unsigned int topic, int msg) override
Handles events received by theMQTTKit
, such as network connectivity changes and time synchronization events, to manage MQTT connection cycles.
Private Members:
const Credentials *mpCredentials
Pointer to theCredentials
object containing device and owner identifiers.MQTTPath mPath
Instance ofMQTTPath
used for constructing MQTT topic paths based on credentials.CBORExtender mInfoExtender
Function pointer for extending CBOR messages with additional information.PubSubClient mPubSubClient
Instance of thePubSubClient
library used for MQTT communications.bool mNetworkConnected
Flag indicating the current network connection status.int mConnectionId
Identifier for tracking MQTT connection attempts and sessions.WiFiClient mWiFiClient
WiFi client instance used for establishing network connections.ClearQueue<MQTTDevice *> mDevices
Queue managing all registeredMQTTDevice
instances.TaskScheduler::TaskPtr mTaskMQTT
Pointer to the scheduled MQTT task responsible for managing MQTT operations.
Last updated