IoTHub raw messaging client sample using MQTT
Dependencies: EthernetInterface NTPClient mbed-rtos mbed wolfSSL azure_c_shared_utility iothub_client azure_umqtt_c iothub_mqtt_transport
Diff: iothub_client_sample_mqtt.c
- Revision:
- 44:093816abb152
- Parent:
- 37:fdee5b96897d
- Child:
- 45:c5727007e4f0
--- a/iothub_client_sample_mqtt.c Fri Aug 11 14:04:14 2017 -0700 +++ b/iothub_client_sample_mqtt.c Fri Aug 25 11:24:45 2017 -0700 @@ -42,6 +42,8 @@ MAP_HANDLE mapProperties; const char* messageId; const char* correlationId; + const char* userDefinedContentType; + const char* userDefinedContentEncoding; // Message properties if ((messageId = IoTHubMessage_GetMessageId(message)) == NULL) @@ -54,6 +56,16 @@ correlationId = "<null>"; } + if ((userDefinedContentType = IoTHubMessage_GetContentTypeSystemProperty(message)) == NULL) + { + userDefinedContentType = "<null>"; + } + + if ((userDefinedContentEncoding = IoTHubMessage_GetContentEncodingSystemProperty(message)) == NULL) + { + userDefinedContentEncoding = "<null>"; + } + // Message content if (IoTHubMessage_GetByteArray(message, (const unsigned char**)&buffer, &size) != IOTHUB_MESSAGE_OK) { @@ -61,7 +73,8 @@ } else { - (void)printf("Received Message [%d]\r\n Message ID: %s\r\n Correlation ID: %s\r\n Data: <<<%.*s>>> & Size=%d\r\n", *counter, messageId, correlationId, (int)size, buffer, (int)size); + (void)printf("Received Message [%d]\r\n Message ID: %s\r\n Correlation ID: %s\r\n Content-Type: %s\r\n Content-Encoding: %s\r\n Data: <<<%.*s>>> & Size=%d\r\n", + *counter, messageId, correlationId, userDefinedContentType, userDefinedContentEncoding, (int)size, buffer, (int)size); // If we receive the work 'quit' then we stop running if (size == (strlen("quit") * sizeof(char)) && memcmp(buffer, "quit", size) == 0) { @@ -173,6 +186,8 @@ (void)IoTHubMessage_SetMessageId(messages[iterator].messageHandle, "MSG_ID"); (void)IoTHubMessage_SetCorrelationId(messages[iterator].messageHandle, "CORE_ID"); + (void)IoTHubMessage_SetContentTypeSystemProperty(messages[iterator].messageHandle, "application%2Fjson"); + (void)IoTHubMessage_SetContentEncodingSystemProperty(messages[iterator].messageHandle, "utf-8"); messages[iterator].messageTrackingId = iterator; MAP_HANDLE propMap = IoTHubMessage_Properties(messages[iterator].messageHandle);