The Cayenne MQTT mbed Library provides functions to easily connect to the Cayenne IoT project builder.
Dependents: Cayenne-ESP8266Interface Cayenne-WIZnet_Library Cayenne-WIZnetInterface Cayenne-X-NUCLEO-IDW01M1 ... more
Client< Network, Timer, MAX_MQTT_PACKET_SIZE, MAX_MESSAGE_HANDLERS > Class Template Reference
blocking, non-threaded MQTT client API More...
#include <MQTTClient.h>
Public Member Functions | |
Client (Network &network, unsigned int command_timeout_ms=30000) | |
Construct the client. | |
void | setDefaultMessageHandler (messageHandler mh) |
Set the default message handling callback - used for any message which does not match a subscription message handler. | |
template<class T > | |
void | setDefaultMessageHandler (T *item, void(T::*method)(MessageData &)) |
Set the default message handling callback - used for any message which does not match a subscription message handler. | |
int | connect () |
MQTT Connect - send an MQTT connect packet down the network and wait for a Connack The nework object must be connected to the network endpoint before calling this Default connect options are used. | |
int | connect (MQTTPacket_connectData &options) |
MQTT Connect - send an MQTT connect packet down the network and wait for a Connack The nework object must be connected to the network endpoint before calling this. | |
int | publish (const char *topicName, Message &message) |
MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs. | |
int | publish (const char *topicName, void *payload, size_t payloadlen, enum QoS qos=QOS0, bool retained=false) |
MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs. | |
int | publish (const char *topicName, void *payload, size_t payloadlen, unsigned short &id, enum QoS qos=QOS1, bool retained=false) |
MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs. | |
int | subscribe (const char *topicFilter, enum QoS qos, messageHandler mh) |
MQTT Subscribe - send an MQTT subscribe packet and wait for the suback. | |
int | unsubscribe (const char *topicFilter) |
MQTT Unsubscribe - send an MQTT unsubscribe packet and wait for the unsuback. | |
int | disconnect () |
MQTT Disconnect - send an MQTT disconnect packet, and clean up any state. | |
int | yield (unsigned long timeout_ms=1000L) |
A call to this API must be made within the keepAlive interval to keep the MQTT connection alive yield can be called if no other MQTT operation is needed. | |
bool | isConnected () |
Is the client connected? |
Detailed Description
template<class Network, class Timer, int MAX_MQTT_PACKET_SIZE = 100, int MAX_MESSAGE_HANDLERS = 5>
class MQTT::Client< Network, Timer, MAX_MQTT_PACKET_SIZE, MAX_MESSAGE_HANDLERS >
blocking, non-threaded MQTT client API
This version of the API blocks on all method calls, until they are complete. This means that only one MQTT request can be in process at any one time.
- Parameters:
-
Network a network class with the methods: read, write. See NetworkInterface.h for function definitions. Timer a timer class with the methods: countdown_ms, countdown, left_ms, expired. See TimerInterface.h for function definitions.
Definition at line 98 of file MQTTClient.h.
Constructor & Destructor Documentation
Client | ( | Network & | network, |
unsigned int | command_timeout_ms = 30000 |
||
) |
Construct the client.
- Parameters:
-
network - pointer to an instance of the Network class - must be connected to the endpoint before calling MQTT connect limits an instance of the Limit class - to alter limits as required
Definition at line 301 of file MQTTClient.h.
Member Function Documentation
int connect | ( | ) |
MQTT Connect - send an MQTT connect packet down the network and wait for a Connack The nework object must be connected to the network endpoint before calling this Default connect options are used.
- Returns:
- success code -
Reimplemented in MQTTClient< Network, Timer, MAX_MQTT_PACKET_SIZE, MAX_MESSAGE_HANDLERS >.
Definition at line 813 of file MQTTClient.h.
int connect | ( | MQTTPacket_connectData & | options ) |
MQTT Connect - send an MQTT connect packet down the network and wait for a Connack The nework object must be connected to the network endpoint before calling this.
- Parameters:
-
options - connect options
- Returns:
- success code -
Definition at line 755 of file MQTTClient.h.
int disconnect | ( | ) |
MQTT Disconnect - send an MQTT disconnect packet, and clean up any state.
- Returns:
- success code -
Reimplemented in MQTTClient< Network, Timer, MAX_MQTT_PACKET_SIZE, MAX_MESSAGE_HANDLERS >.
Definition at line 1018 of file MQTTClient.h.
bool isConnected | ( | ) |
Is the client connected?
- Returns:
- flag - is the client connected or not?
Definition at line 202 of file MQTTClient.h.
int publish | ( | const char * | topicName, |
Message & | message | ||
) |
MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs.
- Parameters:
-
topic - the topic to publish to message - the message to send
- Returns:
- success code -
Definition at line 1011 of file MQTTClient.h.
int publish | ( | const char * | topicName, |
void * | payload, | ||
size_t | payloadlen, | ||
enum QoS | qos = QOS0 , |
||
bool | retained = false |
||
) |
MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs.
- Parameters:
-
topic - the topic to publish to payload - the data to send payloadlen - the length of the data qos - the QoS to send the publish at retained - whether the message should be retained
- Returns:
- success code -
Definition at line 1003 of file MQTTClient.h.
int publish | ( | const char * | topicName, |
void * | payload, | ||
size_t | payloadlen, | ||
unsigned short & | id, | ||
enum QoS | qos = QOS1 , |
||
bool | retained = false |
||
) |
MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs.
- Parameters:
-
topic - the topic to publish to payload - the data to send payloadlen - the length of the data id - the packet id used - returned qos - the QoS to send the publish at retained - whether the message should be retained
- Returns:
- success code -
Definition at line 961 of file MQTTClient.h.
void setDefaultMessageHandler | ( | T * | item, |
void(T::*)(MessageData &) | method | ||
) |
Set the default message handling callback - used for any message which does not match a subscription message handler.
- Parameters:
-
time - address of initialized object mh - pointer to the callback function
Definition at line 125 of file MQTTClient.h.
void setDefaultMessageHandler | ( | messageHandler | mh ) |
Set the default message handling callback - used for any message which does not match a subscription message handler.
- Parameters:
-
mh - pointer to the callback function
Reimplemented in MQTTClient< Network, Timer, MAX_MQTT_PACKET_SIZE, MAX_MESSAGE_HANDLERS >.
Definition at line 115 of file MQTTClient.h.
int subscribe | ( | const char * | topicFilter, |
enum QoS | qos, | ||
messageHandler | mh | ||
) |
MQTT Subscribe - send an MQTT subscribe packet and wait for the suback.
- Parameters:
-
topicFilter - a topic pattern which can include wildcards qos - the MQTT QoS to subscribe at mh - the callback function to be invoked when a message is received for this subscription
- Returns:
- success code -
Definition at line 821 of file MQTTClient.h.
int unsubscribe | ( | const char * | topicFilter ) |
MQTT Unsubscribe - send an MQTT unsubscribe packet and wait for the unsuback.
- Parameters:
-
topicFilter - a topic pattern which can include wildcards
- Returns:
- success code -
Definition at line 868 of file MQTTClient.h.
int yield | ( | unsigned long | timeout_ms = 1000L ) |
A call to this API must be made within the keepAlive interval to keep the MQTT connection alive yield can be called if no other MQTT operation is needed.
This will also allow messages to be received.
- Parameters:
-
timeout_ms the time to wait, in milliseconds
- Returns:
- success code - on failure, this means the client has disconnected
Reimplemented in MQTTClient< Network, Timer, MAX_MQTT_PACKET_SIZE, MAX_MESSAGE_HANDLERS >.
Definition at line 525 of file MQTTClient.h.
Generated on Wed Jul 13 2022 15:49:29 by 1.7.2