A simple IoTHub sample using HTTP as transport
Dependencies: EthernetInterface NTPClient iothub_client iothub_http_transport mbed-rtos mbed wolfSSL serializer azure_c_shared_utility
This sample showcases the usage of Azure IoT client libraries with the HTTP transport for sending/receiving raw messages from an IoT Hub.
simplesample_http.c@89:e4502f210191, 2018-09-11 (annotated)
- Committer:
- AzureIoTClient
- Date:
- Tue Sep 11 11:17:43 2018 -0700
- Revision:
- 89:e4502f210191
- Parent:
- 78:4b96969617b3
1.2.9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AzureIoTClient | 17:3abbcd6aac9f | 1 | // Copyright (c) Microsoft. All rights reserved. |
AzureIoTClient | 17:3abbcd6aac9f | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
AzureIoTClient | 17:3abbcd6aac9f | 3 | |
AzureIoTClient | 89:e4502f210191 | 4 | // |
AzureIoTClient | 89:e4502f210191 | 5 | // IMPORTANT: Please read and understand serializer limitations and alternatives as |
AzureIoTClient | 89:e4502f210191 | 6 | // described ../../readme.md before beginning to use the serializer. |
AzureIoTClient | 89:e4502f210191 | 7 | // |
AzureIoTClient | 89:e4502f210191 | 8 | |
AzureIoTClient | 17:3abbcd6aac9f | 9 | #include <stdlib.h> |
AzureIoTClient | 17:3abbcd6aac9f | 10 | |
AzureIoTClient | 17:3abbcd6aac9f | 11 | #include <stdio.h> |
AzureIoTClient | 17:3abbcd6aac9f | 12 | #include <stdint.h> |
AzureIoTClient | 17:3abbcd6aac9f | 13 | |
AzureIoTClient | 17:3abbcd6aac9f | 14 | /* This sample uses the _LL APIs of iothub_client for example purposes. |
AzureIoTClient | 17:3abbcd6aac9f | 15 | That does not mean that HTTP only works with the _LL APIs. |
AzureIoTClient | 17:3abbcd6aac9f | 16 | Simply changing the using the convenience layer (functions not having _LL) |
AzureIoTClient | 17:3abbcd6aac9f | 17 | and removing calls to _DoWork will yield the same results. */ |
AzureIoTClient | 17:3abbcd6aac9f | 18 | |
Azure.IoT Build | 41:4080293252bc | 19 | #include "azure_c_shared_utility/threadapi.h" |
Azure.IoT Build | 41:4080293252bc | 20 | #include "azure_c_shared_utility/platform.h" |
AzureIoTClient | 17:3abbcd6aac9f | 21 | #include "serializer.h" |
AzureIoTClient | 17:3abbcd6aac9f | 22 | #include "iothub_client_ll.h" |
AzureIoTClient | 17:3abbcd6aac9f | 23 | #include "iothubtransporthttp.h" |
AzureIoTClient | 17:3abbcd6aac9f | 24 | |
AzureIoTClient | 17:3abbcd6aac9f | 25 | #ifdef MBED_BUILD_TIMESTAMP |
AzureIoTClient | 73:124496f755ab | 26 | #define SET_TRUSTED_CERT_IN_SAMPLES |
AzureIoTClient | 73:124496f755ab | 27 | #endif // MBED_BUILD_TIMESTAMP |
AzureIoTClient | 73:124496f755ab | 28 | |
AzureIoTClient | 73:124496f755ab | 29 | #ifdef SET_TRUSTED_CERT_IN_SAMPLES |
AzureIoTClient | 17:3abbcd6aac9f | 30 | #include "certs.h" |
AzureIoTClient | 73:124496f755ab | 31 | #endif // SET_TRUSTED_CERT_IN_SAMPLES |
AzureIoTClient | 17:3abbcd6aac9f | 32 | |
AzureIoTClient | 19:253a0a1ea1c5 | 33 | /*String containing Hostname, Device Id & Device Key in the format: */ |
AzureIoTClient | 19:253a0a1ea1c5 | 34 | /* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */ |
AzureIoTClient | 17:3abbcd6aac9f | 35 | static const char* connectionString = "[device connection string]"; |
AzureIoTClient | 17:3abbcd6aac9f | 36 | |
AzureIoTClient | 17:3abbcd6aac9f | 37 | // Define the Model |
AzureIoTClient | 17:3abbcd6aac9f | 38 | BEGIN_NAMESPACE(WeatherStation); |
AzureIoTClient | 17:3abbcd6aac9f | 39 | |
AzureIoTClient | 17:3abbcd6aac9f | 40 | DECLARE_MODEL(ContosoAnemometer, |
AzureIoTClient | 17:3abbcd6aac9f | 41 | WITH_DATA(ascii_char_ptr, DeviceId), |
AzureIoTClient | 20:188fd25e65fc | 42 | WITH_DATA(int, WindSpeed), |
AzureIoTClient | 64:0cdbc7c1cecc | 43 | WITH_DATA(float, Temperature), |
AzureIoTClient | 64:0cdbc7c1cecc | 44 | WITH_DATA(float, Humidity), |
AzureIoTClient | 17:3abbcd6aac9f | 45 | WITH_ACTION(TurnFanOn), |
AzureIoTClient | 17:3abbcd6aac9f | 46 | WITH_ACTION(TurnFanOff), |
AzureIoTClient | 17:3abbcd6aac9f | 47 | WITH_ACTION(SetAirResistance, int, Position) |
AzureIoTClient | 17:3abbcd6aac9f | 48 | ); |
AzureIoTClient | 17:3abbcd6aac9f | 49 | |
AzureIoTClient | 17:3abbcd6aac9f | 50 | END_NAMESPACE(WeatherStation); |
AzureIoTClient | 17:3abbcd6aac9f | 51 | |
AzureIoTClient | 64:0cdbc7c1cecc | 52 | static char propText[1024]; |
AzureIoTClient | 17:3abbcd6aac9f | 53 | |
AzureIoTClient | 17:3abbcd6aac9f | 54 | EXECUTE_COMMAND_RESULT TurnFanOn(ContosoAnemometer* device) |
AzureIoTClient | 17:3abbcd6aac9f | 55 | { |
AzureIoTClient | 17:3abbcd6aac9f | 56 | (void)device; |
AzureIoTClient | 17:3abbcd6aac9f | 57 | (void)printf("Turning fan on.\r\n"); |
AzureIoTClient | 17:3abbcd6aac9f | 58 | return EXECUTE_COMMAND_SUCCESS; |
AzureIoTClient | 17:3abbcd6aac9f | 59 | } |
AzureIoTClient | 17:3abbcd6aac9f | 60 | |
AzureIoTClient | 17:3abbcd6aac9f | 61 | EXECUTE_COMMAND_RESULT TurnFanOff(ContosoAnemometer* device) |
AzureIoTClient | 17:3abbcd6aac9f | 62 | { |
AzureIoTClient | 17:3abbcd6aac9f | 63 | (void)device; |
AzureIoTClient | 17:3abbcd6aac9f | 64 | (void)printf("Turning fan off.\r\n"); |
AzureIoTClient | 17:3abbcd6aac9f | 65 | return EXECUTE_COMMAND_SUCCESS; |
AzureIoTClient | 17:3abbcd6aac9f | 66 | } |
AzureIoTClient | 17:3abbcd6aac9f | 67 | |
AzureIoTClient | 17:3abbcd6aac9f | 68 | EXECUTE_COMMAND_RESULT SetAirResistance(ContosoAnemometer* device, int Position) |
AzureIoTClient | 17:3abbcd6aac9f | 69 | { |
AzureIoTClient | 17:3abbcd6aac9f | 70 | (void)device; |
AzureIoTClient | 17:3abbcd6aac9f | 71 | (void)printf("Setting Air Resistance Position to %d.\r\n", Position); |
AzureIoTClient | 17:3abbcd6aac9f | 72 | return EXECUTE_COMMAND_SUCCESS; |
AzureIoTClient | 17:3abbcd6aac9f | 73 | } |
AzureIoTClient | 17:3abbcd6aac9f | 74 | |
AzureIoTClient | 17:3abbcd6aac9f | 75 | void sendCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback) |
AzureIoTClient | 17:3abbcd6aac9f | 76 | { |
AzureIoTClient | 42:fc9ef8d266b3 | 77 | unsigned int messageTrackingId = (unsigned int)(uintptr_t)userContextCallback; |
AzureIoTClient | 17:3abbcd6aac9f | 78 | |
AzureIoTClient | 42:fc9ef8d266b3 | 79 | (void)printf("Message Id: %u Received.\r\n", messageTrackingId); |
AzureIoTClient | 17:3abbcd6aac9f | 80 | |
AzureIoTClient | 17:3abbcd6aac9f | 81 | (void)printf("Result Call Back Called! Result is: %s \r\n", ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result)); |
AzureIoTClient | 17:3abbcd6aac9f | 82 | } |
AzureIoTClient | 17:3abbcd6aac9f | 83 | |
AzureIoTClient | 17:3abbcd6aac9f | 84 | static void sendMessage(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const unsigned char* buffer, size_t size) |
AzureIoTClient | 17:3abbcd6aac9f | 85 | { |
AzureIoTClient | 17:3abbcd6aac9f | 86 | static unsigned int messageTrackingId; |
AzureIoTClient | 17:3abbcd6aac9f | 87 | IOTHUB_MESSAGE_HANDLE messageHandle = IoTHubMessage_CreateFromByteArray(buffer, size); |
AzureIoTClient | 17:3abbcd6aac9f | 88 | if (messageHandle == NULL) |
AzureIoTClient | 17:3abbcd6aac9f | 89 | { |
AzureIoTClient | 17:3abbcd6aac9f | 90 | printf("unable to create a new IoTHubMessage\r\n"); |
AzureIoTClient | 17:3abbcd6aac9f | 91 | } |
AzureIoTClient | 17:3abbcd6aac9f | 92 | else |
AzureIoTClient | 17:3abbcd6aac9f | 93 | { |
AzureIoTClient | 17:3abbcd6aac9f | 94 | if (IoTHubClient_LL_SendEventAsync(iotHubClientHandle, messageHandle, sendCallback, (void*)(uintptr_t)messageTrackingId) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 17:3abbcd6aac9f | 95 | { |
AzureIoTClient | 17:3abbcd6aac9f | 96 | printf("failed to hand over the message to IoTHubClient"); |
AzureIoTClient | 17:3abbcd6aac9f | 97 | } |
AzureIoTClient | 17:3abbcd6aac9f | 98 | else |
AzureIoTClient | 17:3abbcd6aac9f | 99 | { |
AzureIoTClient | 17:3abbcd6aac9f | 100 | printf("IoTHubClient accepted the message for delivery\r\n"); |
AzureIoTClient | 17:3abbcd6aac9f | 101 | } |
AzureIoTClient | 17:3abbcd6aac9f | 102 | IoTHubMessage_Destroy(messageHandle); |
AzureIoTClient | 17:3abbcd6aac9f | 103 | } |
AzureIoTClient | 17:3abbcd6aac9f | 104 | free((void*)buffer); |
AzureIoTClient | 17:3abbcd6aac9f | 105 | messageTrackingId++; |
AzureIoTClient | 17:3abbcd6aac9f | 106 | } |
AzureIoTClient | 17:3abbcd6aac9f | 107 | |
AzureIoTClient | 17:3abbcd6aac9f | 108 | /*this function "links" IoTHub to the serialization library*/ |
AzureIoTClient | 17:3abbcd6aac9f | 109 | static IOTHUBMESSAGE_DISPOSITION_RESULT IoTHubMessage(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback) |
AzureIoTClient | 17:3abbcd6aac9f | 110 | { |
AzureIoTClient | 17:3abbcd6aac9f | 111 | IOTHUBMESSAGE_DISPOSITION_RESULT result; |
AzureIoTClient | 17:3abbcd6aac9f | 112 | const unsigned char* buffer; |
AzureIoTClient | 17:3abbcd6aac9f | 113 | size_t size; |
AzureIoTClient | 17:3abbcd6aac9f | 114 | if (IoTHubMessage_GetByteArray(message, &buffer, &size) != IOTHUB_MESSAGE_OK) |
AzureIoTClient | 17:3abbcd6aac9f | 115 | { |
AzureIoTClient | 17:3abbcd6aac9f | 116 | printf("unable to IoTHubMessage_GetByteArray\r\n"); |
AzureIoTClient | 56:99dabe3ce9ff | 117 | result = IOTHUBMESSAGE_ABANDONED; |
AzureIoTClient | 17:3abbcd6aac9f | 118 | } |
AzureIoTClient | 17:3abbcd6aac9f | 119 | else |
AzureIoTClient | 17:3abbcd6aac9f | 120 | { |
AzureIoTClient | 17:3abbcd6aac9f | 121 | /*buffer is not zero terminated*/ |
AzureIoTClient | 17:3abbcd6aac9f | 122 | char* temp = malloc(size + 1); |
AzureIoTClient | 17:3abbcd6aac9f | 123 | if (temp == NULL) |
AzureIoTClient | 17:3abbcd6aac9f | 124 | { |
AzureIoTClient | 17:3abbcd6aac9f | 125 | printf("failed to malloc\r\n"); |
AzureIoTClient | 56:99dabe3ce9ff | 126 | result = IOTHUBMESSAGE_ABANDONED; |
AzureIoTClient | 17:3abbcd6aac9f | 127 | } |
AzureIoTClient | 17:3abbcd6aac9f | 128 | else |
AzureIoTClient | 17:3abbcd6aac9f | 129 | { |
AzureIoTClient | 19:253a0a1ea1c5 | 130 | EXECUTE_COMMAND_RESULT executeCommandResult; |
AzureIoTClient | 89:e4502f210191 | 131 | |
AzureIoTClient | 56:99dabe3ce9ff | 132 | (void)memcpy(temp, buffer, size); |
AzureIoTClient | 17:3abbcd6aac9f | 133 | temp[size] = '\0'; |
AzureIoTClient | 19:253a0a1ea1c5 | 134 | executeCommandResult = EXECUTE_COMMAND(userContextCallback, temp); |
AzureIoTClient | 17:3abbcd6aac9f | 135 | result = |
AzureIoTClient | 17:3abbcd6aac9f | 136 | (executeCommandResult == EXECUTE_COMMAND_ERROR) ? IOTHUBMESSAGE_ABANDONED : |
AzureIoTClient | 17:3abbcd6aac9f | 137 | (executeCommandResult == EXECUTE_COMMAND_SUCCESS) ? IOTHUBMESSAGE_ACCEPTED : |
AzureIoTClient | 17:3abbcd6aac9f | 138 | IOTHUBMESSAGE_REJECTED; |
AzureIoTClient | 17:3abbcd6aac9f | 139 | free(temp); |
AzureIoTClient | 17:3abbcd6aac9f | 140 | } |
AzureIoTClient | 17:3abbcd6aac9f | 141 | } |
AzureIoTClient | 17:3abbcd6aac9f | 142 | return result; |
AzureIoTClient | 17:3abbcd6aac9f | 143 | } |
AzureIoTClient | 17:3abbcd6aac9f | 144 | |
AzureIoTClient | 17:3abbcd6aac9f | 145 | void simplesample_http_run(void) |
AzureIoTClient | 17:3abbcd6aac9f | 146 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 147 | if (platform_init() != 0) |
AzureIoTClient | 17:3abbcd6aac9f | 148 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 149 | printf("Failed to initialize the platform.\r\n"); |
AzureIoTClient | 17:3abbcd6aac9f | 150 | } |
AzureIoTClient | 17:3abbcd6aac9f | 151 | else |
AzureIoTClient | 17:3abbcd6aac9f | 152 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 153 | if (serializer_init(NULL) != SERIALIZER_OK) |
AzureIoTClient | 17:3abbcd6aac9f | 154 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 155 | (void)printf("Failed on serializer_init\r\n"); |
AzureIoTClient | 17:3abbcd6aac9f | 156 | } |
AzureIoTClient | 17:3abbcd6aac9f | 157 | else |
AzureIoTClient | 17:3abbcd6aac9f | 158 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 159 | IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, HTTP_Protocol); |
Azure.IoT Build | 28:44b1d44d0d3b | 160 | int avgWindSpeed = 10; |
AzureIoTClient | 64:0cdbc7c1cecc | 161 | float minTemperature = 20.0; |
AzureIoTClient | 64:0cdbc7c1cecc | 162 | float minHumidity = 60.0; |
AzureIoTClient | 17:3abbcd6aac9f | 163 | |
Azure.IoT Build | 28:44b1d44d0d3b | 164 | srand((unsigned int)time(NULL)); |
Azure.IoT Build | 28:44b1d44d0d3b | 165 | |
Azure.IoT Build | 28:44b1d44d0d3b | 166 | if (iotHubClientHandle == NULL) |
AzureIoTClient | 17:3abbcd6aac9f | 167 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 168 | (void)printf("Failed on IoTHubClient_LL_Create\r\n"); |
AzureIoTClient | 17:3abbcd6aac9f | 169 | } |
AzureIoTClient | 17:3abbcd6aac9f | 170 | else |
AzureIoTClient | 17:3abbcd6aac9f | 171 | { |
AzureIoTClient | 89:e4502f210191 | 172 | // Because it can poll "after 9 seconds" polls will happen |
Azure.IoT Build | 28:44b1d44d0d3b | 173 | // effectively at ~10 seconds. |
Azure.IoT Build | 28:44b1d44d0d3b | 174 | // Note that for scalabilty, the default value of minimumPollingTime |
Azure.IoT Build | 28:44b1d44d0d3b | 175 | // is 25 minutes. For more information, see: |
Azure.IoT Build | 28:44b1d44d0d3b | 176 | // https://azure.microsoft.com/documentation/articles/iot-hub-devguide/#messaging |
Azure.IoT Build | 28:44b1d44d0d3b | 177 | unsigned int minimumPollingTime = 9; |
Azure.IoT Build | 28:44b1d44d0d3b | 178 | ContosoAnemometer* myWeather; |
Azure.IoT Build | 28:44b1d44d0d3b | 179 | |
Azure.IoT Build | 28:44b1d44d0d3b | 180 | if (IoTHubClient_LL_SetOption(iotHubClientHandle, "MinimumPollingTime", &minimumPollingTime) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 17:3abbcd6aac9f | 181 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 182 | printf("failure to set option \"MinimumPollingTime\"\r\n"); |
Azure.IoT Build | 28:44b1d44d0d3b | 183 | } |
Azure.IoT Build | 28:44b1d44d0d3b | 184 | |
AzureIoTClient | 73:124496f755ab | 185 | #ifdef SET_TRUSTED_CERT_IN_SAMPLES |
Azure.IoT Build | 28:44b1d44d0d3b | 186 | // For mbed add the certificate information |
Azure.IoT Build | 28:44b1d44d0d3b | 187 | if (IoTHubClient_LL_SetOption(iotHubClientHandle, "TrustedCerts", certificates) != IOTHUB_CLIENT_OK) |
Azure.IoT Build | 28:44b1d44d0d3b | 188 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 189 | (void)printf("failure to set option \"TrustedCerts\"\r\n"); |
Azure.IoT Build | 28:44b1d44d0d3b | 190 | } |
AzureIoTClient | 73:124496f755ab | 191 | #endif // SET_TRUSTED_CERT_IN_SAMPLES |
Azure.IoT Build | 28:44b1d44d0d3b | 192 | |
Azure.IoT Build | 28:44b1d44d0d3b | 193 | myWeather = CREATE_MODEL_INSTANCE(WeatherStation, ContosoAnemometer); |
Azure.IoT Build | 28:44b1d44d0d3b | 194 | if (myWeather == NULL) |
Azure.IoT Build | 28:44b1d44d0d3b | 195 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 196 | (void)printf("Failed on CREATE_MODEL_INSTANCE\r\n"); |
AzureIoTClient | 17:3abbcd6aac9f | 197 | } |
AzureIoTClient | 17:3abbcd6aac9f | 198 | else |
AzureIoTClient | 17:3abbcd6aac9f | 199 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 200 | if (IoTHubClient_LL_SetMessageCallback(iotHubClientHandle, IoTHubMessage, myWeather) != IOTHUB_CLIENT_OK) |
AzureIoTClient | 17:3abbcd6aac9f | 201 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 202 | printf("unable to IoTHubClient_SetMessageCallback\r\n"); |
Azure.IoT Build | 28:44b1d44d0d3b | 203 | } |
Azure.IoT Build | 28:44b1d44d0d3b | 204 | else |
Azure.IoT Build | 28:44b1d44d0d3b | 205 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 206 | myWeather->DeviceId = "myFirstDevice"; |
Azure.IoT Build | 28:44b1d44d0d3b | 207 | myWeather->WindSpeed = avgWindSpeed + (rand() % 4 + 2); |
AzureIoTClient | 64:0cdbc7c1cecc | 208 | myWeather->Temperature = minTemperature + (rand() % 10); |
AzureIoTClient | 64:0cdbc7c1cecc | 209 | myWeather->Humidity = minHumidity + (rand() % 20); |
AzureIoTClient | 17:3abbcd6aac9f | 210 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 211 | unsigned char* destination; |
Azure.IoT Build | 28:44b1d44d0d3b | 212 | size_t destinationSize; |
AzureIoTClient | 64:0cdbc7c1cecc | 213 | if (SERIALIZE(&destination, &destinationSize, myWeather->DeviceId, myWeather->WindSpeed, myWeather->Temperature, myWeather->Humidity) != CODEFIRST_OK) |
AzureIoTClient | 17:3abbcd6aac9f | 214 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 215 | (void)printf("Failed to serialize\r\n"); |
AzureIoTClient | 17:3abbcd6aac9f | 216 | } |
AzureIoTClient | 17:3abbcd6aac9f | 217 | else |
AzureIoTClient | 17:3abbcd6aac9f | 218 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 219 | IOTHUB_MESSAGE_HANDLE messageHandle = IoTHubMessage_CreateFromByteArray(destination, destinationSize); |
Azure.IoT Build | 28:44b1d44d0d3b | 220 | if (messageHandle == NULL) |
AzureIoTClient | 17:3abbcd6aac9f | 221 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 222 | printf("unable to create a new IoTHubMessage\r\n"); |
AzureIoTClient | 17:3abbcd6aac9f | 223 | } |
AzureIoTClient | 17:3abbcd6aac9f | 224 | else |
AzureIoTClient | 17:3abbcd6aac9f | 225 | { |
AzureIoTClient | 64:0cdbc7c1cecc | 226 | MAP_HANDLE propMap = IoTHubMessage_Properties(messageHandle); |
AzureIoTClient | 64:0cdbc7c1cecc | 227 | (void)sprintf_s(propText, sizeof(propText), myWeather->Temperature > 28 ? "true" : "false"); |
AzureIoTClient | 64:0cdbc7c1cecc | 228 | if (Map_AddOrUpdate(propMap, "temperatureAlert", propText) != MAP_OK) |
AzureIoTClient | 64:0cdbc7c1cecc | 229 | { |
AzureIoTClient | 64:0cdbc7c1cecc | 230 | printf("ERROR: Map_AddOrUpdate Failed!\r\n"); |
AzureIoTClient | 64:0cdbc7c1cecc | 231 | } |
AzureIoTClient | 64:0cdbc7c1cecc | 232 | |
Azure.IoT Build | 28:44b1d44d0d3b | 233 | if (IoTHubClient_LL_SendEventAsync(iotHubClientHandle, messageHandle, sendCallback, (void*)1) != IOTHUB_CLIENT_OK) |
Azure.IoT Build | 28:44b1d44d0d3b | 234 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 235 | printf("failed to hand over the message to IoTHubClient"); |
Azure.IoT Build | 28:44b1d44d0d3b | 236 | } |
Azure.IoT Build | 28:44b1d44d0d3b | 237 | else |
Azure.IoT Build | 28:44b1d44d0d3b | 238 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 239 | printf("IoTHubClient accepted the message for delivery\r\n"); |
Azure.IoT Build | 28:44b1d44d0d3b | 240 | } |
AzureIoTClient | 17:3abbcd6aac9f | 241 | |
Azure.IoT Build | 28:44b1d44d0d3b | 242 | IoTHubMessage_Destroy(messageHandle); |
Azure.IoT Build | 28:44b1d44d0d3b | 243 | } |
Azure.IoT Build | 28:44b1d44d0d3b | 244 | free(destination); |
AzureIoTClient | 17:3abbcd6aac9f | 245 | } |
Azure.IoT Build | 28:44b1d44d0d3b | 246 | } |
Azure.IoT Build | 28:44b1d44d0d3b | 247 | |
Azure.IoT Build | 28:44b1d44d0d3b | 248 | /* wait for commands */ |
Azure.IoT Build | 28:44b1d44d0d3b | 249 | while (1) |
Azure.IoT Build | 28:44b1d44d0d3b | 250 | { |
Azure.IoT Build | 28:44b1d44d0d3b | 251 | IoTHubClient_LL_DoWork(iotHubClientHandle); |
Azure.IoT Build | 28:44b1d44d0d3b | 252 | ThreadAPI_Sleep(100); |
AzureIoTClient | 17:3abbcd6aac9f | 253 | } |
AzureIoTClient | 17:3abbcd6aac9f | 254 | } |
AzureIoTClient | 17:3abbcd6aac9f | 255 | |
Azure.IoT Build | 28:44b1d44d0d3b | 256 | DESTROY_MODEL_INSTANCE(myWeather); |
AzureIoTClient | 17:3abbcd6aac9f | 257 | } |
Azure.IoT Build | 28:44b1d44d0d3b | 258 | IoTHubClient_LL_Destroy(iotHubClientHandle); |
AzureIoTClient | 17:3abbcd6aac9f | 259 | } |
Azure.IoT Build | 28:44b1d44d0d3b | 260 | serializer_deinit(); |
AzureIoTClient | 17:3abbcd6aac9f | 261 | } |
Azure.IoT Build | 28:44b1d44d0d3b | 262 | platform_deinit(); |
AzureIoTClient | 17:3abbcd6aac9f | 263 | } |
AzureIoTClient | 17:3abbcd6aac9f | 264 | } |