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: EthernetInterface NTPClient iothub_amqp_transport iothub_client mbed-rtos mbed
Fork of iothub_client_sample_amqp by
Revision 31:7a8aed41e109, committed 2016-02-04
- Comitter:
- Azure.IoT Build
- Date:
- Thu Feb 04 16:01:03 2016 -0800
- Parent:
- 30:4fc347bc76fb
- Child:
- 32:8781be2152df
- Commit message:
- 1.0.0
Changed in this revision
| iothub_client_sample_amqp.c | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/iothub_client_sample_amqp.c Fri Jan 29 23:42:22 2016 +0000
+++ b/iothub_client_sample_amqp.c Thu Feb 04 16:01:03 2016 -0800
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include "platform.h"
#include "iothub_client.h"
#include "iothub_message.h"
#include "threadapi.h"
@@ -14,8 +15,6 @@
#include "certs.h"
#endif // MBED_BUILD_TIMESTAMP
-/*String containing Hostname, Device Id & Device Key in the format: */
-/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */
static const char* connectionString = "[device connection string]";
static int callbackCounter;
@@ -30,12 +29,36 @@
static IOTHUBMESSAGE_DISPOSITION_RESULT ReceiveMessageCallback(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback)
{
int* counter = (int*)userContextCallback;
- const char* buffer;
- size_t size;
+ const unsigned char* buffer = NULL;
+ size_t size = 0;
+
+ IOTHUBMESSAGE_CONTENT_TYPE contentType = IoTHubMessage_GetContentType(message);
- if (IoTHubMessage_GetByteArray(message, (const unsigned char**)&buffer, &size) == IOTHUB_MESSAGE_OK)
+ if (contentType == IOTHUBMESSAGE_BYTEARRAY)
+ {
+ if (IoTHubMessage_GetByteArray(message, &buffer, &size) == IOTHUB_MESSAGE_OK)
+ {
+ (void)printf("Received Message [%d] with BINARY Data: <<<%.*s>>> & Size=%d\r\n", *counter, (int)size, buffer, (int)size);
+ }
+ else
+ {
+ (void)printf("Failed getting the BINARY body of the message received.\r\n");
+ }
+ }
+ else if (contentType == IOTHUBMESSAGE_STRING)
{
- (void)printf("Received Message [%d] with Data: <<<%.*s>>> & Size=%d\r\n", *counter, (int)size, buffer, (int)size);
+ if ((buffer = IoTHubMessage_GetString(message)) != NULL && (size = strlen(buffer)) > 0)
+ {
+ (void)printf("Received Message [%d] with STRING Data: <<<%.*s>>> & Size=%d\r\n", *counter, (int)size, buffer, (int)size);
+ }
+ else
+ {
+ (void)printf("Failed getting the STRING body of the message received.\r\n");
+ }
+ }
+ else
+ {
+ (void)printf("Failed getting the body of the message received (type %i).\r\n", contentType);
}
// Retrieve properties from the message
@@ -49,8 +72,10 @@
{
if (propertyCount > 0)
{
+ size_t index;
+
printf("Message Properties:\r\n");
- for (size_t index = 0; index < propertyCount; index++)
+ for (index = 0; index < propertyCount; index++)
{
printf("\tKey: %s Value: %s\r\n", keys[index], values[index]);
}
@@ -78,7 +103,7 @@
#define MESSAGE_COUNT 5
void iothub_client_sample_amqp_run(void)
-{
+{
IOTHUB_CLIENT_HANDLE iotHubClientHandle;
EVENT_INSTANCE messages[MESSAGE_COUNT];
@@ -90,7 +115,7 @@
int receiveContext = 0;
(void)printf("Starting the IoTHub client sample AMQP...\r\n");
-
+
if ((iotHubClientHandle = IoTHubClient_CreateFromConnectionString(connectionString, AMQP_Protocol)) == NULL)
{
(void)printf("ERROR: iotHubClientHandle is NULL!\r\n");
--- a/main.cpp Fri Jan 29 23:42:22 2016 +0000
+++ b/main.cpp Thu Feb 04 16:01:03 2016 -0800
@@ -2,28 +2,19 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <stdio.h>
-#include "EthernetInterface.h"
-#include "mbed/logging.h"
-#include "mbed/mbedtime.h"
+#include "platform.h"
#include "iothub_client_sample_amqp.h"
-#include "NTPClient.h"
-#include "azureiot_common/platform.h"
int main(void)
{
(void)printf("Initializing mbed specific things...\r\n");
- /* These are needed in order to initialize the time provider for Proton-C */
- mbed_log_init();
- mbedtime_init();
- int result;
-
- if ((result = platform_init()) != 0)
+ if (platform_init() != 0)
{
- (void)printf("Error initializing the platform: %d\r\n",result);
+ (void)printf("Failed initializing platform.\r\n");
return -1;
}
-
+
iothub_client_sample_amqp_run();
platform_deinit();
