MQTT Native API

Extensions

Functions

intmqttConnect(Mqtt *mq, cchar *username, cchar *password, int flags, MqttWaitFlags waitFlags)
 Establish a session with the MQTT broker.
cchar*mqttGetError(struct Mqtt *mq)
 Returns an error message for error code, error
intmqttMsgsInQueue(Mqtt *mq)
 Get the number of messages to send in the send queue.
intmqttMsgsToSend(Mqtt *mq)
 Get the number of messages in the queue.
intmqttPing(Mqtt *mq)
 Ping the broker.
intmqttPublish(Mqtt *mq, cvoid *msg, ssize size, int qos, MqttWaitFlags waitFlags, cchar *topic, ...)
 Publish an application message to the MQTT broker.
intmqttPublishRetained(Mqtt *mq, cvoid *msg, ssize size, int qos, MqttWaitFlags waitFlags, cchar *topic, ...)
 Publish a retained message to the MQTT broker.
voidmqttSetMessageSize(Mqtt *mq, int size)
 Set the maximum message size.
intmqttSubscribe(Mqtt *mq, MqttCallback callback, int maxQos, MqttWaitFlags waitFlags, cchar *topic, ...)
 Subscribe to a topic.
intmqttUnsubscribe(Mqtt *mq, cchar *topic, MqttWaitFlags wait)
 Unsubscribe from a topic.

Typedefs

MqttAn MQTT mq.
MqttCallbackSubscription callback.
MqttHdrFixed header of a packet.
MqttRespA struct used to deserialize/interpret an incoming packet from the broker.
MqttRespConnA connection response.
MqttRespPingThe resp to a ping request.
MqttRespPubA publish packet received from the broker.
MqttRespPubAckA publish acknowledgement for messages that were published with QoS level 1.
MqttRespPubCompThe resp to a PUBREL packet.
MqttRespPubRecThe resp packet to a PUBLISH packet with QoS level 2.
MqttRespPubRelThe resp to a PUBREC packet.
MqttRespSubAckThe resp to a subscription request.
MqttRespUnsubAckThe brokers resp to a UNSUBSCRIBE request.

Defines

#defineMQTT_PROTOCOL_LEVEL   0x04
 Protocol version.

Functions

int mqttConnect (Mqtt *mq, cchar *username, cchar *password, int flags, MqttWaitFlags waitFlags)

Establish a session with the MQTT broker.

Mqtt_init must have been called.
Parameters:
mqThe Mqtt object.
usernameThe username to use when establishing the session with the MQTT broker. Set to NULL if a username is not required.
passwordThe password to use when establishing the session with the MQTT broker. Set to NULL if a password is not required.
flagsAdditional MqttConnectFlags to use when establishing the connection. These flags are for forcing the session to start clean, MQTT_CONNECT_CLEAN_SESSION, the QOS level to publish the will_message with (provided will_message != NULL), MQTT_CONNECT_WILL_QOS_[0,1,2], and whether or not the broker should retain the will_message, MQTT_CONNECT_WILL_RETAIN.
waitFlagsWait flags.
Returns:
Zero if successful.
API Stability:
Evolving.
cchar * mqttGetError (struct Mqtt *mq)

Returns an error message for error code, error

Parameters:
mqMqtt object.
Returns:
The associated error message.
API Stability:
Evolving.
int mqttMsgsInQueue (Mqtt *mq)

Get the number of messages to send in the send queue.

Parameters:
mqThe MQTT mq.
Returns:
The number of messages in the queue to send.
API Stability:
Evolving.
int mqttMsgsToSend (Mqtt *mq)

Get the number of messages in the queue.

Parameters:
mqThe MQTT mq.
Returns:
The number of messages in the queue.
API Stability:
Evolving.
int mqttPing (Mqtt *mq)

Ping the broker.

MqttConnect must have been called.
Parameters:
mqThe MQTT mq.
Returns:
Zero if successful.
API Stability:
Evolving.
int mqttPublish (Mqtt *mq, cvoid *msg, ssize size, int qos, MqttWaitFlags waitFlags, cchar *topic, ...)

Publish an application message to the MQTT broker.

MqttConnect must have been called.
Parameters:
mqThe Mqtt object.
msgThe data to be published.
sizeThe size of application_message in bytes.
qosQuality of service. 0, 1, or 2.
waitFlagsWait flags.
topicPrintf style topic string.
...Topic args.
Returns:
Zero if successful.
int mqttPublishRetained (Mqtt *mq, cvoid *msg, ssize size, int qos, MqttWaitFlags waitFlags, cchar *topic, ...)

Publish a retained message to the MQTT broker.

MqttConnect must have been called.
Parameters:
mqThe Mqtt object.
msgThe data to be published.
sizeThe size of application_message in bytes.
qosQuality of service. 0, 1, or 2.
waitFlagsWait flags.
topicPrintf style topic string.
...Topic args.
Returns:
Zero if successful.
void mqttSetMessageSize (Mqtt *mq, int size)

Set the maximum message size.

Description:
AWS supports a smaller maximum message size.
Parameters:
mqThe MQTT mq.
sizeThe maximum message size.
API Stability:
Evolving.
int mqttSubscribe (Mqtt *mq, MqttCallback callback, int maxQos, MqttWaitFlags waitFlags, cchar *topic, ...)

Subscribe to a topic.

MqttConnect must have been called.
Parameters:
mqMqtt object.
callbackFunction to invoke on receipt of messages.
maxQosMaximum quality of service message to receive.
waitFlagsWait flags.
topicPrintf style topic string.
...Topic args.
Returns:
Zero if successful.
API Stability:
Evolving.
int mqttUnsubscribe (Mqtt *mq, cchar *topic, MqttWaitFlags wait)

Unsubscribe from a topic.

MqttConnect must have been called.
Parameters:
mqThe MQTT mq.
topicThe name of the topic to unsubscribe from.
waitWait flags.
Returns:
Zero if successful.
API Stability:
Evolving.

Typedefs

typedef void(* MqttCallback) (struct MqttRespPub *resp).

Subscription callback.

Parameters:
respMessage received structure.
API Stability:
Evolving.
Mqtt

An MQTT mq.

All members can be manipulated via the related functions.
Fields:
API Stability:
Evolving.
MqttHdr

Fixed header of a packet.

API Stability:
Evolving.
Fields:
intflags Packet control flags.
intlength Size in bytes.
MqttResp

A struct used to deserialize/interpret an incoming packet from the broker.

API Stability:
Evolving.
Fields:
MqttRespConn

A connection response.

API Stability:
Evolving.
Fields:
MqttConnCodecode Connection return code.
ucharhasSession Check if already have a session.
MqttRespPing

The resp to a ping request.

This resp contains no members.
Fields:
API Stability:
Evolving.
MqttRespPub

A publish packet received from the broker.

Description:
A publish packet is received from the broker when a mq publishes to a topic that the {local mq} is subscribed to.
Fields:
cvoid *data Message.
intdataSize Size of message.
MqttCallbackcallback Message callback function.
uchardup Set to 0 on first attempt to send packet.
char *fullTopic Full topic string.
uint16_tid Message ID.
struct Mqtt *mq Message queue.
ucharqos Quality of service.
ucharretain Message is retained.
cvoid *topic Topic string. Not null terminated.
uint16_ttopicSize Size of the topic.
API Stability:
Evolving.
MqttRespPubAck

A publish acknowledgement for messages that were published with QoS level 1.

API Stability:
Evolving.
Fields:
uint16_tid Message ID.
MqttRespPubComp

The resp to a PUBREL packet.

API Stability:
Evolving.
Fields:
uint16_tid Message ID.
MqttRespPubRec

The resp packet to a PUBLISH packet with QoS level 2.

API Stability:
Evolving.
Fields:
uint16_tid Message ID.
MqttRespPubRel

The resp to a PUBREC packet.

API Stability:
Evolving.
Fields:
uint16_tid Message ID.
MqttRespSubAck

The resp to a subscription request.

API Stability:
Evolving.
Fields:
cuchar *codes Array of return codes for subscribed topics.
uint16_tid Message ID.
intnumCodes Size of codes.
MqttRespUnsubAck

The brokers resp to a UNSUBSCRIBE request.

API Stability:
Evolving.
Fields:
uint16_tid Message ID.

© Embedthis Software. All rights reserved.