#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) |
int cycle | ( | MQTTClient * | c, |
Timer * | timer | ||
) |
References MQTTClient::buf, MQTTClient::buf_size, CONNACK, deliverMessage(), MQTTMessage::dup, FAILURE, MQTTMessage::id, keepalive(), MQTTDeserialize_ack(), MQTTDeserialize_publish(), MQTTSerialize_ack(), MQTTMessage::payload, MQTTMessage::payloadlen, MQTTClient::ping_outstanding, PINGRESP, PUBACK, PUBCOMP, PUBLISH, PUBREC, PUBREL, MQTTMessage::qos, QOS0, QOS1, QOS2, MQTTClient::readbuf, MQTTClient::readbuf_size, readPacket(), MQTTMessage::retained, sendPacket(), SUBACK, and SUCCESS.
Referenced by MQTTRun(), MQTTYield(), and waitfor().
|
static |
References i, MQTTClient::ipstack, MAX_NO_OF_REMAINING_LENGTH_BYTES, MQTTPACKET_READ_ERROR, and Network_t::mqttread.
Referenced by readPacket().
int deliverMessage | ( | MQTTClient * | c, |
MQTTString * | topicName, | ||
MQTTMessage * | message | ||
) |
|
static |
References MAX_PACKET_ID, and MQTTClient::next_packetid.
Referenced by MQTTPublish(), MQTTSubscribe(), and MQTTUnsubscribe().
|
static |
References MQTTLenString::data, MQTTLenString::len, and MQTTString::lenstring.
Referenced by deliverMessage().
int keepalive | ( | MQTTClient * | c | ) |
References MQTTClient::buf, MQTTClient::buf_size, FAILURE, MQTTClient::keepAliveInterval, MQTTSerialize_pingreq(), MQTTClient::ping_outstanding, MQTTClient::ping_timer, sendPacket(), SUCCESS, TimerCountdownMS(), TimerInit(), and TimerIsExpired().
Referenced by cycle().
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.
client | |
network | |
command_timeout_ms | |
References MQTTClient::buf, MQTTClient::buf_size, MQTTClient::command_timeout_ms, MQTTClient::defaultMessageHandler, i, MQTTClient::ipstack, MQTTClient::isconnected, MAX_MESSAGE_HANDLERS, MQTTClient::messageHandlers, MQTTClient::next_packetid, NULL, MQTTClient::ping_outstanding, MQTTClient::ping_timer, MQTTClient::readbuf, MQTTClient::readbuf_size, TimerInit(), and MQTTClient::MessageHandlers::topicFilter.
Referenced by mqtt_init().
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.
options | - connect options |
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.
client | - the client object to use |
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.
client | - the client object to use |
topic | - the topic to publish to |
message | - the message to send |
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 | ) |
References cycle(), TimerCountdownMS(), and TimerInit().
int MQTTSubscribe | ( | MQTTClient * | client, |
const char * | topicFilter, | ||
enum | QoS, | ||
messageHandler | |||
) |
MQTT Subscribe - send an MQTT subscribe packet and wait for suback before returning.
client | - the client object to use |
topicFilter | - the topic filter to subscribe to |
message | - the message to send |
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.
client | - the client object to use |
topicFilter | - the topic filter to unsubscribe from |
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.
client | - the client object to use |
time | - the time, in milliseconds, to yield for |
References cycle(), FAILURE, SUCCESS, TimerCountdownMS(), TimerInit(), and TimerIsExpired().
Referenced by mqtt_yield().
|
static |
References MessageData::message, and MessageData::topicName.
Referenced by deliverMessage().
|
static |
References MQTTHeader::bits, MQTTHeader::byte, decodePacket(), FAILURE, header, MQTTClient::ipstack, MQTTPacket_encode(), Network_t::mqttread, MQTTClient::readbuf, TimerLeftMS(), and MQTTHeader::type.
Referenced by cycle().
|
static |
References MQTTClient::buf, FAILURE, MQTTClient::ipstack, MQTTClient::keepAliveInterval, Network_t::mqttwrite, MQTTClient::ping_timer, SUCCESS, TimerCountdown(), TimerIsExpired(), and TimerLeftMS().
Referenced by cycle(), keepalive(), MQTTConnect(), MQTTDisconnect(), MQTTPublish(), MQTTSubscribe(), and MQTTUnsubscribe().
int waitfor | ( | MQTTClient * | c, |
int | packet_type, | ||
Timer * | timer | ||
) |
References cycle(), FAILURE, and TimerIsExpired().
Referenced by MQTTConnect(), MQTTPublish(), MQTTSubscribe(), and MQTTUnsubscribe().