Microchip® Advanced Software Framework

MQTTClient.c File Reference
#include "MQTTClient.h"

Functions

int cycle (MQTTClient *c, Timer *timer)
 
static int decodePacket (MQTTClient *c, int *value, int timeout)
 
int deliverMessage (MQTTClient *c, MQTTString *topicName, MQTTMessage *message)
 
static int getNextPacketId (MQTTClient *c)
 
static char isTopicMatched (char *topicFilter, MQTTString *topicName)
 
int keepalive (MQTTClient *c)
 
void MQTTClientInit (MQTTClient *c, 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...
 
int MQTTConnect (MQTTClient *c, 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...
 
int MQTTDisconnect (MQTTClient *c)
 MQTT Disconnect - send an MQTT disconnect packet and close the connection. More...
 
int MQTTPublish (MQTTClient *c, const char *topicName, MQTTMessage *message)
 MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs. More...
 
void MQTTRun (void *parm)
 
int MQTTSubscribe (MQTTClient *c, const char *topicFilter, enum QoS qos, messageHandler msgHandler)
 MQTT Subscribe - send an MQTT subscribe packet and wait for suback before returning. More...
 
int MQTTUnsubscribe (MQTTClient *c, const char *topicFilter)
 MQTT Subscribe - send an MQTT unsubscribe packet and wait for unsuback before returning. More...
 
int MQTTYield (MQTTClient *c, int timeout_ms)
 MQTT Yield - MQTT background. More...
 
static void NewMessageData (MessageData *md, MQTTString *aTopicName, MQTTMessage *aMessage)
 
static int readPacket (MQTTClient *c, Timer *timer)
 
static int sendPacket (MQTTClient *c, int length, Timer *timer)
 
int waitfor (MQTTClient *c, int packet_type, Timer *timer)
 

static int decodePacket ( MQTTClient c,
int *  value,
int  timeout 
)
static
static int getNextPacketId ( MQTTClient c)
static
static char isTopicMatched ( char *  topicFilter,
MQTTString topicName 
)
static
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 
)
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().

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().

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().

void MQTTRun ( void *  parm)
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().

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().

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().

static void NewMessageData ( MessageData md,
MQTTString aTopicName,
MQTTMessage aMessage 
)
static
int waitfor ( MQTTClient c,
int  packet_type,
Timer timer 
)