mqtt_client.c File Reference

MQTT client. More...

Go to the source code of this file.

Macros

#define TRACE_LEVEL   MQTT_TRACE_LEVEL
 

Functions

error_t mqttClientInit (MqttClientContext *context)
 Initialize MQTT client context. More...
 
void mqttClientInitCallbacks (MqttClientCallbacks *callbacks)
 Initialize callback structure. More...
 
error_t mqttClientRegisterCallbacks (MqttClientContext *context, const MqttClientCallbacks *callbacks)
 Register MQTT client callbacks. More...
 
error_t mqttClientSetProtocolLevel (MqttClientContext *context, MqttProtocolLevel protocolLevel)
 Set the MQTT protocol version to be used. More...
 
error_t mqttClientSetTransportProtocol (MqttClientContext *context, MqttTransportProtocol transportProtocol)
 Set the transport protocol to be used. More...
 
error_t mqttClientSetTimeout (MqttClientContext *context, uint16_t timeout)
 Set communication timeout. More...
 
error_t mqttClientSetKeepAlive (MqttClientContext *context, uint16_t keepAlive)
 Set keep-alive value. More...
 
error_t mqttClientSetHost (MqttClientContext *context, const char_t *host)
 Set the hostname of the resource being requested. More...
 
error_t mqttClientSetUri (MqttClientContext *context, const char_t *uri)
 Set the name of the resource being requested. More...
 
error_t mqttClientSetIdentifier (MqttClientContext *context, const char_t *clientId)
 Set client identifier. More...
 
error_t mqttClientSetAuthInfo (MqttClientContext *context, const char_t *username, const char_t *password)
 Set authentication information. More...
 
error_t mqttClientSetWillMessage (MqttClientContext *context, const char_t *topic, const void *message, size_t length, MqttQosLevel qos, bool_t retain)
 Specify the Will message. More...
 
error_t mqttClientBindToInterface (MqttClientContext *context, NetInterface *interface)
 Bind the MQTT client to a particular network interface. More...
 
error_t mqttClientConnect (MqttClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort, bool_t cleanSession)
 Establish connection with the MQTT server. More...
 
error_t mqttClientPublish (MqttClientContext *context, const char_t *topic, const void *message, size_t length, MqttQosLevel qos, bool_t retain, uint16_t *packetId)
 Publish message. More...
 
error_t mqttClientSubscribe (MqttClientContext *context, const char_t *topic, MqttQosLevel qos, uint16_t *packetId)
 Subscribe to topic. More...
 
error_t mqttClientUnsubscribe (MqttClientContext *context, const char_t *topic, uint16_t *packetId)
 Unsubscribe from topic. More...
 
error_t mqttClientPing (MqttClientContext *context, systime_t *rtt)
 Send ping request. More...
 
error_t mqttClientDisconnect (MqttClientContext *context)
 Gracefully disconnect from the MQTT server. More...
 
error_t mqttClientClose (MqttClientContext *context)
 Close the connection with the MQTT server. More...
 
error_t mqttClientProcessEvents (MqttClientContext *context, systime_t timeout)
 Process MQTT client events. More...
 

Detailed Description

MQTT client.

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file mqtt_client.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   MQTT_TRACE_LEVEL

Definition at line 30 of file mqtt_client.c.

Function Documentation

◆ mqttClientBindToInterface()

error_t mqttClientBindToInterface ( MqttClientContext context,
NetInterface interface 
)

Bind the MQTT client to a particular network interface.

Parameters
[in]contextPointer to the MQTT client context
[in]interfaceNetwork interface to be used
Returns
Error code

Definition at line 397 of file mqtt_client.c.

◆ mqttClientClose()

error_t mqttClientClose ( MqttClientContext context)

Close the connection with the MQTT server.

Parameters
[in]contextPointer to the MQTT client context
Returns
Error code

Definition at line 1077 of file mqtt_client.c.

◆ mqttClientConnect()

error_t mqttClientConnect ( MqttClientContext context,
const IpAddr serverIpAddr,
uint16_t  serverPort,
bool_t  cleanSession 
)

Establish connection with the MQTT server.

Parameters
[in]contextPointer to the MQTT client context
[in]serverIpAddrIP address of the MQTT server to connect to
[in]serverPortTCP port number that will be used to establish the connection
[in]cleanSessionIf this flag is set, then the client and server must discard any previous session and start a new one
Returns
Error code

Definition at line 423 of file mqtt_client.c.

◆ mqttClientDisconnect()

error_t mqttClientDisconnect ( MqttClientContext context)

Gracefully disconnect from the MQTT server.

Parameters
[in]contextPointer to the MQTT client context
Returns
Error code

Definition at line 993 of file mqtt_client.c.

◆ mqttClientInit()

error_t mqttClientInit ( MqttClientContext context)

Initialize MQTT client context.

Parameters
[in]contextPointer to the MQTT client context
Returns
Error code

Definition at line 50 of file mqtt_client.c.

◆ mqttClientInitCallbacks()

void mqttClientInitCallbacks ( MqttClientCallbacks callbacks)

Initialize callback structure.

Parameters
[in]callbacksPointer to a structure that contains callback functions
Returns
Error code

Definition at line 101 of file mqtt_client.c.

◆ mqttClientPing()

error_t mqttClientPing ( MqttClientContext context,
systime_t rtt 
)

Send ping request.

Parameters
[in]contextPointer to the MQTT client context
[out]rttRound-trip time (optional parameter)
Returns
Error code

Definition at line 885 of file mqtt_client.c.

◆ mqttClientProcessEvents()

error_t mqttClientProcessEvents ( MqttClientContext context,
systime_t  timeout 
)

Process MQTT client events.

Parameters
[in]contextPointer to the MQTT client context
[in]timeoutMaximum time to wait before returning
Returns
Error code

Definition at line 1106 of file mqtt_client.c.

◆ mqttClientPublish()

error_t mqttClientPublish ( MqttClientContext context,
const char_t topic,
const void *  message,
size_t  length,
MqttQosLevel  qos,
bool_t  retain,
uint16_t *  packetId 
)

Publish message.

Parameters
[in]contextPointer to the MQTT client context
[in]topicTopic name
[in]messageMessage payload
[in]lengthLength of the message payload
[in]qosQoS level to be used when publishing the message
[in]retainThis flag specifies if the message is to be retained
[out]packetIdPacket identifier used to send the PUBLISH packet
Returns
Error code

Definition at line 559 of file mqtt_client.c.

◆ mqttClientRegisterCallbacks()

error_t mqttClientRegisterCallbacks ( MqttClientContext context,
const MqttClientCallbacks callbacks 
)

Register MQTT client callbacks.

Parameters
[in]contextPointer to the MQTT client context
[in]callbacksPointer to a structure that contains callback functions
Returns
Error code

Definition at line 115 of file mqtt_client.c.

◆ mqttClientSetAuthInfo()

error_t mqttClientSetAuthInfo ( MqttClientContext context,
const char_t username,
const char_t password 
)

Set authentication information.

Parameters
[in]contextPointer to the MQTT client context
[in]usernameNULL-terminated string containing the user name to be used
[in]passwordNULL-terminated string containing the password to be used
Returns
Error code

Definition at line 307 of file mqtt_client.c.

◆ mqttClientSetHost()

error_t mqttClientSetHost ( MqttClientContext context,
const char_t host 
)

Set the hostname of the resource being requested.

Parameters
[in]contextPointer to the MQTT client context
[in]hostNULL-terminated string containing the hostname
Returns
Error code

Definition at line 226 of file mqtt_client.c.

◆ mqttClientSetIdentifier()

error_t mqttClientSetIdentifier ( MqttClientContext context,
const char_t clientId 
)

Set client identifier.

Parameters
[in]contextPointer to the MQTT client context
[in]clientIdNULL-terminated string containing the client identifier
Returns
Error code

Definition at line 280 of file mqtt_client.c.

◆ mqttClientSetKeepAlive()

error_t mqttClientSetKeepAlive ( MqttClientContext context,
uint16_t  keepAlive 
)

Set keep-alive value.

Parameters
[in]contextPointer to the MQTT client context
[in]keepAliveMaximum time interval that is permitted to elapse between the point at which the client finishes transmitting one control packet and the point it starts sending the next
Returns
Error code

Definition at line 205 of file mqtt_client.c.

◆ mqttClientSetProtocolLevel()

error_t mqttClientSetProtocolLevel ( MqttClientContext context,
MqttProtocolLevel  protocolLevel 
)

Set the MQTT protocol version to be used.

Parameters
[in]contextPointer to the MQTT client context
[in]protocolLevelMQTT protocol level (3.1 or 3.1.1)
Returns
Error code

Definition at line 137 of file mqtt_client.c.

◆ mqttClientSetTimeout()

error_t mqttClientSetTimeout ( MqttClientContext context,
uint16_t  timeout 
)

Set communication timeout.

Parameters
[in]contextPointer to the MQTT client context
[in]timeoutTimeout value, in seconds
Returns
Error code

Definition at line 182 of file mqtt_client.c.

◆ mqttClientSetTransportProtocol()

error_t mqttClientSetTransportProtocol ( MqttClientContext context,
MqttTransportProtocol  transportProtocol 
)

Set the transport protocol to be used.

Parameters
[in]contextPointer to the MQTT client context
[in]transportProtocolTransport protocol to be used (TCP, TLS, WebSocket, or secure WebSocket)
Returns
Error code

Definition at line 160 of file mqtt_client.c.

◆ mqttClientSetUri()

error_t mqttClientSetUri ( MqttClientContext context,
const char_t uri 
)

Set the name of the resource being requested.

Parameters
[in]contextPointer to the MQTT client context
[in]uriNULL-terminated string containing the URI
Returns
Error code

Definition at line 253 of file mqtt_client.c.

◆ mqttClientSetWillMessage()

error_t mqttClientSetWillMessage ( MqttClientContext context,
const char_t topic,
const void *  message,
size_t  length,
MqttQosLevel  qos,
bool_t  retain 
)

Specify the Will message.

Parameters
[in]contextPointer to the MQTT client context
[in]topicWill topic name
[in]messageWill message
[in]lengthLength of the Will message
[in]qosQoS level to be used when publishing the Will message
[in]retainThis flag specifies if the Will message is to be retained
Returns
Error code

Definition at line 344 of file mqtt_client.c.

◆ mqttClientSubscribe()

error_t mqttClientSubscribe ( MqttClientContext context,
const char_t topic,
MqttQosLevel  qos,
uint16_t *  packetId 
)

Subscribe to topic.

Parameters
[in]contextPointer to the MQTT client context
[in]topicTopic filter
[in]qosMaximum QoS level at which the server can send application messages to the client
[out]packetIdPacket identifier used to send the SUBSCRIBE packet
Returns
Error code

Definition at line 678 of file mqtt_client.c.

◆ mqttClientUnsubscribe()

error_t mqttClientUnsubscribe ( MqttClientContext context,
const char_t topic,
uint16_t *  packetId 
)

Unsubscribe from topic.

Parameters
[in]contextPointer to the MQTT client context
[in]topicTopic filter
[out]packetIdPacket identifier used to send the UNSUBSCRIBE packet
Returns
Error code

Definition at line 782 of file mqtt_client.c.