Microchip® Advanced Software Framework

pahomqtt/MQTTClient/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,
  QOS0 = 0,
  QOS1 = 1,
  QOS2 = 2
}
 
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 
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 
)
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, len, MQTTSerialize_disconnect(), sendPacket(), TimerCountdownMS(), and TimerInit().

Referenced by aws_iot_mqtt_disconnect(), handleDisconnect(), and 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, len, 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 aws_iot_mqtt_publish(), and mqtt_publish().

DLLExport int MQTTSubscribe ( MQTTClient client,
const char *  topicFilter,
enum  QoS,
messageHandler   
)
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, len, MQTTDeserialize_unsuback(), MQTTSerialize_unsubscribe(), MQTTString_initializer, MQTTClient::readbuf, MQTTClient::readbuf_size, sendPacket(), SUCCESS, TimerCountdownMS(), TimerInit(), UNSUBACK, and waitfor().

Referenced by aws_iot_mqtt_unsubscribe(), and 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 aws_iot_mqtt_yield(), and 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().