mqttsn_client.h File Reference

Table of contents Table of contents

MQTT-SN client API. More...

Data Structures

struct  MQTTSNClientEventHandlers
 Structure grouping event callbacks for MQTT-SN client. More...
 
struct  MQTTSNTopicDescriptor
 Structure describing a single MQTT-SN topic. More...
 
struct  MQTTSNSessionFlags
 MQTT-SN session flags. More...
 
struct  MQTTSNQosMsg
 Structure describing the MQTTSN QOS(1-2) message. More...
 
struct  MQTTSNClient
 Structure describing the MQTT-SN Client. More...
 

Macros

#define MQTTSN_MAX_TOPIC_NAME_LENGTH   38
 Maximum length of the MQTT-SN topic name.
 
#define MQTTSN_MAX_MESSAGE_LENGTH   32
 Maximum length of the MQTT-SN message data.
 
#define MQTTSN_MAX_CLIENT_ID_LENGTH   23
 Maximum length of the MQTT-SN client id.
 
#define MQTTSN_CLIENT_MAX_TOPICS_TO_SUBSCRIBE   10
 Maximum number of topics that the client can subscribe to.
 
#define MQTTSN_CLIENT_MAX_TOPICS_TO_PUBLISH   10
 Maximum number of topics that the client can publish to.
 
#define MQTTSN_CLIENT_MAX_PINGRESP_LOST   3
 Maximum number of consecutive PINGRESP messages that can be lost before the client assumes the gateway is not responding.
 

Typedefs

typedef uint16_t MQTTSNTopicId
 Type describing topic id.
 
typedef void(* MQTTSNOnClientConnected) (struct MQTTSNClient *client)
 Callback function type describing a function that is called when the MQTT-SN client connects to the gateway.
 
typedef void(* MQTTSNOnClientDisconnected) (struct MQTTSNClient *client, MQTTSNClientDisconnectionReason disconnectionReason)
 Callback function type describing a function that is called when the MQTT-SN client gets disconnected from the gateway.
 
typedef void(* MQTTSNOnTopicRegisteredByClient) (const struct MQTTSNClient *client, MQTTSNTopicId topicId, char const *topicName)
 Callback function type describing a function that is called when a topic is successfully registered by the client in the gateway.
 
typedef void(* MQTTSNOnTopicRegisteredByGateway) (struct MQTTSNClient *client, MQTTSNTopicId topicId, char const *topicName)
 Callback function type describing a function that is called when a topic is successfully registered by the gateway.
 
typedef void(* MQTTSNOnTopicSubscribedByClient) (const struct MQTTSNClient *client, MQTTSNTopicId topicId, char const *topicName)
 Callback function type describing a function that is called when the client successfully subscribes to a topic.
 
typedef void(* MQTTSNOnTopicUnsubscribedByClient) (const struct MQTTSNClient *client, MQTTSNTopicId topicId, char const *topicName)
 Callback function type describing a function that is called when the client successfully unsubscribes from a topic.
 
typedef void(* MQTTSNOnPublishReceived) (struct MQTTSNClient *client, MQTTSNTopicId topicId, void const *data, size_t dataSize)
 Callback function type describing a function that is called when a message is received on a topic.
 
typedef void(* MQTTSNOnPublishSent) (struct MQTTSNClient *client, MQTTSNTopicId topicId, void const *data, size_t dataSize)
 Callback function type describing a function that is called when a message is sent to a topic.
 

Enumerations

enum  MQTTSNClientState {
  MQTTSN_CLIENT_STATE_DISCONNECTED ,
  MQTTSN_CLIENT_STATE_CONNECTING ,
  MQTTSN_CLIENT_STATE_AWAITING_WILL_TOPIC_REQ ,
  MQTTSN_CLIENT_STATE_AWAITING_WILL_MSG_REQ ,
  MQTTSN_CLIENT_STATE_CONNECTED ,
  MQTTSN_CLIENT_STATE_DISCONNECTING
}
 Possible states of the MQTT-SN client. More...
 
enum  MQTTSNClientResult {
  MQTTSN_CLIENT_RESULT_OK = 0 ,
  MQTTSN_CLIENT_RESULT_INVALID_INPUT_ARGUMENT ,
  MQTTSN_CLIENT_RESULT_FAILED_TO_REGISTER_UDP_SOCKET ,
  MQTTSN_CLIENT_RESULT_FAILED_TO_CREATE_TASK ,
  MQTTSN_CLIENT_RESULT_FAILED_TO_SEND_PACKET ,
  MQTTSN_CLIENT_RESULT_FAILED_TO_SERIALIZE_PACKET ,
  MQTTSN_CLIENT_RESULT_CLIENT_NOT_CONNECTED ,
  MQTTSN_CLIENT_RESULT_CLIENT_ALREADY_CONNECTED ,
  MQTTSN_CLIENT_RESULT_TOPIC_NOT_FOUND ,
  MQTTSN_CLIENT_RESULT_PUBLISH_BUFFER_FULL ,
  MQTTSN_CLIENT_RESULT_SUBSCRIBE_BUFFER_FULL ,
  MQTTSN_CLIENT_RESULT_TOPIC_TOO_LONG ,
  MQTTSN_CLIENT_RESULT_MESSAGE_TOO_LONG
}
 Possible results of the MQTT-SN client API calls. More...
 
enum  MQTTSNPacketQoS {
  MQTTSN_QOS0 ,
  MQTTSN_QOS1 ,
  MQTTSN_QOS2
}
 Possible levels of QoS. More...
 
enum  MQTTSNClientDisconnectionReason {
  MQTTSN_CLIENT_DISCONNECTED_DUE_TO_OWN_REQUEST ,
  MQTTSN_CLIENT_DISCONNECTED_BY_GATEWAY ,
  MQTTSN_CLIENT_DISCONNECTED_DUE_TO_TIMEOUT
}
 Possible disconnection reasons. More...
 

Functions

MQTTSNClientResult MQTTSN_CLIENT_Init (MQTTSNClient *client, uint16_t port, char const *clientId, MQTTSNClientEventHandlers const *eventHandlers)
 Initializes the MQTT-SN client.
 
void MQTTSN_CLIENT_Deinit (MQTTSNClient *client)
 Deinitializes the MQTT-SN client.
 
MQTTSNClientResult MQTTSN_CLIENT_Connect (MQTTSNClient *client, EMBENET_IPV6 const *gatewayAddress, uint16_t gatewayPort, uint32_t keepAliveTimeMs, uint32_t gatewayTimeoutMs, char const *willTopic, uint8_t const *willMsg, uint8_t const qosRetransmissions)
 Makes the client try to connect to a gateway.
 
MQTTSNClientResult MQTTSN_CLIENT_Disconnect (MQTTSNClient *client)
 Disconnects the client from the gateway.
 
MQTTSNClientResult MQTTSN_CLIENT_RegisterTopic (MQTTSNClient *client, char const *topic, MQTTSNOnTopicRegisteredByClient onTopicRegisteredCallback)
 Registers a topic in the gateway.
 
MQTTSNTopicId MQTTSN_CLIENT_GetTopicId (MQTTSNClient *client, char const *topic)
 Gets the id of the registered topic.
 
MQTTSNClientResult MQTTSN_CLIENT_PublishMessage (MQTTSNClient *client, char const *topic, MQTTSNPacketQoS qos, void const *message, size_t messageLen, MQTTSNOnPublishSent onPublishSentCallback)
 Publishes a message on a topic given the topic string.
 
MQTTSNClientResult MQTTSN_CLIENT_PublishMessageById (MQTTSNClient *client, MQTTSNTopicId topicId, MQTTSNPacketQoS qos, void const *message, size_t messageLen, MQTTSNOnPublishSent onPublishSentCallback)
 Publishes a message on a topic given the topic id.
 
MQTTSNClientResult MQTTSN_CLIENT_Subscribe (MQTTSNClient *client, char const *topic, MQTTSNPacketQoS qos, MQTTSNOnTopicSubscribedByClient onTopicSubscribedByClient, MQTTSNOnPublishReceived onPublishReceivedCallback)
 Subscribes to the topic.
 
MQTTSNClientResult MQTTSN_CLIENT_Unsubscribe (MQTTSNClient *client, char const *topic, MQTTSNOnTopicUnsubscribedByClient onTopicUnsubscribedByClient)
 Unsubscribes from the topic.
 

Detailed Description

MQTT-SN client API.

License: ${PROJECT_LICENSE}
Version
${PROJECT_VERSION}
Purpose: embeNET MQTT-SN client

This implementation of MQTT-SN client is based on the MQTT-SN specification version 1.2.

Contact us

Any question or remarks? Just write us a message!

Contact Information

Feel free to get in touch

ikona youtube kanał ikona linkedin kanał