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:
- 36:eb9d95ee6d63
- Parent:
- 30:0a147a179e7e
- Child:
- 37:fdee5b96897d
--- a/iothub_client_sample_mqtt.c Fri Apr 21 14:52:07 2017 -0700 +++ b/iothub_client_sample_mqtt.c Mon May 08 10:52:19 2017 -0700 @@ -115,6 +115,8 @@ g_continueRunning = true; srand((unsigned int)time(NULL)); double avgWindSpeed = 10.0; + double minTemperature = 20.0; + double minHumidity = 60.0; callbackCounter = 0; int receiveContext = 0; @@ -153,11 +155,15 @@ /* Now that we are ready to receive commands, let's send some messages */ size_t iterator = 0; + double temperature = 0; + double humidity = 0; do { if (iterator < MESSAGE_COUNT) { - sprintf_s(msgText, sizeof(msgText), "{\"deviceId\":\"myFirstDevice\",\"windSpeed\":%.2f}", avgWindSpeed + (rand() % 4 + 2)); + temperature = minTemperature + (rand() % 10); + humidity = minHumidity + (rand() % 20); + sprintf_s(msgText, sizeof(msgText), "{\"deviceId\":\"myFirstDevice\",\"windSpeed\":%.2f,\"temperature\":%.2f,\"humidity\":%.2f}", avgWindSpeed + (rand() % 4 + 2), temperature, humidity); if ((messages[iterator].messageHandle = IoTHubMessage_CreateFromByteArray((const unsigned char*)msgText, strlen(msgText))) == NULL) { (void)printf("ERROR: iotHubMessageHandle is NULL!\r\n"); @@ -166,8 +172,8 @@ { messages[iterator].messageTrackingId = iterator; MAP_HANDLE propMap = IoTHubMessage_Properties(messages[iterator].messageHandle); - (void)sprintf_s(propText, sizeof(propText), "PropMsg_%zu", iterator); - if (Map_AddOrUpdate(propMap, "PropName", propText) != MAP_OK) + (void)sprintf_s(propText, sizeof(propText), temperature > 28 ? "true" : "false"); + if (Map_AddOrUpdate(propMap, "temperatureAlert", propText) != MAP_OK) { (void)printf("ERROR: Map_AddOrUpdate Failed!\r\n"); }