An API for using MQTT over multiple transports

Dependencies:   FP MQTTPacket

Dependents:   IBMIoTClientEthernetExample_W5500 IBMIoTClientEthernetExample_W5200

Fork of MQTT by MQTT

Embed: (wiki syntax)

« Back to documentation index

Client< Network, Timer, MAX_MQTT_PACKET_SIZE, MAX_MESSAGE_HANDLERS > Class Template Reference

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.
int connect (MQTTPacket_connectData *options=0)
 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 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 (int timeout_ms=1000)
 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.

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:
Networka network class which supports send, receive
Timera timer class with the methods:

Definition at line 104 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
limitsan instance of the Limit class - to alter limits as required

Definition at line 222 of file MQTTClient.h.


Member Function Documentation

int connect ( MQTTPacket_connectData *  options = 0 )

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 524 of file MQTTClient.h.

int disconnect (  )

MQTT Disconnect - send an MQTT disconnect packet, and clean up any state.

Returns:
success code -

Definition at line 692 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 641 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

Definition at line 121 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 565 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 610 of file MQTTClient.h.

int yield ( int  timeout_ms = 1000 )

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_msthe time to wait, in milliseconds
Returns:
success code - on failure, this means the client has disconnected

Definition at line 388 of file MQTTClient.h.