mqttsn_client.h File Reference

Table of contents Table of contents

MQTT-SN client API declaration. 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_DATA   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_GATEWAY_RESPONSE_TIMEOUT_MS   10000
 Gateway response timeout in milliseconds, after which the client assumes the gateway is not responding.
 
#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)
 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.
 
typedef struct MQTTSNTopicDescriptor MQTTSNTopicDescriptor
 Structure describing a single MQTT-SN topic.
 
typedef struct MQTTSNQosMsg MQTTSNQosMsg
 Structure describing the MQTTSN QOS(1-2) message.
 
typedef struct MQTTSNClient MQTTSNClient
 Structure describing the MQTT-SN Client.
 

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_CONNECT_SERIALIZATION_ERR , MQTTSN_CLIENT_RESULT_BUFFER_OR_CLIENT_IS_NULL , MQTTSN_CLIENT_CLIENTID_FORBIDDEN_LENGTH ,
  MQTTSN_CLIENT_UNEXPECTED_ACK_RECEIVED , MQTTSN_CLIENT_TOPIC_NOT_IN_REGISTRATION , MQTTSN_CLIENT_REGACK_DESERIALIZATION_FAILED , MQTTSN_CLIENT_PUBLISH_DESERIALIZATION_FAILED ,
  MQTTSN_CLIENT_SUBACK_DESERIALIZATION_FAILED , MQTTSN_CLIENT_UNSUBACK_DESERIALIZATION_FAILED , MQTTSN_CLIENT_PUBACK_DESERIALIZATION_FAILED , MQTTSN_CLIENT_PUBREC_DESERIALIZATION_FAILED ,
  MQTTSN_CLIENT_PUBREL_DESERIALIZATION_FAILED , MQTTSN_CLIENT_PUBCOMP_DESERIALIZATION_FAILED , MQTTSN_CLIENT_GW_ERR_CONGESTION , MQTTSN_CLIENT_GW_INVALID_TOPIC_ID ,
  MQTTSN_CLIENT_GW_ERR_NOT_SUPPORTED , MQTTSN_CLIENT_UNKNOWN_ERROR , MQTTSN_CLIENT_WILL_TOPIC_SERIALIZATION_ERROR , MQTTSN_CLIENT_UNEXPECTED_WILL_TOPIC_REQ_RECEIVED ,
  MQTTSN_CLIENT_UNEXPECTED_WILL_MSG_REQ_RECEIVED , MQTTSN_CLIENT_WILL_MSG_SERIALIZATION_ERROR , MQTTSN_CLIENT_PING_SERIALIZATION_ERROR , MQTTSN_CLIENT_TXTOPICS_BUFFER_FULL ,
  MQTTSN_CLIENT_REGISTER_SERIALIZATION_ERROR , MQTTSN_CLIENT_PUBLISH_SERIALIZATION_ERROR , MQTTSN_CLIENT_PUBACK_SERIALIZATION_ERROR , MQTTSN_CLIENT_PUBREC_SERIALIZATION_ERROR ,
  MQTTSN_CLIENT_PUBREL_SERIALIZATION_ERROR , MQTTSN_CLIENT_PUBCOMP_SERIALIZATION_ERROR , MQTTSN_CLIENT_TOPIC_NOT_REGISTERED , MQTTSN_CLIENT_SUBSCRIBE_SERIALIZATION_ERROR ,
  MQTTSN_CLIENT_UNSUBSCRIBE_SERIALIZATION_ERROR , MQTTSN_CLIENT_RECEIVED_BROKEN_PACKET , MQTTSN_CLIENT_CLIENT_NOT_CONNECTED , MQTTSN_CLIENT_CLIENT_NOT_DISCONNECTED ,
  MQTTSN_CLIENT_DISCONNECT_SERIALIZATION_ERROR , MQTTSN_CLIENT_RESULT_TOPIC_NOT_FOUND , MQTTSN_CLIENT_RESULT_TOPIC_NOT_PENDING_REGISTRATION , MQTTSN_CLIENT_RESULT_DISCONNECT_SERIALIZATION_ERROR ,
  MQTTSN_CLIENT_SUBSCRIBE_BUFFER_FULL , MQTTSN_CLIENT_TOPIC_EXCEEDS_SET_MAX_LEN
}
 Possible results of the MQTT-SN client API calls. More...
 
enum  MQTTSNPacketQoS { MQTTSN_MESSAGE_QOS0 , MQTTSN_MESSAGE_QOS1 , MQTTSN_MESSAGE_QOS2 }
 Possible levels of QoS. 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, uint16_t keepAliveTime, uint16_t pingPeriod, char const *willTopic, uint8_t const *willMsg, uint8_t const qosRetransmissions)
 Makes the client try to connect to a gateway.
 
MQTTSNClientResult MQTTSN_CLIENT_CleanConnect (MQTTSNClient *client, EMBENET_IPV6 const *gatewayAddress, uint16_t gatewayPort, uint16_t keepAliveTime, uint16_t pingPeriod, char const *willTopic, uint8_t const *willMsg, uint8_t const qosRetransmissions)
 Makes the client try to connect to a gateway using clean connection.
 
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, char 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, char 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 by a regular topic name via UNSUBSCRIBE packet. Once unsubscribed, the client will no longer receive messages published on the topic.
 

Detailed Description

MQTT-SN client API declaration.

License: $License$
Version
$Revision$
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