Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: iothub_client EthernetInterface iothub_http_transport mbed-rtos mbed wolfSSL azure_c_shared_utility NTPClient
iothub_client_sample_http.c@82:031681808c6a, 2017-12-15 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Fri Dec 15 14:11:44 2017 -0800
- Revision:
- 82:031681808c6a
- Parent:
- 79:e5cdb4c2307c
- Child:
- 83:2911682db006
1.1.29
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AzureIoTClient | 18:e3e29fc771c9 | 1 | // Copyright (c) Microsoft. All rights reserved. |
AzureIoTClient | 18:e3e29fc771c9 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
AzureIoTClient | 18:e3e29fc771c9 | 3 | |
AzureIoTClient | 18:e3e29fc771c9 | 4 | #include <stdio.h> |
AzureIoTClient | 18:e3e29fc771c9 | 5 | #include <stdlib.h> |
AzureIoTClient | 18:e3e29fc771c9 | 6 | |
AzureIoTClient | 18:e3e29fc771c9 | 7 | /* This sample uses the _LL APIs of iothub_client for example purposes. |
AzureIoTClient | 41:7a930aa6dc01 | 8 | That does not mean that HTTP only works with the _LL APIs. |
AzureIoTClient | 41:7a930aa6dc01 | 9 | Simply changing the using the convenience layer (functions not having _LL) |
AzureIoTClient | 41:7a930aa6dc01 | 10 | and removing calls to _DoWork will yield the same results. */ |
AzureIoTClient | 18:e3e29fc771c9 | 11 | |
Azure.IoT Build | 46:91bd03862871 | 12 | #include "azure_c_shared_utility/threadapi.h" |
Azure.IoT Build | 46:91bd03862871 | 13 | #include "azure_c_shared_utility/crt_abstractions.h" |
Azure.IoT Build | 46:91bd03862871 | 14 | #include "azure_c_shared_utility/platform.h" |
AzureIoTClient | 79:e5cdb4c2307c | 15 | #include "azure_c_shared_utility/shared_util_options.h" |
AzureIoTClient | 18:e3e29fc771c9 | 16 | #include "iothub_client_ll.h" |
AzureIoTClient | 18:e3e29fc771c9 | 17 | #include "iothub_message.h" |
AzureIoTClient | 18:e3e29fc771c9 | 18 | #include "iothubtransporthttp.h" |
AzureIoTClient | 18:e3e29fc771c9 | 19 | |
AzureIoTClient | 18:e3e29fc771c9 | 20 | #ifdef MBED_BUILD_TIMESTAMP |
AzureIoTClient | 77:d4c04296120e | 21 | #define SET_TRUSTED_CERT_IN_SAMPLES |
AzureIoTClient | 77:d4c04296120e | 22 | #endif // MBED_BUILD_TIMESTAMP |
AzureIoTClient | 77:d4c04296120e | 23 | |
AzureIoTClient | 77:d4c04296120e | 24 | #ifdef SET_TRUSTED_CERT_IN_SAMPLES |
AzureIoTClient | 18:e3e29fc771c9 | 25 | #include "certs.h" |
AzureIoTClient | 77:d4c04296120e | 26 | #endif // SET_TRUSTED_CERT_IN_SAMPLES |
AzureIoTClient | 18:e3e29fc771c9 | 27 | |
AzureIoTClient | 39:405f9c637ba4 | 28 | /*String containing Hostname, Device Id & Device Key in the format: */ |
AzureIoTClient | 39:405f9c637ba4 | 29 | /* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */ |
AzureIoTClient | 39:405f9c637ba4 | 30 | /* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessSignature=<device_sas_token>" */ |
AzureIoTClient | 18:e3e29fc771c9 | 31 | static const char* connectionString = "[device connection string]"; |
AzureIoTClient | 39:405f9c637ba4 | 32 | |
AzureIoTClient | 48:07c7ca66634a | 33 | |
AzureIoTClient | 18:e3e29fc771c9 | 34 | static int callbackCounter; |
AzureIoTClient | 42:289de245ba1d | 35 | static bool g_continueRunning; |
Azure.IoT Build | 46:91bd03862871 | 36 | static char msgText[1024]; |
Azure.IoT Build | 46:91bd03862871 | 37 | static char propText[1024]; |
Azure.IoT Build | 46:91bd03862871 | 38 | #define MESSAGE_COUNT 5 |
Azure.IoT Build | 46:91bd03862871 | 39 | #define DOWORK_LOOP_NUM 3 |
AzureIoTClient | 18:e3e29fc771c9 | 40 | |
AzureIoTClient | 18:e3e29fc771c9 | 41 | |
AzureIoTClient | 18:e3e29fc771c9 | 42 | typedef struct EVENT_INSTANCE_TAG |
AzureIoTClient | 18:e3e29fc771c9 | 43 | { |
AzureIoTClient | 18:e3e29fc771c9 | 44 | IOTHUB_MESSAGE_HANDLE messageHandle; |
AzureIoTClient | 47:bc18bf0e4a6a | 45 | size_t messageTrackingId; // For tracking the messages within the user callback. |
AzureIoTClient | 18:e3e29fc771c9 | 46 | } EVENT_INSTANCE; |
AzureIoTClient | 18:e3e29fc771c9 | 47 | |
AzureIoTClient | 18:e3e29fc771c9 | 48 | static IOTHUBMESSAGE_DISPOSITION_RESULT ReceiveMessageCallback(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback) |
AzureIoTClient | 18:e3e29fc771c9 | 49 | { |
AzureIoTClient | 18:e3e29fc771c9 | 50 | int* counter = (int*)userContextCallback; |
AzureIoTClient | 18:e3e29fc771c9 | 51 | const char* buffer; |
AzureIoTClient | 18:e3e29fc771c9 | 52 | size_t size; |
AzureIoTClient | 41:7a930aa6dc01 | 53 | MAP_HANDLE mapProperties; |
AzureIoTClient | 62:2320ad565fc3 | 54 | const char* messageId; |
AzureIoTClient | 62:2320ad565fc3 | 55 | const char* correlationId; |
AzureIoTClient | 76:e9a30712b6d7 | 56 | const char* contentType; |
AzureIoTClient | 76:e9a30712b6d7 | 57 | const char* contentEncoding; |
AzureIoTClient | 20:52f8298d7256 | 58 | |
AzureIoTClient | 62:2320ad565fc3 | 59 | // Message properties |
AzureIoTClient | 62:2320ad565fc3 | 60 | if ((messageId = IoTHubMessage_GetMessageId(message)) == NULL) |
AzureIoTClient | 62:2320ad565fc3 | 61 | { |
AzureIoTClient | 62:2320ad565fc3 | 62 | messageId = "<null>"; |
AzureIoTClient | 62:2320ad565fc3 | 63 | } |
AzureIoTClient | 62:2320ad565fc3 | 64 | |
AzureIoTClient | 62:2320ad565fc3 | 65 | if ((correlationId = IoTHubMessage_GetCorrelationId(message)) == NULL) |
AzureIoTClient | 62:2320ad565fc3 | 66 | { |
AzureIoTClient | 62:2320ad565fc3 | 67 | correlationId = "<null>"; |
AzureIoTClient | 62:2320ad565fc3 | 68 | } |
AzureIoTClient | 62:2320ad565fc3 | 69 | |
AzureIoTClient | 76:e9a30712b6d7 | 70 | // TODO: re-enable after IoTHubClient nuget package has been released (ewertons) |
AzureIoTClient | 76:e9a30712b6d7 | 71 | //if ((contentType = IoTHubMessage_GetContentTypeSystemProperty(message)) == NULL) |
AzureIoTClient | 76:e9a30712b6d7 | 72 | //{ |
AzureIoTClient | 76:e9a30712b6d7 | 73 | contentType = "<null>"; |
AzureIoTClient | 76:e9a30712b6d7 | 74 | //} |
AzureIoTClient | 76:e9a30712b6d7 | 75 | |
AzureIoTClient | 76:e9a30712b6d7 | 76 | // TODO: re-enable after IoTHubClient nuget package has been released (ewertons) |
AzureIoTClient | 76:e9a30712b6d7 | 77 | //if ((contentEncoding = IoTHubMessage_GetContentEncodingSystemProperty(message)) == NULL) |
AzureIoTClient | 76:e9a30712b6d7 | 78 | //{ |
AzureIoTClient | 76:e9a30712b6d7 | 79 | contentEncoding = "<null>"; |
AzureIoTClient | 76:e9a30712b6d7 | 80 | //} |
AzureIoTClient | 76:e9a30712b6d7 | 81 | |
AzureIoTClient | 62:2320ad565fc3 | 82 | // Message content |
AzureIoTClient | 18:e3e29fc771c9 | 83 | if (IoTHubMessage_GetByteArray(message, (const unsigned char**)&buffer, &size) != IOTHUB_MESSAGE_OK) |
AzureIoTClient | 18:e3e29fc771c9 | 84 | { |
AzureIoTClient | 18:e3e29fc771c9 | 85 | printf("unable to retrieve the message data\r\n"); |
AzureIoTClient | 18:e3e29fc771c9 | 86 | } |
AzureIoTClient | 18:e3e29fc771c9 | 87 | else |
AzureIoTClient | 18:e3e29fc771c9 | 88 | { |
AzureIoTClient | 76:e9a30712b6d7 | 89 | (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", |
AzureIoTClient | 76:e9a30712b6d7 | 90 | *counter, messageId, correlationId, contentType, contentEncoding, (int)size, buffer, (int)size); |
AzureIoTClient | 79:e5cdb4c2307c | 91 | if (size == (strlen("quit") * sizeof(char)) && memcmp(buffer, "quit", size) == 0) |
AzureIoTClient | 42:289de245ba1d | 92 | { |
AzureIoTClient | 42:289de245ba1d | 93 | g_continueRunning = false; |
AzureIoTClient | 42:289de245ba1d | 94 | } |
AzureIoTClient | 18:e3e29fc771c9 | 95 | } |
AzureIoTClient | 18:e3e29fc771c9 | 96 | |
AzureIoTClient | 18:e3e29fc771c9 | 97 | // Retrieve properties from the message |
AzureIoTClient | 20:52f8298d7256 | 98 | mapProperties = IoTHubMessage_Properties(message); |
AzureIoTClient | 18:e3e29fc771c9 | 99 | if (mapProperties != NULL) |
AzureIoTClient | 18:e3e29fc771c9 | 100 | { |
AzureIoTClient | 18:e3e29fc771c9 | 101 | const char*const* keys; |
AzureIoTClient | 18:e3e29fc771c9 | 102 | const char*const* values; |
AzureIoTClient | 18:e3e29fc771c9 | 103 | size_t propertyCount = 0; |
AzureIoTClient | 18:e3e29fc771c9 | 104 | if (Map_GetInternals(mapProperties, &keys, &values, &propertyCount) == MAP_OK) |
AzureIoTClient | 18:e3e29fc771c9 | 105 | { |
AzureIoTClient | 18:e3e29fc771c9 | 106 | if (propertyCount > 0) |
AzureIoTClient | 18:e3e29fc771c9 | 107 | { |
AzureIoTClient | 41:7a930aa6dc01 | 108 | size_t index; |
AzureIoTClient | 20:52f8298d7256 | 109 | |
AzureIoTClient | 62:2320ad565fc3 | 110 | printf(" Message Properties:\r\n"); |
AzureIoTClient | 20:52f8298d7256 | 111 | for (index = 0; index < propertyCount; index++) |
AzureIoTClient | 18:e3e29fc771c9 | 112 | { |
AzureIoTClient | 18:e3e29fc771c9 | 113 | printf("\tKey: %s Value: %s\r\n", keys[index], values[index]); |
AzureIoTClient | 18:e3e29fc771c9 | 114 | } |
AzureIoTClient | 18:e3e29fc771c9 | 115 | printf("\r\n"); |
AzureIoTClient | 18:e3e29fc771c9 | 116 | } |
AzureIoTClient | 18:e3e29fc771c9 | 117 | } |
AzureIoTClient | 18:e3e29fc771c9 | 118 | } |
AzureIoTClient | 18:e3e29fc771c9 | 119 | |
AzureIoTClient | 18:e3e29fc771c9 | 120 | /* Some device specific action code goes here... */ |
AzureIoTClient | 18:e3e29fc771c9 | 121 | (*counter)++; |
AzureIoTClient | 18:e3e29fc771c9 | 122 | return IOTHUBMESSAGE_ACCEPTED; |
AzureIoTClient | 18:e3e29fc771c9 | 123 | } |
AzureIoTClient | 18:e3e29fc771c9 | 124 | |
AzureIoTClient | 18:e3e29fc771c9 | 125 | static void SendConfirmationCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback) |
AzureIoTClient | 18:e3e29fc771c9 | 126 | { |
AzureIoTClient | 18:e3e29fc771c9 | 127 | EVENT_INSTANCE* eventInstance = (EVENT_INSTANCE*)userContextCallback; |
AzureIoTClient | 49:2aa1b773af3c | 128 | |
AzureIoTClient | 49:2aa1b773af3c | 129 | (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)); |
AzureIoTClient | 49:2aa1b773af3c | 130 | |
AzureIoTClient | 18:e3e29fc771c9 | 131 | /* Some device specific action code goes here... */ |
AzureIoTClient | 18:e3e29fc771c9 | 132 | callbackCounter++; |
AzureIoTClient | 18:e3e29fc771c9 | 133 | IoTHubMessage_Destroy(eventInstance->messageHandle); |
AzureIoTClient | 18:e3e29fc771c9 | 134 | } |
AzureIoTClient | 18:e3e29fc771c9 | 135 | |
AzureIoTClient | 18:e3e29fc771c9 | 136 | void iothub_client_sample_http_run(void) |
AzureIoTClient | 18:e3e29fc771c9 | 137 | { |
AzureIoTClient | 18:e3e29fc771c9 | 138 | IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle; |
AzureIoTClient | 18:e3e29fc771c9 | 139 | |
AzureIoTClient | 18:e3e29fc771c9 | 140 | EVENT_INSTANCE messages[MESSAGE_COUNT]; |
AzureIoTClient | 20:52f8298d7256 | 141 | double avgWindSpeed = 10.0; |
AzureIoTClient | 68:a8c0f61d8478 | 142 | double minTemperature = 20.0; |
AzureIoTClient | 68:a8c0f61d8478 | 143 | double minHumidity = 60.0; |
AzureIoTClient | 20:52f8298d7256 | 144 | int receiveContext = 0; |
Azure.IoT Build | 46:91bd03862871 | 145 | |
AzureIoTClient | 42:289de245ba1d | 146 | g_continueRunning = true; |
AzureIoTClient | 18:e3e29fc771c9 | 147 | |
AzureIoTClient | 18:e3e29fc771c9 | 148 | srand((unsigned int)time(NULL)); |
AzureIoTClient | 18:e3e29fc771c9 | 149 | |
AzureIoTClient | 18:e3e29fc771c9 | 150 | callbackCounter = 0; |
AzureIoTClient | 18:e3e29fc771c9 | 151 | |
Azure.IoT Build | 33:f8eb46ca453d | 152 | if (platform_init() != 0) |
AzureIoTClient | 18:e3e29fc771c9 | 153 | { |
Azure.IoT Build | 33:f8eb46ca453d | 154 | printf("Failed to initialize the platform.\r\n"); |
AzureIoTClient | 18:e3e29fc771c9 | 155 | } |
AzureIoTClient | 18:e3e29fc771c9 | 156 | else |
AzureIoTClient | 18:e3e29fc771c9 | 157 | { |
Azure.IoT Build | 33:f8eb46ca453d | 158 | (void)printf("Starting the IoTHub client sample HTTP...\r\n"); |
AzureIoTClient | 18:e3e29fc771c9 | 159 | |
Azure.IoT Build | 33:f8eb46ca453d | 160 | if ((iotHubClientHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, HTTP_Protocol)) == NULL) |
AzureIoTClient | 18:e3e29fc771c9 | 161 | { |
Azure.IoT Build | 33:f8eb46ca453d | 162 | (void)printf("ERROR: iotHubClientHandle is NULL!\r\n"); |
AzureIoTClient | 18:e3e29fc771c9 | 163 | } |
AzureIoTClient | 18:e3e29fc771c9 | 164 | else |
AzureIoTClient | 18:e3e29fc771c9 | 165 | { |
Azure.IoT Build | 33:f8eb46ca453d | 166 | unsigned int timeout = 241000; |
Azure.IoT Build | 33:f8eb46ca453d | 167 | // Because it can poll "after 9 seconds" polls will happen effectively // at ~10 seconds. |
Azure.IoT Build | 33:f8eb46ca453d | 168 | // Note that for scalabilty, the default value of minimumPollingTime |
Azure.IoT Build | 33:f8eb46ca453d | 169 | // is 25 minutes. For more information, see: |
Azure.IoT Build | 33:f8eb46ca453d | 170 | // https://azure.microsoft.com/documentation/articles/iot-hub-devguide/#messaging |
Azure.IoT Build | 33:f8eb46ca453d | 171 | unsigned int minimumPollingTime = 9; |
Azure.IoT Build | 33:f8eb46ca453d | 172 | if (IoTHubClient_LL_SetOption(iotHubClientHandle, "timeout", &timeout) != IOTHUB_CLIENT_OK) |
Azure.IoT Build | 33:f8eb46ca453d | 173 | { |
Azure.IoT Build | 33:f8eb46ca453d | 174 | printf("failure to set option \"timeout\"\r\n"); |
Azure.IoT Build | 33:f8eb46ca453d | 175 | } |
AzureIoTClient | 20:52f8298d7256 | 176 | |
Azure.IoT Build | 33:f8eb46ca453d | 177 | if (IoTHubClient_LL_SetOption(iotHubClientHandle, "MinimumPollingTime", &minimumPollingTime) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 18:e3e29fc771c9 | 178 | { |
Azure.IoT Build | 33:f8eb46ca453d | 179 | printf("failure to set option \"MinimumPollingTime\"\r\n"); |
Azure.IoT Build | 33:f8eb46ca453d | 180 | } |
Azure.IoT Build | 33:f8eb46ca453d | 181 | |
AzureIoTClient | 77:d4c04296120e | 182 | #ifdef SET_TRUSTED_CERT_IN_SAMPLES |
Azure.IoT Build | 33:f8eb46ca453d | 183 | // For mbed add the certificate information |
AzureIoTClient | 79:e5cdb4c2307c | 184 | if (IoTHubClient_LL_SetOption(iotHubClientHandle, OPTION_TRUSTED_CERT, certificates) != IOTHUB_CLIENT_OK) |
Azure.IoT Build | 33:f8eb46ca453d | 185 | { |
Azure.IoT Build | 33:f8eb46ca453d | 186 | printf("failure to set option \"TrustedCerts\"\r\n"); |
Azure.IoT Build | 33:f8eb46ca453d | 187 | } |
AzureIoTClient | 77:d4c04296120e | 188 | #endif // SET_TRUSTED_CERT_IN_SAMPLES |
Azure.IoT Build | 33:f8eb46ca453d | 189 | |
Azure.IoT Build | 33:f8eb46ca453d | 190 | /* Setting Message call back, so we can receive Commands. */ |
Azure.IoT Build | 33:f8eb46ca453d | 191 | if (IoTHubClient_LL_SetMessageCallback(iotHubClientHandle, ReceiveMessageCallback, &receiveContext) != IOTHUB_CLIENT_OK) |
Azure.IoT Build | 33:f8eb46ca453d | 192 | { |
Azure.IoT Build | 33:f8eb46ca453d | 193 | (void)printf("ERROR: IoTHubClient_LL_SetMessageCallback..........FAILED!\r\n"); |
Azure.IoT Build | 33:f8eb46ca453d | 194 | } |
Azure.IoT Build | 33:f8eb46ca453d | 195 | else |
Azure.IoT Build | 33:f8eb46ca453d | 196 | { |
Azure.IoT Build | 33:f8eb46ca453d | 197 | (void)printf("IoTHubClient_LL_SetMessageCallback...successful.\r\n"); |
Azure.IoT Build | 33:f8eb46ca453d | 198 | |
Azure.IoT Build | 33:f8eb46ca453d | 199 | /* Now that we are ready to receive commands, let's send some messages */ |
AzureIoTClient | 42:289de245ba1d | 200 | size_t iterator = 0; |
AzureIoTClient | 68:a8c0f61d8478 | 201 | double temperature = 0; |
AzureIoTClient | 68:a8c0f61d8478 | 202 | double humidity = 0; |
AzureIoTClient | 42:289de245ba1d | 203 | do |
AzureIoTClient | 18:e3e29fc771c9 | 204 | { |
AzureIoTClient | 42:289de245ba1d | 205 | if (iterator < MESSAGE_COUNT) |
AzureIoTClient | 18:e3e29fc771c9 | 206 | { |
AzureIoTClient | 68:a8c0f61d8478 | 207 | temperature = minTemperature + (rand() % 10); |
AzureIoTClient | 68:a8c0f61d8478 | 208 | humidity = minHumidity + (rand() % 20); |
AzureIoTClient | 68:a8c0f61d8478 | 209 | sprintf_s(msgText, sizeof(msgText), "{\"deviceId\":\"myFirstDevice\",\"windSpeed\":%.2f,\"temperature\":%.2f,\"humidity\":%.2f}", avgWindSpeed + (rand() % 4 + 2), temperature, humidity); |
AzureIoTClient | 42:289de245ba1d | 210 | if ((messages[iterator].messageHandle = IoTHubMessage_CreateFromByteArray((const unsigned char*)msgText, strlen(msgText))) == NULL) |
Azure.IoT Build | 33:f8eb46ca453d | 211 | { |
AzureIoTClient | 42:289de245ba1d | 212 | (void)printf("ERROR: iotHubMessageHandle is NULL!\r\n"); |
Azure.IoT Build | 33:f8eb46ca453d | 213 | } |
Azure.IoT Build | 33:f8eb46ca453d | 214 | else |
Azure.IoT Build | 33:f8eb46ca453d | 215 | { |
AzureIoTClient | 42:289de245ba1d | 216 | MAP_HANDLE propMap; |
AzureIoTClient | 42:289de245ba1d | 217 | |
AzureIoTClient | 42:289de245ba1d | 218 | messages[iterator].messageTrackingId = iterator; |
Azure.IoT Build | 33:f8eb46ca453d | 219 | |
AzureIoTClient | 42:289de245ba1d | 220 | propMap = IoTHubMessage_Properties(messages[iterator].messageHandle); |
AzureIoTClient | 68:a8c0f61d8478 | 221 | (void)sprintf_s(propText, sizeof(propText), temperature > 28 ? "true" : "false"); |
AzureIoTClient | 68:a8c0f61d8478 | 222 | if (Map_AddOrUpdate(propMap, "temperatureAlert", propText) != MAP_OK) |
AzureIoTClient | 42:289de245ba1d | 223 | { |
AzureIoTClient | 42:289de245ba1d | 224 | (void)printf("ERROR: Map_AddOrUpdate Failed!\r\n"); |
AzureIoTClient | 42:289de245ba1d | 225 | } |
AzureIoTClient | 18:e3e29fc771c9 | 226 | |
AzureIoTClient | 76:e9a30712b6d7 | 227 | // TODO: re-enable after IoTHubClient nuget package has been released (ewertons) |
AzureIoTClient | 76:e9a30712b6d7 | 228 | //(void)IoTHubMessage_SetContentTypeSystemProperty(messages[iterator].messageHandle, "application/json"); |
AzureIoTClient | 76:e9a30712b6d7 | 229 | //(void)IoTHubMessage_SetContentEncodingSystemProperty(messages[iterator].messageHandle, "utf-8"); |
AzureIoTClient | 76:e9a30712b6d7 | 230 | |
AzureIoTClient | 42:289de245ba1d | 231 | if (IoTHubClient_LL_SendEventAsync(iotHubClientHandle, messages[iterator].messageHandle, SendConfirmationCallback, &messages[iterator]) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 42:289de245ba1d | 232 | { |
AzureIoTClient | 42:289de245ba1d | 233 | (void)printf("ERROR: IoTHubClient_LL_SendEventAsync..........FAILED!\r\n"); |
AzureIoTClient | 42:289de245ba1d | 234 | } |
AzureIoTClient | 42:289de245ba1d | 235 | else |
AzureIoTClient | 42:289de245ba1d | 236 | { |
AzureIoTClient | 49:2aa1b773af3c | 237 | (void)printf("IoTHubClient_LL_SendEventAsync accepted message [%zu] for transmission to IoT Hub.\r\n", iterator); |
AzureIoTClient | 49:2aa1b773af3c | 238 | |
AzureIoTClient | 42:289de245ba1d | 239 | } |
AzureIoTClient | 42:289de245ba1d | 240 | |
AzureIoTClient | 42:289de245ba1d | 241 | } |
AzureIoTClient | 42:289de245ba1d | 242 | } |
AzureIoTClient | 42:289de245ba1d | 243 | IoTHubClient_LL_DoWork(iotHubClientHandle); |
AzureIoTClient | 42:289de245ba1d | 244 | ThreadAPI_Sleep(1); |
AzureIoTClient | 42:289de245ba1d | 245 | |
AzureIoTClient | 42:289de245ba1d | 246 | iterator++; |
AzureIoTClient | 42:289de245ba1d | 247 | } while (g_continueRunning); |
Azure.IoT Build | 46:91bd03862871 | 248 | |
AzureIoTClient | 48:07c7ca66634a | 249 | (void)printf("iothub_client_sample_http has gotten quit message, call DoWork %d more time to complete final sending...\r\n", DOWORK_LOOP_NUM); |
Azure.IoT Build | 46:91bd03862871 | 250 | for (size_t index = 0; index < DOWORK_LOOP_NUM; index++) |
Azure.IoT Build | 46:91bd03862871 | 251 | { |
Azure.IoT Build | 46:91bd03862871 | 252 | IoTHubClient_LL_DoWork(iotHubClientHandle); |
Azure.IoT Build | 46:91bd03862871 | 253 | ThreadAPI_Sleep(1); |
Azure.IoT Build | 46:91bd03862871 | 254 | } |
Azure.IoT Build | 33:f8eb46ca453d | 255 | } |
Azure.IoT Build | 33:f8eb46ca453d | 256 | IoTHubClient_LL_Destroy(iotHubClientHandle); |
AzureIoTClient | 18:e3e29fc771c9 | 257 | } |
Azure.IoT Build | 33:f8eb46ca453d | 258 | platform_deinit(); |
AzureIoTClient | 18:e3e29fc771c9 | 259 | } |
AzureIoTClient | 18:e3e29fc771c9 | 260 | } |
AzureIoTClient | 42:289de245ba1d | 261 | |
AzureIoTClient | 42:289de245ba1d | 262 | int main(void) |
AzureIoTClient | 42:289de245ba1d | 263 | { |
AzureIoTClient | 48:07c7ca66634a | 264 | iothub_client_sample_http_run(); |
AzureIoTClient | 48:07c7ca66634a | 265 | return 0; |
AzureIoTClient | 42:289de245ba1d | 266 | } |