![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A simple IoTHub sample using MQTT as transport
Dependencies: EthernetInterface NTPClient mbed-rtos mbed wolfSSL azure_c_shared_utility iothub_client azure_umqtt_c iothub_mqtt_transport serializer
Diff: simplesample_mqtt.c
- Revision:
- 51:90c6d50af45f
- Parent:
- 47:5a11f794a6ae
- Child:
- 52:e7a6a18a9c0f
--- a/simplesample_mqtt.c Fri Nov 03 13:26:48 2017 -0700 +++ b/simplesample_mqtt.c Fri Nov 17 14:02:41 2017 -0800 @@ -114,13 +114,11 @@ /*this function "links" IoTHub to the serialization library*/ static IOTHUBMESSAGE_DISPOSITION_RESULT IoTHubMessage(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback) { - IOTHUBMESSAGE_DISPOSITION_RESULT result; const unsigned char* buffer; size_t size; if (IoTHubMessage_GetByteArray(message, &buffer, &size) != IOTHUB_MESSAGE_OK) { - printf("unable to IoTHubMessage_GetByteArray\r\n"); - result = IOTHUBMESSAGE_ABANDONED; + (void)printf("unable to IoTHubMessage_GetByteArray\r\n"); } else { @@ -128,22 +126,22 @@ char* temp = malloc(size + 1); if (temp == NULL) { - printf("failed to malloc\r\n"); - result = IOTHUBMESSAGE_ABANDONED; + (void)printf("failed to malloc\r\n"); } else { (void)memcpy(temp, buffer, size); temp[size] = '\0'; EXECUTE_COMMAND_RESULT executeCommandResult = EXECUTE_COMMAND(userContextCallback, temp); - result = - (executeCommandResult == EXECUTE_COMMAND_ERROR) ? IOTHUBMESSAGE_ABANDONED : - (executeCommandResult == EXECUTE_COMMAND_SUCCESS) ? IOTHUBMESSAGE_ACCEPTED : - IOTHUBMESSAGE_REJECTED; + if (executeCommandResult != EXECUTE_COMMAND_SUCCESS) + { + (void)printf("Execute command failed\r\n"); + } free(temp); } } - return result; + // MQTT can only accept messages + return IOTHUBMESSAGE_ACCEPTED; } void simplesample_mqtt_run(void)