mqtt_sn_client.h File Reference

MQTT-SN client. More...

#include "core/net.h"
#include "mqtt_sn/mqtt_sn_common.h"
#include "mqtt_sn/mqtt_sn_message.h"
#include "core/crypto.h"
#include "tls.h"

Go to the source code of this file.

Data Structures

struct  MqttSnClientWillMessage
 Will message. More...
 
struct  MqttSnClientTopicEntry
 Mapping between a topic name and a topic ID. More...
 
struct  MqttSnClientMsgIdEntry
 QoS 2 message state. More...
 
struct  _MqttSnClientContext
 MQTT-SN client context. More...
 

Macros

#define MQTT_SN_CLIENT_SUPPORT   ENABLED
 
#define MQTT_SN_CLIENT_DTLS_SUPPORT   DISABLED
 
#define MQTT_SN_CLIENT_TOPIC_TABLE_SIZE   10
 
#define MQTT_SN_CLIENT_MSG_ID_TABLE_SIZE   10
 
#define MQTT_SN_CLIENT_MAX_ID_LEN   23
 
#define MQTT_SN_CLIENT_MAX_TOPIC_NAME_LEN   32
 
#define MQTT_SN_CLIENT_MAX_WILL_TOPIC_LEN   32
 
#define MQTT_SN_CLIENT_MAX_WILL_PAYLOAD_LEN   32
 
#define MQTT_SN_CLIENT_TICK_INTERVAL   100
 
#define MQTT_SN_CLIENT_DEFAULT_TIMEOUT   30000
 
#define MQTT_SN_CLIENT_DEFAULT_KEEP_ALIVE   0
 
#define MQTT_SN_CLIENT_MAX_KEEP_ALIVE_PROBES   5
 
#define MQTT_SN_CLIENT_SEARCH_DELAY   0
 
#define MQTT_SN_CLIENT_RETRY_TIMEOUT   5000
 
#define MqttSnClientContext   struct _MqttSnClientContext
 

Typedefs

typedef error_t(* MqttSnClientDtlsInitCallback) (MqttSnClientContext *context, TlsContext *dtlsContext)
 DTLS initialization callback. More...
 
typedef void(* MqttSnClientPublishCallback) (MqttSnClientContext *context, const char_t *topic, const uint8_t *message, size_t length, MqttSnQosLevel qos, bool_t retain)
 PUBLISH message received callback. More...
 

Enumerations

enum  MqttSnClientState {
  MQTT_SN_CLIENT_STATE_DISCONNECTED = 0, MQTT_SN_CLIENT_STATE_SEARCHING = 1, MQTT_SN_CLIENT_STATE_CONNECTING = 2, MQTT_SN_CLIENT_STATE_ACTIVE = 3,
  MQTT_SN_CLIENT_STATE_SENDING_REQ = 4, MQTT_SN_CLIENT_STATE_RESP_RECEIVED = 5, MQTT_SN_CLIENT_STATE_LOST = 6, MQTT_SN_CLIENT_STATE_ASLEEP = 7,
  MQTT_SN_CLIENT_STATE_AWAKE = 8, MQTT_SN_CLIENT_STATE_DISCONNECTING = 9
}
 MQTT-SN client states. More...
 

Functions

error_t mqttSnClientInit (MqttSnClientContext *context)
 Initialize MQTT-SN client context. More...
 
error_t mqttSnClientSetTransportProtocol (MqttSnClientContext *context, MqttSnTransportProtocol transportProtocol)
 Set the transport protocol to be used. More...
 
error_t mqttSnClientRegisterDtlsInitCallback (MqttSnClientContext *context, MqttSnClientDtlsInitCallback callback)
 Register DTLS initialization callback function. More...
 
error_t mqttSnClientRegisterPublishCallback (MqttSnClientContext *context, MqttSnClientPublishCallback callback)
 Register publish callback function. More...
 
error_t mqttSnClientSetPredefinedTopics (MqttSnClientContext *context, MqttSnPredefinedTopic *predefinedTopics, uint_t size)
 Set the list of predefined topics. More...
 
error_t mqttSnClientSetTimeout (MqttSnClientContext *context, systime_t timeout)
 Set communication timeout. More...
 
error_t mqttSnClientSetKeepAlive (MqttSnClientContext *context, systime_t keepAlive)
 Set keep-alive value. More...
 
error_t mqttSnClientSetIdentifier (MqttSnClientContext *context, const char_t *clientId)
 Set client identifier. More...
 
error_t mqttSnClientSetWillMessage (MqttSnClientContext *context, const char_t *topic, const void *message, size_t length, MqttSnQosLevel qos, bool_t retain)
 Specify the Will message. More...
 
error_t mqttSnClientBindToInterface (MqttSnClientContext *context, NetInterface *interface)
 Bind the MQTT-SN client to a particular network interface. More...
 
error_t mqttSnClientSetGateway (MqttSnClientContext *context, const IpAddr *gwIpAddr, uint16_t gwPort)
 Specify the address of the gateway. More...
 
error_t mqttSnClientSearchGateway (MqttSnClientContext *context, const IpAddr *destIpAddr, uint16_t destPort)
 Search for a gateway. More...
 
error_t mqttSnClientConnect (MqttSnClientContext *context, bool_t cleanSession)
 Establish connection with the MQTT-SN gateway. More...
 
error_t mqttSnClientPublish (MqttSnClientContext *context, const char_t *topicName, const void *message, size_t length, MqttSnQosLevel qos, bool_t retain, bool_t dup, uint16_t *msgId)
 Publish message. More...
 
error_t mqttSnClientSubscribe (MqttSnClientContext *context, const char_t *topicName, MqttSnQosLevel qos)
 Subscribe to topic. More...
 
error_t mqttSnClientUnsubscribe (MqttSnClientContext *context, const char_t *topicName)
 Unsubscribe from topic. More...
 
error_t mqttSnClientPing (MqttSnClientContext *context)
 Send ping request. More...
 
error_t mqttSnClientUpdateWillMessage (MqttSnClientContext *context, const char_t *topic, const void *message, size_t length, MqttSnQosLevel qos, bool_t retain)
 Update the Will message. More...
 
error_t mqttSnClientGetReturnCode (MqttSnClientContext *context, MqttSnReturnCode *returnCode)
 Retrieve return code. More...
 
error_t mqttSnClientTask (MqttSnClientContext *context, systime_t timeout)
 Process MQTT-SN client events. More...
 
error_t mqttSnClientDisconnect (MqttSnClientContext *context)
 Disconnect from the MQTT-SN gateway. More...
 
void mqttSnClientDeinit (MqttSnClientContext *context)
 Release MQTT-SN client context. More...
 

Detailed Description

MQTT-SN 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_sn_client.h.

Macro Definition Documentation

◆ MQTT_SN_CLIENT_DEFAULT_KEEP_ALIVE

#define MQTT_SN_CLIENT_DEFAULT_KEEP_ALIVE   0

Definition at line 109 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_DEFAULT_TIMEOUT

#define MQTT_SN_CLIENT_DEFAULT_TIMEOUT   30000

Definition at line 102 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_DTLS_SUPPORT

#define MQTT_SN_CLIENT_DTLS_SUPPORT   DISABLED

Definition at line 46 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_MAX_ID_LEN

#define MQTT_SN_CLIENT_MAX_ID_LEN   23

Definition at line 67 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_MAX_KEEP_ALIVE_PROBES

#define MQTT_SN_CLIENT_MAX_KEEP_ALIVE_PROBES   5

Definition at line 116 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_MAX_TOPIC_NAME_LEN

#define MQTT_SN_CLIENT_MAX_TOPIC_NAME_LEN   32

Definition at line 74 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_MAX_WILL_PAYLOAD_LEN

#define MQTT_SN_CLIENT_MAX_WILL_PAYLOAD_LEN   32

Definition at line 88 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_MAX_WILL_TOPIC_LEN

#define MQTT_SN_CLIENT_MAX_WILL_TOPIC_LEN   32

Definition at line 81 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_MSG_ID_TABLE_SIZE

#define MQTT_SN_CLIENT_MSG_ID_TABLE_SIZE   10

Definition at line 60 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_RETRY_TIMEOUT

#define MQTT_SN_CLIENT_RETRY_TIMEOUT   5000

Definition at line 130 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_SEARCH_DELAY

#define MQTT_SN_CLIENT_SEARCH_DELAY   0

Definition at line 123 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_SUPPORT

#define MQTT_SN_CLIENT_SUPPORT   ENABLED

Definition at line 39 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_TICK_INTERVAL

#define MQTT_SN_CLIENT_TICK_INTERVAL   100

Definition at line 95 of file mqtt_sn_client.h.

◆ MQTT_SN_CLIENT_TOPIC_TABLE_SIZE

#define MQTT_SN_CLIENT_TOPIC_TABLE_SIZE   10

Definition at line 53 of file mqtt_sn_client.h.

◆ MqttSnClientContext

#define MqttSnClientContext   struct _MqttSnClientContext

Definition at line 143 of file mqtt_sn_client.h.

Typedef Documentation

◆ MqttSnClientDtlsInitCallback

typedef error_t(* MqttSnClientDtlsInitCallback) (MqttSnClientContext *context, TlsContext *dtlsContext)

DTLS initialization callback.

Definition at line 177 of file mqtt_sn_client.h.

◆ MqttSnClientPublishCallback

typedef void(* MqttSnClientPublishCallback) (MqttSnClientContext *context, const char_t *topic, const uint8_t *message, size_t length, MqttSnQosLevel qos, bool_t retain)

PUBLISH message received callback.

Definition at line 187 of file mqtt_sn_client.h.

Enumeration Type Documentation

◆ MqttSnClientState

MQTT-SN client states.

Enumerator
MQTT_SN_CLIENT_STATE_DISCONNECTED 
MQTT_SN_CLIENT_STATE_SEARCHING 
MQTT_SN_CLIENT_STATE_CONNECTING 
MQTT_SN_CLIENT_STATE_ACTIVE 
MQTT_SN_CLIENT_STATE_SENDING_REQ 
MQTT_SN_CLIENT_STATE_RESP_RECEIVED 
MQTT_SN_CLIENT_STATE_LOST 
MQTT_SN_CLIENT_STATE_ASLEEP 
MQTT_SN_CLIENT_STATE_AWAKE 
MQTT_SN_CLIENT_STATE_DISCONNECTING 

Definition at line 155 of file mqtt_sn_client.h.

Function Documentation

◆ mqttSnClientBindToInterface()

error_t mqttSnClientBindToInterface ( MqttSnClientContext context,
NetInterface interface 
)

Bind the MQTT-SN client to a particular network interface.

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

Definition at line 317 of file mqtt_sn_client.c.

◆ mqttSnClientConnect()

error_t mqttSnClientConnect ( MqttSnClientContext context,
bool_t  cleanSession 
)

Establish connection with the MQTT-SN gateway.

Parameters
[in]contextPointer to the MQTT-SN client context
[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 477 of file mqtt_sn_client.c.

◆ mqttSnClientDeinit()

void mqttSnClientDeinit ( MqttSnClientContext context)

Release MQTT-SN client context.

Parameters
[in]contextPointer to the MQTT-SN client context

Definition at line 1460 of file mqtt_sn_client.c.

◆ mqttSnClientDisconnect()

error_t mqttSnClientDisconnect ( MqttSnClientContext context)

Disconnect from the MQTT-SN gateway.

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

Definition at line 1367 of file mqtt_sn_client.c.

◆ mqttSnClientGetReturnCode()

error_t mqttSnClientGetReturnCode ( MqttSnClientContext context,
MqttSnReturnCode returnCode 
)

Retrieve return code.

Parameters
[in]contextPointer to the MQTT-SN client context
[out]returnCodeReturn code
Returns
Error code

Definition at line 1312 of file mqtt_sn_client.c.

◆ mqttSnClientInit()

error_t mqttSnClientInit ( MqttSnClientContext context)

Initialize MQTT-SN client context.

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

Definition at line 50 of file mqtt_sn_client.c.

◆ mqttSnClientPing()

error_t mqttSnClientPing ( MqttSnClientContext context)

Send ping request.

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

Definition at line 1067 of file mqtt_sn_client.c.

◆ mqttSnClientPublish()

error_t mqttSnClientPublish ( MqttSnClientContext context,
const char_t topicName,
const void *  message,
size_t  length,
MqttSnQosLevel  qos,
bool_t  retain,
bool_t  dup,
uint16_t *  msgId 
)

Publish message.

Parameters
[in]contextPointer to the MQTT-SN client context
[in]topicNameTopic 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
[in]dupThis flag specifies if the message is sent for the first time or if the message is retransmitted
[in,out]msgIdMessage identifier used to send the PUBLISH message
Returns
Error code

Definition at line 631 of file mqtt_sn_client.c.

◆ mqttSnClientRegisterDtlsInitCallback()

error_t mqttSnClientRegisterDtlsInitCallback ( MqttSnClientContext context,
MqttSnClientDtlsInitCallback  callback 
)

Register DTLS initialization callback function.

Parameters
[in]contextPointer to the MQTT-SN client context
[in]callbackDTLS initialization callback function
Returns
Error code

Definition at line 120 of file mqtt_sn_client.c.

◆ mqttSnClientRegisterPublishCallback()

error_t mqttSnClientRegisterPublishCallback ( MqttSnClientContext context,
MqttSnClientPublishCallback  callback 
)

Register publish callback function.

Parameters
[in]contextPointer to the MQTT-SN client context
[in]callbackCallback function to be called when a PUBLISH message is received
Returns
Error code

Definition at line 145 of file mqtt_sn_client.c.

◆ mqttSnClientSearchGateway()

error_t mqttSnClientSearchGateway ( MqttSnClientContext context,
const IpAddr destIpAddr,
uint16_t  destPort 
)

Search for a gateway.

Parameters
[in]contextPointer to the MQTT-SN client context
[in]destIpAddrDestination IP address
[in]destPortDestination port number
Returns
Error code

Definition at line 364 of file mqtt_sn_client.c.

◆ mqttSnClientSetGateway()

error_t mqttSnClientSetGateway ( MqttSnClientContext context,
const IpAddr gwIpAddr,
uint16_t  gwPort 
)

Specify the address of the gateway.

Parameters
[in]contextPointer to the MQTT-SN client context
[in]gwIpAddrGateway IP address
[in]gwPortGateway port number
Returns
Error code

Definition at line 340 of file mqtt_sn_client.c.

◆ mqttSnClientSetIdentifier()

error_t mqttSnClientSetIdentifier ( MqttSnClientContext context,
const char_t clientId 
)

Set client identifier.

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

Definition at line 237 of file mqtt_sn_client.c.

◆ mqttSnClientSetKeepAlive()

error_t mqttSnClientSetKeepAlive ( MqttSnClientContext context,
systime_t  keepAlive 
)

Set keep-alive value.

Parameters
[in]contextPointer to the MQTT-SN client context
[in]keepAliveKeep-alive interval, in milliseconds
Returns
Error code

Definition at line 216 of file mqtt_sn_client.c.

◆ mqttSnClientSetPredefinedTopics()

error_t mqttSnClientSetPredefinedTopics ( MqttSnClientContext context,
MqttSnPredefinedTopic predefinedTopics,
uint_t  size 
)

Set the list of predefined topics.

Parameters
[in]contextPointer to the MQTT-SN client context
[in]predefinedTopicsList of predefined topics
[in]sizeNumber of predefined topics
Returns
Error code

Definition at line 168 of file mqtt_sn_client.c.

◆ mqttSnClientSetTimeout()

error_t mqttSnClientSetTimeout ( MqttSnClientContext context,
systime_t  timeout 
)

Set communication timeout.

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

Definition at line 195 of file mqtt_sn_client.c.

◆ mqttSnClientSetTransportProtocol()

error_t mqttSnClientSetTransportProtocol ( MqttSnClientContext context,
MqttSnTransportProtocol  transportProtocol 
)

Set the transport protocol to be used.

Parameters
[in]contextPointer to the MQTT-SN client context
[in]transportProtocolTransport protocol to be used (UDP or DTLS)
Returns
Error code

Definition at line 96 of file mqtt_sn_client.c.

◆ mqttSnClientSetWillMessage()

error_t mqttSnClientSetWillMessage ( MqttSnClientContext context,
const char_t topic,
const void *  message,
size_t  length,
MqttSnQosLevel  qos,
bool_t  retain 
)

Specify the Will message.

Parameters
[in]contextPointer to the MQTT-SN 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 267 of file mqtt_sn_client.c.

◆ mqttSnClientSubscribe()

error_t mqttSnClientSubscribe ( MqttSnClientContext context,
const char_t topicName,
MqttSnQosLevel  qos 
)

Subscribe to topic.

Parameters
[in]contextPointer to the MQTT-SN client context
[in]topicNameTopic filter
[in]qosMaximum QoS level at which the server can send application messages to the client
Returns
Error code

Definition at line 868 of file mqtt_sn_client.c.

◆ mqttSnClientTask()

error_t mqttSnClientTask ( MqttSnClientContext context,
systime_t  timeout 
)

Process MQTT-SN client events.

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

Definition at line 1334 of file mqtt_sn_client.c.

◆ mqttSnClientUnsubscribe()

error_t mqttSnClientUnsubscribe ( MqttSnClientContext context,
const char_t topicName 
)

Unsubscribe from topic.

Parameters
[in]contextPointer to the MQTT-SN client context
[in]topicNameTopic filter
Returns
Error code

Definition at line 977 of file mqtt_sn_client.c.

◆ mqttSnClientUpdateWillMessage()

error_t mqttSnClientUpdateWillMessage ( MqttSnClientContext context,
const char_t topic,
const void *  message,
size_t  length,
MqttSnQosLevel  qos,
bool_t  retain 
)

Update the Will message.

Parameters
[in]contextPointer to the MQTT-SN 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 1165 of file mqtt_sn_client.c.