Microchip® Advanced Software Framework

MQTTClient.h File Reference
#include "MQTTPacket/MQTTPacket.h"
#include "stdio.h"
#include "MQTTClient/Platforms/mqtt_platform.h"

Data Structures

struct  MessageData
 
struct  MQTTClient::MessageHandlers
 
struct  MQTTClient
 
struct  MQTTMessage
 

Macros

#define DefaultClient   {0, 0, 0, 0, NULL, NULL, 0, 0, 0}
 
#define DLLExport
 
#define DLLImport
 
#define MAX_MESSAGE_HANDLERS   5 /* redefinable - how many subscriptions do you want? */
 
#define MAX_PACKET_ID   65535 /* according to the MQTT specification - do not change! */
 

Typedefs

typedef struct MessageData MessageData
 
typedef void(* messageHandler )(MessageData *)
 
typedef struct MQTTClient MQTTClient
 
typedef struct MQTTMessage MQTTMessage
 

Enumerations

enum  QoS {
  QOS0,
  QOS1,
  QOS2
}
 
enum  returnCode {
  BUFFER_OVERFLOW = -2,
  FAILURE = -1,
  SUCCESS = 0
}
 

Functions

DLLExport void MQTTClientInit (MQTTClient *client, Network *network, unsigned int command_timeout_ms, unsigned char *sendbuf, size_t sendbuf_size, unsigned char *readbuf, size_t readbuf_size)
 Create an MQTT client object. More...
 
DLLExport int MQTTConnect (MQTTClient *client, 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. More...
 
DLLExport int MQTTDisconnect (MQTTClient *client)
 MQTT Disconnect - send an MQTT disconnect packet and close the connection. More...
 
DLLExport int MQTTPublish (MQTTClient *client, const char *, MQTTMessage *)
 MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs. More...
 
DLLExport int MQTTSubscribe (MQTTClient *client, const char *topicFilter, enum QoS, messageHandler)
 MQTT Subscribe - send an MQTT subscribe packet and wait for suback before returning. More...
 
DLLExport int MQTTUnsubscribe (MQTTClient *client, const char *topicFilter)
 MQTT Subscribe - send an MQTT unsubscribe packet and wait for unsuback before returning. More...
 
DLLExport int MQTTYield (MQTTClient *client, int time)
 MQTT Yield - MQTT background. More...
 
void TimerCountdown (Timer *, unsigned int)
 
void TimerCountdownMS (Timer *, unsigned int)
 
void TimerInit (Timer *)
 
char TimerIsExpired (Timer *)
 
int TimerLeftMS (Timer *)
 

#define DefaultClient   {0, 0, 0, 0, NULL, NULL, 0, 0, 0}
#define DLLExport
#define DLLImport
#define MAX_MESSAGE_HANDLERS   5 /* redefinable - how many subscriptions do you want? */
#define MAX_PACKET_ID   65535 /* according to the MQTT specification - do not change! */

Referenced by getNextPacketId().

typedef struct MessageData MessageData
typedef void(* messageHandler)(MessageData *)
typedef struct MQTTClient MQTTClient
typedef struct MQTTMessage MQTTMessage

enum QoS
Enumerator
QOS0 
QOS1 
QOS2 
enum returnCode
Enumerator
BUFFER_OVERFLOW 
FAILURE 
SUCCESS 

DLLExport void MQTTClientInit ( MQTTClient client,
Network network,
unsigned int  command_timeout_ms,
unsigned char *  sendbuf,
size_t  sendbuf_size,
unsigned char *  readbuf,
size_t  readbuf_size 
)
DLLExport int MQTTConnect ( MQTTClient client,
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

References MQTTClient::buf, MQTTClient::buf_size, MQTTClient::command_timeout_ms, CONNACK, FAILURE, MQTTClient::isconnected, MQTTPacket_connectData::keepAliveInterval, MQTTClient::keepAliveInterval, MQTTDeserialize_connack(), MQTTPacket_connectData_initializer, MQTTSerialize_connect(), MQTTClient::ping_timer, MQTTClient::readbuf, MQTTClient::readbuf_size, sendPacket(), SUCCESS, TimerCountdown(), TimerCountdownMS(), TimerInit(), and waitfor().

Referenced by mqtt_connect_broker().

DLLExport int MQTTDisconnect ( MQTTClient client)

MQTT Disconnect - send an MQTT disconnect packet and close the connection.

Parameters
client- the client object to use
Returns
success code

References MQTTClient::buf, MQTTClient::buf_size, MQTTClient::command_timeout_ms, FAILURE, MQTTClient::isconnected, MQTTSerialize_disconnect(), sendPacket(), TimerCountdownMS(), and TimerInit().

Referenced by mqtt_disconnect().

DLLExport int MQTTPublish ( MQTTClient client,
const char *  ,
MQTTMessage  
)

MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs.

Parameters
client- the client object to use
topic- the topic to publish to
message- the message to send
Returns
success code

References MQTTClient::buf, MQTTClient::buf_size, MQTTClient::command_timeout_ms, MQTTString::cstring, FAILURE, getNextPacketId(), MQTTMessage::id, MQTTClient::isconnected, MQTTDeserialize_ack(), MQTTSerialize_publish(), MQTTString_initializer, MQTTMessage::payload, MQTTMessage::payloadlen, PUBACK, PUBCOMP, MQTTMessage::qos, QOS1, QOS2, MQTTClient::readbuf, MQTTClient::readbuf_size, MQTTMessage::retained, sendPacket(), SUCCESS, TimerCountdownMS(), TimerInit(), and waitfor().

Referenced by mqtt_publish().

DLLExport int MQTTSubscribe ( MQTTClient client,
const char *  topicFilter,
enum  QoS,
messageHandler   
)

MQTT Subscribe - send an MQTT subscribe packet and wait for suback before returning.

Parameters
client- the client object to use
topicFilter- the topic filter to subscribe to
message- the message to send
Returns
success code

References MQTTClient::buf, MQTTClient::buf_size, MQTTClient::command_timeout_ms, count, MQTTString::cstring, FAILURE, MQTTClient::MessageHandlers::fp, getNextPacketId(), i, MQTTClient::isconnected, MAX_MESSAGE_HANDLERS, MQTTClient::messageHandlers, MQTTDeserialize_suback(), MQTTSerialize_subscribe(), MQTTString_initializer, MQTTClient::readbuf, MQTTClient::readbuf_size, sendPacket(), SUBACK, SUCCESS, TimerCountdownMS(), TimerInit(), MQTTClient::MessageHandlers::topicFilter, and waitfor().

Referenced by mqtt_subscribe().

DLLExport int MQTTUnsubscribe ( MQTTClient client,
const char *  topicFilter 
)

MQTT Subscribe - send an MQTT unsubscribe packet and wait for unsuback before returning.

Parameters
client- the client object to use
topicFilter- the topic filter to unsubscribe from
Returns
success code

References MQTTClient::buf, MQTTClient::buf_size, MQTTClient::command_timeout_ms, MQTTString::cstring, FAILURE, getNextPacketId(), MQTTClient::isconnected, MQTTDeserialize_unsuback(), MQTTSerialize_unsubscribe(), MQTTString_initializer, MQTTClient::readbuf, MQTTClient::readbuf_size, sendPacket(), SUCCESS, TimerCountdownMS(), TimerInit(), UNSUBACK, and waitfor().

Referenced by mqtt_unsubscribe().

DLLExport int MQTTYield ( MQTTClient client,
int  time 
)

MQTT Yield - MQTT background.

Parameters
client- the client object to use
time- the time, in milliseconds, to yield for
Returns
success code

References cycle(), FAILURE, SUCCESS, TimerCountdownMS(), TimerInit(), and TimerIsExpired().

Referenced by mqtt_yield().

void TimerCountdown ( Timer ,
unsigned  int 
)

References Timer::end_time, and MilliTimer.

Referenced by MQTTConnect(), and sendPacket().

void TimerCountdownMS ( Timer ,
unsigned  int 
)
char TimerIsExpired ( Timer )

References Timer::end_time, and MilliTimer.

Referenced by keepalive(), MQTTYield(), sendPacket(), and waitfor().

int TimerLeftMS ( Timer )

References Timer::end_time, and MilliTimer.

Referenced by readPacket(), and sendPacket().