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 | MQTT_SN_CLIENT_PRIVATE_CONTEXT |
#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... | |
Detailed Description
MQTT-SN client.
License
SPDX-License-Identifier: GPL-2.0-or-later
Copyright (C) 2010-2024 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.
- Version
- 2.4.4
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 111 of file mqtt_sn_client.h.
◆ MQTT_SN_CLIENT_DEFAULT_TIMEOUT
#define MQTT_SN_CLIENT_DEFAULT_TIMEOUT 30000 |
Definition at line 104 of file mqtt_sn_client.h.
◆ MQTT_SN_CLIENT_DTLS_SUPPORT
#define MQTT_SN_CLIENT_DTLS_SUPPORT DISABLED |
Definition at line 48 of file mqtt_sn_client.h.
◆ MQTT_SN_CLIENT_MAX_ID_LEN
#define MQTT_SN_CLIENT_MAX_ID_LEN 23 |
Definition at line 69 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 118 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 76 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 90 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 83 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 62 of file mqtt_sn_client.h.
◆ MQTT_SN_CLIENT_PRIVATE_CONTEXT
#define MQTT_SN_CLIENT_PRIVATE_CONTEXT |
Definition at line 139 of file mqtt_sn_client.h.
◆ MQTT_SN_CLIENT_RETRY_TIMEOUT
#define MQTT_SN_CLIENT_RETRY_TIMEOUT 5000 |
Definition at line 132 of file mqtt_sn_client.h.
◆ MQTT_SN_CLIENT_SEARCH_DELAY
#define MQTT_SN_CLIENT_SEARCH_DELAY 0 |
Definition at line 125 of file mqtt_sn_client.h.
◆ MQTT_SN_CLIENT_SUPPORT
#define MQTT_SN_CLIENT_SUPPORT ENABLED |
Definition at line 41 of file mqtt_sn_client.h.
◆ MQTT_SN_CLIENT_TICK_INTERVAL
#define MQTT_SN_CLIENT_TICK_INTERVAL 100 |
Definition at line 97 of file mqtt_sn_client.h.
◆ MQTT_SN_CLIENT_TOPIC_TABLE_SIZE
#define MQTT_SN_CLIENT_TOPIC_TABLE_SIZE 10 |
Definition at line 55 of file mqtt_sn_client.h.
◆ MqttSnClientContext
#define MqttSnClientContext struct _MqttSnClientContext |
Definition at line 150 of file mqtt_sn_client.h.
Typedef Documentation
◆ MqttSnClientDtlsInitCallback
typedef error_t(* MqttSnClientDtlsInitCallback) (MqttSnClientContext *context, TlsContext *dtlsContext) |
DTLS initialization callback.
Definition at line 184 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 194 of file mqtt_sn_client.h.
Enumeration Type Documentation
◆ MqttSnClientState
enum MqttSnClientState |
MQTT-SN client states.
Definition at line 162 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] context Pointer to the MQTT-SN client context [in] interface Network interface to be used
- Returns
- Error code
Definition at line 319 of file mqtt_sn_client.c.
◆ mqttSnClientConnect()
error_t mqttSnClientConnect | ( | MqttSnClientContext * | context, |
bool_t | cleanSession | ||
) |
Establish connection with the MQTT-SN gateway.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] cleanSession If 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 479 of file mqtt_sn_client.c.
◆ mqttSnClientDeinit()
void mqttSnClientDeinit | ( | MqttSnClientContext * | context | ) |
Release MQTT-SN client context.
- Parameters
-
[in] context Pointer to the MQTT-SN client context
Definition at line 1468 of file mqtt_sn_client.c.
◆ mqttSnClientDisconnect()
error_t mqttSnClientDisconnect | ( | MqttSnClientContext * | context, |
systime_t | duration | ||
) |
Disconnect from the MQTT-SN gateway.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] duration Sleep duration, in milliseconds
- Returns
- Error code
Definition at line 1374 of file mqtt_sn_client.c.
◆ mqttSnClientGetReturnCode()
error_t mqttSnClientGetReturnCode | ( | MqttSnClientContext * | context, |
MqttSnReturnCode * | returnCode | ||
) |
Retrieve return code.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [out] returnCode Return code
- Returns
- Error code
Definition at line 1318 of file mqtt_sn_client.c.
◆ mqttSnClientInit()
error_t mqttSnClientInit | ( | MqttSnClientContext * | context | ) |
Initialize MQTT-SN client context.
- Parameters
-
[in] context Pointer to the MQTT-SN client context
- Returns
- Error code
Definition at line 52 of file mqtt_sn_client.c.
◆ mqttSnClientPing()
error_t mqttSnClientPing | ( | MqttSnClientContext * | context | ) |
Send ping request.
- Parameters
-
[in] context Pointer to the MQTT-SN client context
- Returns
- Error code
Definition at line 1073 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] context Pointer to the MQTT-SN client context [in] topicName Topic name [in] message Message payload [in] length Length of the message payload [in] qos QoS level to be used when publishing the message [in] retain This flag specifies if the message is to be retained [in] dup This flag specifies if the message is sent for the first time or if the message is retransmitted [in,out] msgId Message identifier used to send the PUBLISH message
- Returns
- Error code
Definition at line 633 of file mqtt_sn_client.c.
◆ mqttSnClientRegisterDtlsInitCallback()
error_t mqttSnClientRegisterDtlsInitCallback | ( | MqttSnClientContext * | context, |
MqttSnClientDtlsInitCallback | callback | ||
) |
Register DTLS initialization callback function.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] callback DTLS initialization callback function
- Returns
- Error code
Definition at line 122 of file mqtt_sn_client.c.
◆ mqttSnClientRegisterPublishCallback()
error_t mqttSnClientRegisterPublishCallback | ( | MqttSnClientContext * | context, |
MqttSnClientPublishCallback | callback | ||
) |
Register publish callback function.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] callback Callback function to be called when a PUBLISH message is received
- Returns
- Error code
Definition at line 147 of file mqtt_sn_client.c.
◆ mqttSnClientSearchGateway()
error_t mqttSnClientSearchGateway | ( | MqttSnClientContext * | context, |
const IpAddr * | destIpAddr, | ||
uint16_t | destPort | ||
) |
Search for a gateway.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] destIpAddr Destination IP address [in] destPort Destination port number
- Returns
- Error code
Definition at line 366 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] context Pointer to the MQTT-SN client context [in] gwIpAddr Gateway IP address [in] gwPort Gateway port number
- Returns
- Error code
Definition at line 342 of file mqtt_sn_client.c.
◆ mqttSnClientSetIdentifier()
error_t mqttSnClientSetIdentifier | ( | MqttSnClientContext * | context, |
const char_t * | clientId | ||
) |
Set client identifier.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] clientId NULL-terminated string containing the client identifier
- Returns
- Error code
Definition at line 239 of file mqtt_sn_client.c.
◆ mqttSnClientSetKeepAlive()
error_t mqttSnClientSetKeepAlive | ( | MqttSnClientContext * | context, |
systime_t | keepAlive | ||
) |
Set keep-alive value.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] keepAlive Keep-alive interval, in milliseconds
- Returns
- Error code
Definition at line 218 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] context Pointer to the MQTT-SN client context [in] predefinedTopics List of predefined topics [in] size Number of predefined topics
- Returns
- Error code
Definition at line 170 of file mqtt_sn_client.c.
◆ mqttSnClientSetTimeout()
error_t mqttSnClientSetTimeout | ( | MqttSnClientContext * | context, |
systime_t | timeout | ||
) |
Set communication timeout.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] timeout Timeout value, in milliseconds
- Returns
- Error code
Definition at line 197 of file mqtt_sn_client.c.
◆ mqttSnClientSetTransportProtocol()
error_t mqttSnClientSetTransportProtocol | ( | MqttSnClientContext * | context, |
MqttSnTransportProtocol | transportProtocol | ||
) |
Set the transport protocol to be used.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] transportProtocol Transport protocol to be used (UDP or DTLS)
- Returns
- Error code
Definition at line 98 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] context Pointer to the MQTT-SN client context [in] topic Will topic name [in] message Will message [in] length Length of the Will message [in] qos QoS level to be used when publishing the Will message [in] retain This flag specifies if the Will message is to be retained
- Returns
- Error code
Definition at line 269 of file mqtt_sn_client.c.
◆ mqttSnClientSubscribe()
error_t mqttSnClientSubscribe | ( | MqttSnClientContext * | context, |
const char_t * | topicName, | ||
MqttSnQosLevel | qos | ||
) |
Subscribe to topic.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] topicName Topic filter [in] qos Maximum QoS level at which the server can send application messages to the client
- Returns
- Error code
Definition at line 874 of file mqtt_sn_client.c.
◆ mqttSnClientTask()
error_t mqttSnClientTask | ( | MqttSnClientContext * | context, |
systime_t | timeout | ||
) |
Process MQTT-SN client events.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] timeout Maximum time to wait before returning
- Returns
- Error code
Definition at line 1340 of file mqtt_sn_client.c.
◆ mqttSnClientUnsubscribe()
error_t mqttSnClientUnsubscribe | ( | MqttSnClientContext * | context, |
const char_t * | topicName | ||
) |
Unsubscribe from topic.
- Parameters
-
[in] context Pointer to the MQTT-SN client context [in] topicName Topic filter
- Returns
- Error code
Definition at line 983 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] context Pointer to the MQTT-SN client context [in] topic Will topic name [in] message Will message [in] length Length of the Will message [in] qos QoS level to be used when publishing the Will message [in] retain This flag specifies if the Will message is to be retained
- Returns
- Error code
Definition at line 1171 of file mqtt_sn_client.c.