IoTHub raw messaging sample using HTTP
Dependencies: iothub_client EthernetInterface iothub_http_transport mbed-rtos mbed wolfSSL azure_c_shared_utility NTPClient
This sample showcases the usage of Azure IoT client libraries with the HTTP transport for sending/receiving raw messages from an IoT Hub.
Diff: iothub_client_sample_http.c
- Revision:
- 48:07c7ca66634a
- Parent:
- 47:bc18bf0e4a6a
- Child:
- 49:2aa1b773af3c
--- a/iothub_client_sample_http.c Mon Jul 18 16:45:56 2016 -0700 +++ b/iothub_client_sample_http.c Fri Jul 29 16:01:40 2016 -0700 @@ -29,6 +29,7 @@ /* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessSignature=<device_sas_token>" */ static const char* connectionString = "[device connection string]"; + static int callbackCounter; static bool g_continueRunning; static char msgText[1024]; @@ -94,7 +95,9 @@ static void SendConfirmationCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback) { EVENT_INSTANCE* eventInstance = (EVENT_INSTANCE*)userContextCallback; - (void)printf("Confirmation[%d] received for message tracking id = %zu with result = %s\r\n", callbackCounter, eventInstance->messageTrackingId, ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result)); + + (void)printf("Confirmation[%d] received for message tracking id = %zu with result = %s\r\n", callbackCounter, eventInstance->messageTrackingId, ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result)); + /* Some device specific action code goes here... */ callbackCounter++; IoTHubMessage_Destroy(eventInstance->messageHandle); @@ -180,7 +183,7 @@ propMap = IoTHubMessage_Properties(messages[iterator].messageHandle); (void)sprintf_s(propText, sizeof(propText), "PropMsg_%zu", iterator); - if (Map_AddOrUpdate(propMap, "PropName", propText) != MAP_OK) + if (Map_AddOrUpdate(propMap, "PropName", propText) != MAP_OK) { (void)printf("ERROR: Map_AddOrUpdate Failed!\r\n"); } @@ -191,7 +194,8 @@ } else { - (void)printf("IoTHubClient_LL_SendEventAsync accepted message [%zu] for transmission to IoT Hub.\r\n", iterator); + (void)printf("IoTHubClient_LL_SendEventAsync accepted message [%zu] for transmission to IoT Hub.\r\n", iterator); + } } @@ -202,7 +206,7 @@ iterator++; } while (g_continueRunning); - (void)printf("iothub_client_sample_mqtt has gotten quit message, call DoWork %d more time to complete final sending...\r\n", DOWORK_LOOP_NUM); + (void)printf("iothub_client_sample_http has gotten quit message, call DoWork %d more time to complete final sending...\r\n", DOWORK_LOOP_NUM); for (size_t index = 0; index < DOWORK_LOOP_NUM; index++) { IoTHubClient_LL_DoWork(iotHubClientHandle); @@ -217,6 +221,6 @@ int main(void) { - iothub_client_sample_http_run(); - return 0; + iothub_client_sample_http_run(); + return 0; }