1.2.3.12 SYS_MQTT_CALLBACK Function
C
int32_t SYS_MQTT_CALLBACK(SYS_MQTT_EVENT_TYPE eEventType, void *data, uint16_t len, void* cookie);
Summary
Pointer to a MQTT system service callback function.
Description
This data type defines a pointer to a Mqtt service callback function, thus defining the function signature. Callback functions may be registered by mqtt clients of the Mqtt service via the SYS_MQTT_Connect call.
Precondition
Is a part of the Mqtt service Setup using the SYS_MQTT_Connect function
Parameters
Param | Description |
---|---|
eEventType - event (SYS_MQTT_EVENT_TYPE) | Message Received/ Got Disconnected data - Data (if any) related to the Event len - Length of the Data received cookie - A context value, returned untouched to the client when the callback occurs. It can be used to identify the instance of the client who registered the callback. |
Returns
None.
Example
void MqttSrvcCallback(SYS_MQTT_EVENT_TYPE event, void *data, uint16_t len, void* cookie, ) { switch(event) { case SYS_MQTT_EVENT_MSG_RCVD: { SYS_MQTT_PublishConfig *psMsg = (SYS_MQTT_PublishConfig *)data; psMsg->message[psMsg->messageLength] = 0; psMsg->topicName[psMsg->topicLength] = 0; SYS_CONSOLE_PRINT("\nMqttCallback(): Msg received on Topic: %s ; Msg: %s\r\n", psMsg->topicName, psMsg->message); break; } case SYS_MQTT_EVENT_MSG_DISCONNECT: { SYS_CONSOLE_PRINT("CloudSrvcCallback(): MQTT DOWN"); break; } } }