FreeRTOS: BLE
BLE
Return to main page ↑
iot_ble_mqtt_serialize.h File Reference

File exposes types and serializer, deserializer APIs for sending and receiving MQTT messages over BLE using a companion mobile device (iOS/Android) SDK. More...

Go to the source code of this file.

Data Structures

struct  MQTTBLESubscribeInfo_t
 
struct  MQTTBLEConnectInfo_t
 
struct  MQTTBLEPublishInfo_t
 

Macros

#define bool   int8_t
 
#define false   ( int8_t ) 0
 
#define true   ( int8_t ) 1
 
#define IOT_BLE_MQTT_MSG_TYPE   "w"
 
#define IOT_BLE_MQTT_CLIENT_ID   "d"
 
#define IOT_BLE_MQTT_BROKER_EP   "a"
 
#define IOT_BLE_MQTT_CLEAN_SESSION   "c"
 
#define IOT_BLE_MQTT_TOPIC   "u"
 
#define IOT_BLE_MQTT_TOPIC_LIST   "v"
 
#define IOT_BLE_MQTT_QOS   "n"
 
#define IOT_BLE_MQTT_QOS_LIST   "o"
 
#define IOT_BLE_MQTT_MESSAGE_ID   "i"
 
#define IOT_BLE_MQTT_PAYLOAD   "k"
 
#define IOT_BLE_MQTT_STATUS   "s"
 
#define IOT_BLE_MQTT_MSG_TYPE_CONNECT   ( 1 )
 
#define IOT_BLE_MQTT_MSG_TYPE_CONNACK   ( 2 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PUBLISH   ( 3 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PUBACK   ( 4 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PUBREC   ( 5 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PUBREL   ( 6 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PUBCOMP   ( 7 )
 
#define IOT_BLE_MQTT_MSG_TYPE_SUBSCRIBE   ( 8 )
 
#define IOT_BLE_MQTT_MSG_TYPE_SUBACK   ( 9 )
 
#define IOT_BLE_MQTT_MSG_TYPE_UNSUBSCRIBE   ( 10 )
 
#define IOT_BLE_MQTT_MSG_TYPE_UNSUBACK   ( 11 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PINGREQ   ( 12 )
 
#define IOT_BLE_MQTT_MSG_TYPE_PINGRESP   ( 13 )
 
#define IOT_BLE_MQTT_MSG_TYPE_DISCONNECT   ( 14 )
 
#define IOT_BLE_MQTT_MSG_TYPE_INVALID   ( 0xFF )
 

Enumerations

enum  MQTTBLEConnectStatus_t {
  IOT_BLE_MQTT_STATUS_UNKNOWN = 0, IOT_BLE_MQTT_STATUS_CONNECTING, IOT_BLE_MQTT_STATUS_CONNECTED, IOT_BLE_MQTT_STATUS_DISCONNECTED,
  IOT_BLE_MQTT_STATUS_CONNECTION_REFUSED, IOT_BLE_MQTT_STATUS_CONNECTION_ERROR, IOT_BLE_MQTT_STATUS_PROTOCOL_ERROR
}
 
enum  MQTTBLEQoS_t { MQTTBLEQoS0 = 0, MQTTBLEQoS1 = 1 }
 
enum  MQTTBLEStatus_t {
  MQTTBLESuccess = 0, MQTTBLEBadParameter, MQTTBLENoMemory, MQTTBLEBadResponse,
  MQTTBLEServerRefused
}
 

Functions

MQTTBLEStatus_t IotBleMqtt_SerializeConnect (const MQTTBLEConnectInfo_t *const pConnectInfo, uint8_t **const pConnectPacket, size_t *const pPacketSize)
 Serialize the MQTT CONNECT message sent over BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_DeserializeConnack (const uint8_t *pBuffer, size_t length)
 Deserialize MQTT CONNACK message received over BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_SerializePublish (const MQTTBLEPublishInfo_t *const pPublishInfo, uint8_t **const pPublishPacket, size_t *const pPacketSize, uint16_t packetIdentifier)
 Serialize MQTT PUBLISH message sent over BLE connection. More...
 
void IotBleMqtt_PublishSetDup (uint8_t *const pPublishPacket, uint8_t *pPacketIdentifierHigh, uint16_t *const pNewPacketIdentifier)
 Set the DUP flag to indicate its a duplicate QoS1/QoS2 message. More...
 
MQTTBLEStatus_t IotBleMqtt_DeserializePublish (uint8_t *pBuffer, size_t length, MQTTBLEPublishInfo_t *publishInfo, uint16_t *packetIdentifier)
 Deserialize MQTT PUBLISH message received over BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_SerializePuback (uint16_t packetIdentifier, uint8_t **const pPubackPacket, size_t *const pPacketSize)
 Serialize MQTT PUBACK message sent over BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_DeserializePuback (uint8_t *pBuffer, size_t length, uint16_t *packetIdentifier)
 Deserialize MQTT PUBACK message received from a BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_SerializeSubscribe (const MQTTBLESubscribeInfo_t *const pSubscriptionList, size_t subscriptionCount, uint8_t **const pSubscribePacket, size_t *const pPacketSize, uint16_t *const pPacketIdentifier)
 Serialize MQTT SUBSCRIBE message sent over BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_DeserializeSuback (const uint8_t *pBuffer, size_t length, uint16_t *packetIdentifier, uint8_t *pStatusCode)
 Deserialize MQTT SUBACK message received over BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_SerializeUnsubscribe (const MQTTBLESubscribeInfo_t *const pSubscriptionList, size_t subscriptionCount, uint8_t **const pUnsubscribePacket, size_t *const pPacketSize, uint16_t *const pPacketIdentifier)
 Serialize MQTT UNSUBSCRIBE message sent over BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_DeserializeUnsuback (uint8_t *pBuffer, size_t length, uint16_t *packetIdentifier)
 Deserialize MQTT UNSUBACK message received over BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_SerializeDisconnect (uint8_t **const pDisconnectPacket, size_t *const pPacketSize)
 Serialize MQTT DISCONNECT message sent over BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_SerializePingreq (uint8_t **const pPingreqPacket, size_t *const pPacketSize)
 Serializes MQTT PING request message sent over BLE connection. More...
 
MQTTBLEStatus_t IotBleMqtt_DeserializePingresp (const uint8_t *pBuffer, size_t length)
 Deserializes MQTT PINGRESP received over BLE connection. More...
 
uint8_t IotBleMqtt_GetPacketType (const uint8_t *pBuffer, size_t length)
 Gets the packet type for the MQTT message. More...
 
void IotBleMqtt_FreePacket (uint8_t *pPacket)
 Frees an MQTT message. More...
 

Detailed Description

File exposes types and serializer, deserializer APIs for sending and receiving MQTT messages over BLE using a companion mobile device (iOS/Android) SDK.

Enumeration Type Documentation

◆ MQTTBLEConnectStatus_t

Enumerator
IOT_BLE_MQTT_STATUS_UNKNOWN 

IOT_BLE_MQTT_STATUS_UNKNOWN Connection status unknown by the SDK.

IOT_BLE_MQTT_STATUS_CONNECTING 

IOT_BLE_MQTT_STATUS_CONNECTING SDK has sent CONNECT request to server and waiting for the response.

IOT_BLE_MQTT_STATUS_CONNECTED 

IOT_BLE_MQTT_STATUS_CONNECTED SDK is connected to the MQTT server.

IOT_BLE_MQTT_STATUS_DISCONNECTED 

IOT_BLE_MQTT_STATUS_DISCONNECTED SDK is disconnected with the MQTT server.

IOT_BLE_MQTT_STATUS_CONNECTION_REFUSED 

IOT_BLE_MQTT_STATUS_CONNECTION_REFUSED Server refused connection with the SDK.

IOT_BLE_MQTT_STATUS_CONNECTION_ERROR 

IOT_BLE_MQTT_STATUS_CONNECTION_ERROR Internal error while connecting to the server.

IOT_BLE_MQTT_STATUS_PROTOCOL_ERROR 

IOT_BLE_MQTT_STATUS_PROTOCOL_ERROR CONNECT message from the device was malformed.

◆ MQTTBLEQoS_t

Enumerator
MQTTBLEQoS0 

Delivery at most once.

MQTTBLEQoS1 

Delivery at least once.

◆ MQTTBLEStatus_t

Enumerator
MQTTBLESuccess 

Function completed successfully.

MQTTBLEBadParameter 

At least one parameter was invalid.

MQTTBLENoMemory 

A provided buffer was too small.

MQTTBLEBadResponse 

An invalid packet was received from the server.

MQTTBLEServerRefused 

Server refused a connection.

Function Documentation

◆ IotBleMqtt_SerializeConnect()

MQTTBLEStatus_t IotBleMqtt_SerializeConnect ( const MQTTBLEConnectInfo_t *const  pConnectInfo,
uint8_t **const  pConnectPacket,
size_t *const  pPacketSize 
)

Serialize the MQTT CONNECT message sent over BLE connection.

Serialize the CONNECT message parameters into a CBOR map to be sent over BLE connection.

Parameters
[in]pConnectInfoMQTT CONNECT parameters.
[in]pWillInfoWill Message parameters.
[out]pConnectPacketThe buffer containing the serialized data.
[in]pPacketSizeThe Size of the serialized data.
Returns
MQTTBLESuccess or MQTTBLENoMemory.

◆ IotBleMqtt_DeserializeConnack()

MQTTBLEStatus_t IotBleMqtt_DeserializeConnack ( const uint8_t *  pBuffer,
size_t  length 
)

Deserialize MQTT CONNACK message received over BLE connection.

Deserialize CONNACK parameters from a CBOR map received over BLE connection.

Parameters
[in]pBufferPointer to start of the CONNACK message within a buffer.
[in]lengthLength of buffer containing the CONNACK message.
Returns
MQTTBLESuccess or MQTTBLEBadResponse.

◆ IotBleMqtt_SerializePublish()

MQTTBLEStatus_t IotBleMqtt_SerializePublish ( const MQTTBLEPublishInfo_t *const  pPublishInfo,
uint8_t **const  pPublishPacket,
size_t *const  pPacketSize,
uint16_t  packetIdentifier 
)

Serialize MQTT PUBLISH message sent over BLE connection.

Serialize PUBLISH message parameters into a CBOR map to be sent over BLE connection.

Parameters
[in]pPublishInfoPointer to the structure containing PUBLISH message parameters.
[out]pPublishPacketPointer to the serialized PUBLISH message.
[out]pPacketSizeLength of the serialized PUBLISH message.
[out]pPacketIdentifierUnique Identifier for the PUBLISH message.
Returns
MQTTBLESuccess or MQTTBLENoMemory.

◆ IotBleMqtt_PublishSetDup()

void IotBleMqtt_PublishSetDup ( uint8_t *const  pPublishPacket,
uint8_t *  pPacketIdentifierHigh,
uint16_t *const  pNewPacketIdentifier 
)

Set the DUP flag to indicate its a duplicate QoS1/QoS2 message.

Sets the DUP flag in the serialized message to indicate its a duplicate QoS1/QoS2 message.

Parameters
[in]pPublishOperationThe operation containing the PUBLISH message.

◆ IotBleMqtt_DeserializePublish()

MQTTBLEStatus_t IotBleMqtt_DeserializePublish ( uint8_t *  pBuffer,
size_t  length,
MQTTBLEPublishInfo_t publishInfo,
uint16_t *  packetIdentifier 
)

Deserialize MQTT PUBLISH message received over BLE connection.

Deserializes the PUBLISH parameters from a CBOR map received over BLE connection.

Parameters
[in]pBufferPointer to start of the PUBLISH message within a buffer.
[in]lengthLength of buffer containing the PUBLISH message.
[out]pPublishInfoParameters parsed from PUBLISH message.
[out]pPacketIdentifierUnique identifier for the PUBLISH message.
Returns
MQTTBLESuccess or MQTTBLEBadResponse.

◆ IotBleMqtt_SerializePuback()

MQTTBLEStatus_t IotBleMqtt_SerializePuback ( uint16_t  packetIdentifier,
uint8_t **const  pPubackPacket,
size_t *const  pPacketSize 
)

Serialize MQTT PUBACK message sent over BLE connection.

Serializes the PUBACK parameters into a CBOR map to be sent over BLE connection.

Parameters
[in]packetIdentifierIdentifier to be included in the PUBACK message.
[out]pPubackPacketPointer to the start of the PUBACK message.
[out]pPacketSizeLength of the PUBACK message.
Returns
MQTTBLESuccess or MQTTBLENoMemory.

◆ IotBleMqtt_DeserializePuback()

MQTTBLEStatus_t IotBleMqtt_DeserializePuback ( uint8_t *  pBuffer,
size_t  length,
uint16_t *  packetIdentifier 
)

Deserialize MQTT PUBACK message received from a BLE connection.

Deserializes the PUBACK parameters from a CBOR map received over BLE connection.

Parameters
[in]pBufferPointer to start of the PUBACK message within a buffer.
[in]lengthLength of buffer containing the PUBACK message.
[out]pPacketIdentifierUnique identifier for the PUBACK message.
Returns
MQTTBLESuccess or MQTTBLEBadResponse.

◆ IotBleMqtt_SerializeSubscribe()

MQTTBLEStatus_t IotBleMqtt_SerializeSubscribe ( const MQTTBLESubscribeInfo_t *const  pSubscriptionList,
size_t  subscriptionCount,
uint8_t **const  pSubscribePacket,
size_t *const  pPacketSize,
uint16_t *const  pPacketIdentifier 
)

Serialize MQTT SUBSCRIBE message sent over BLE connection.

Serialize the SUBSCRIBE message parameters into a CBOR map to be sent over BLE connection.

Parameters
[in]pSubscriptionListPointer to a array of subscriptions.
[out]subscriptionCountNumber of subscriptions.
[out]pSubscribePacketPointer to the SUBSCRIBE message.
[out]pPacketSizeLength of the SUBSCRIBE message.
[out]pPacketIdentifierUnique identifier for the SUBSCRIBE message.
Returns
MQTTBLESuccess or MQTTBLENoMemory.

◆ IotBleMqtt_DeserializeSuback()

MQTTBLEStatus_t IotBleMqtt_DeserializeSuback ( const uint8_t *  pBuffer,
size_t  length,
uint16_t *  packetIdentifier,
uint8_t *  pStatusCode 
)

Deserialize MQTT SUBACK message received over BLE connection.

Deserializes MQTT SUBACK parameters from a CBOR map received over BLE connection.

Parameters
[in]pBufferPointer to the start of suback packet.
[in]lengthLength of the buffer containing suback packet
[out]pPacketIdentifierUnique identifier for the SUBACK message.
[out]pStatusCodeStatus code of the subscription.
Returns
MQTTBLESuccess or MQTTBLEBadResponse.

◆ IotBleMqtt_SerializeUnsubscribe()

MQTTBLEStatus_t IotBleMqtt_SerializeUnsubscribe ( const MQTTBLESubscribeInfo_t *const  pSubscriptionList,
size_t  subscriptionCount,
uint8_t **const  pUnsubscribePacket,
size_t *const  pPacketSize,
uint16_t *const  pPacketIdentifier 
)

Serialize MQTT UNSUBSCRIBE message sent over BLE connection.

Serialize the UNSUBSCRIBE message parameters into a CBOR map to be sent over BLE connection.

Parameters
[in]pSubscriptionListPointer to a array of subscriptions.
[out]subscriptionCountNumber of subscriptions.
[out]pUnsubscribePacketPointer to the UNSUBSCRIBE message.
[out]pPacketSizeLength of the UNSUBSCRIBE message.
[out]pPacketIdentifierUnique identifier for the UNSUBSCRIBE message.
Returns
#MQTTSuccess or #MQTTNoMemory.

◆ IotBleMqtt_DeserializeUnsuback()

MQTTBLEStatus_t IotBleMqtt_DeserializeUnsuback ( uint8_t *  pBuffer,
size_t  length,
uint16_t *  packetIdentifier 
)

Deserialize MQTT UNSUBACK message received over BLE connection.

Deserializes the UNSUBACK parameters from a CBOR map received over BLE connection.

Parameters
[in]pBufferStart of the UNSUBACK message within a buffer.
[in]lengthLength of the buffer containing UNSUBACK message
[out]pPacketIdentifierUnique identifier for the UNSUBACK message.
Returns
MQTTBLESuccess or MQTTBLEBadResponse.

◆ IotBleMqtt_SerializeDisconnect()

MQTTBLEStatus_t IotBleMqtt_SerializeDisconnect ( uint8_t **const  pDisconnectPacket,
size_t *const  pPacketSize 
)

Serialize MQTT DISCONNECT message sent over BLE connection.

Serialize the DISCONNECT message parameters into a CBOR map to be sent over BLE connection.

Parameters
[out]pDisconnectPacketPointer to the DISCONNECT message
[out]pPacketSizeLength of the DISCONNECT message.
Returns
MQTTBLESuccess or MQTTBLENoMemory.

◆ IotBleMqtt_SerializePingreq()

MQTTBLEStatus_t IotBleMqtt_SerializePingreq ( uint8_t **const  pPingreqPacket,
size_t *const  pPacketSize 
)

Serializes MQTT PING request message sent over BLE connection.

Serializes PING request message parameters into a cbor map to be sent over BLE connection.

Parameters
[out]pPingreqPacketPointer to the PING request packet
[out]pPacketSizeSize of the PING request packet
Returns
MQTTBLESuccess or MQTTBLENoMemory.

◆ IotBleMqtt_DeserializePingresp()

MQTTBLEStatus_t IotBleMqtt_DeserializePingresp ( const uint8_t *  pBuffer,
size_t  length 
)

Deserializes MQTT PINGRESP received over BLE connection.

Deserializes PINGRESP parameters from a CBOR map received over BLE connection.

Parameters
[in]pBufferPointer to start of buffer containing PING response
[in]lengthLength of the buffer containing PING response
Returns
#MQTTSuccess or #MQTTBadResponse.

◆ IotBleMqtt_GetPacketType()

uint8_t IotBleMqtt_GetPacketType ( const uint8_t *  pBuffer,
size_t  length 
)

Gets the packet type for the MQTT message.

Parses the CBOR message received and gets the packet type.

Parameters
[in]pBufferBuffer pointing to the serialized packet
[in]lengthLength of the buffer containing the packet
Returns
Packet type for the packet

◆ IotBleMqtt_FreePacket()

void IotBleMqtt_FreePacket ( uint8_t *  pPacket)

Frees an MQTT message.

Parameters
[in]Pointerto the message.