Initialize an MQTT context.
MQTTStatus_t MQTT_Init(MQTTContext_t *pContext, const TransportInterface_t *pTransportInterface, MQTTGetCurrentTimeFunc_t getTimeFunction, MQTTEventCallback_t userCallback, const MQTTFixedBuffer_t *pNetworkBuffer)
Initialize an MQTT context.
Definition: core_mqtt.c:1660
void(* MQTTEventCallback_t)(struct MQTTContext *pContext, struct MQTTPacketInfo *pPacketInfo, struct MQTTDeserializedInfo *pDeserializedInfo)
Application callback for receiving incoming publishes and incoming acks.
Definition: core_mqtt.h:83
uint32_t(* MQTTGetCurrentTimeFunc_t)(void)
Application provided callback to retrieve the current time in milliseconds.
Definition: core_mqtt.h:68
MQTTStatus_t
Return codes from MQTT functions.
Definition: core_mqtt_serializer.h:105
A struct representing an MQTT connection.
Definition: core_mqtt.h:156
Buffer passed to MQTT library.
Definition: core_mqtt_serializer.h:138
The transport layer interface.
Definition: transport_interface.h:196
This function must be called on a MQTTContext_t before any other function.
- Note
- The MQTTGetCurrentTimeFunc_t callback function must be defined. If there is no time implementation, it is the responsibility of the application to provide a dummy function to always return 0, and provide 0 timeouts for all calls to MQTT_Connect, MQTT_ProcessLoop, and MQTT_ReceiveLoop. This will result in loop functions running for a single iteration, and MQTT_Connect relying on MQTT_MAX_CONNACK_RECEIVE_RETRY_COUNT to receive the CONNACK packet.
- Parameters
-
[in] | pContext | The context to initialize. |
[in] | pTransportInterface | The transport interface to use with the context. |
[in] | getTimeFunction | The time utility function to use with the context. |
[in] | userCallback | The user callback to use with the context to notify about incoming packet events. |
[in] | pNetworkBuffer | Network buffer provided for the context. |
- Returns
- MQTTBadParameter if invalid parameters are passed; MQTTSuccess otherwise.
Example
uint32_t getTimeStampMs();
void eventCallback(
);
int32_t networkSend(
NetworkContext_t * pContext,
const void * pBuffer,
size_t bytes );
int32_t networkRecv(
NetworkContext_t * pContext,
void * pBuffer,
size_t bytes );
uint8_t buffer[ 1024 ];
memset( (
void * ) &mqttContext, 0x00,
sizeof(
MQTTContext_t ) );
transport.pNetworkInterface = &someNetworkInterface;
transport.
send = networkSend;
transport.
recv = networkRecv;
status =
MQTT_Init( &mqttContext, &transport, getTimeStampMs, eventCallback, &fixedBuffer );
{
}
@ MQTTSuccess
Definition: core_mqtt_serializer.h:106
struct NetworkContext NetworkContext_t
The NetworkContext is an incomplete type. An implementation of this interface must define struct Netw...
Definition: transport_interface.h:155
Struct to hold deserialized packet information for an MQTTEventCallback_t callback.
Definition: core_mqtt.h:220
size_t size
Size of buffer.
Definition: core_mqtt_serializer.h:140
uint8_t * pBuffer
Pointer to buffer.
Definition: core_mqtt_serializer.h:139
MQTT incoming packet parameters.
Definition: core_mqtt_serializer.h:259
TransportSend_t send
Definition: transport_interface.h:198
TransportRecv_t recv
Definition: transport_interface.h:197