A simple IoTHub sample using AMQP as transport

Dependencies:   EthernetInterface NTPClient iothub_amqp_transport iothub_client mbed-rtos mbed azure_c_shared_utility serializer wolfSSL azure_uamqp_c

This sample showcases the usage of Azure IoT client libraries with the AMQP transport for sending/receiving raw messages from an IoT Hub.

Committer:
AzureIoTClient
Date:
Mon Sep 28 18:34:54 2015 -0700
Revision:
11:6eac761707a0
Parent:
6:8121913f61d7
v1.0.0-preview.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 0:caa8884fe136 1 // Copyright (c) Microsoft. All rights reserved.
AzureIoTClient 0:caa8884fe136 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
AzureIoTClient 0:caa8884fe136 3
AzureIoTClient 0:caa8884fe136 4 #include <stdio.h>
AzureIoTClient 0:caa8884fe136 5 #include "EthernetInterface.h"
AzureIoTClient 0:caa8884fe136 6 #include "mbed/logging.h"
AzureIoTClient 0:caa8884fe136 7 #include "mbed/mbedtime.h"
AzureIoTClient 0:caa8884fe136 8 #include "simplesample_amqp.h"
AzureIoTClient 2:fc3132155be8 9 #include "NTPClient.h"
AzureIoTClient 2:fc3132155be8 10
AzureIoTClient 5:f681a1af27c6 11 int setupRealTime(void)
AzureIoTClient 2:fc3132155be8 12 {
AzureIoTClient 6:8121913f61d7 13 int result;
AzureIoTClient 6:8121913f61d7 14
AzureIoTClient 2:fc3132155be8 15 (void)printf("setupRealTime begin\r\n");
AzureIoTClient 2:fc3132155be8 16 if (EthernetInterface::connect())
AzureIoTClient 2:fc3132155be8 17 {
AzureIoTClient 2:fc3132155be8 18 (void)printf("Error initializing EthernetInterface.\r\n");
AzureIoTClient 5:f681a1af27c6 19 result = __LINE__;
AzureIoTClient 2:fc3132155be8 20 }
AzureIoTClient 2:fc3132155be8 21 else
AzureIoTClient 2:fc3132155be8 22 {
AzureIoTClient 2:fc3132155be8 23 (void)printf("setupRealTime NTP begin\r\n");
AzureIoTClient 2:fc3132155be8 24 NTPClient ntp;
AzureIoTClient 2:fc3132155be8 25 if (ntp.setTime("0.pool.ntp.org") != 0)
AzureIoTClient 2:fc3132155be8 26 {
AzureIoTClient 2:fc3132155be8 27 (void)printf("Failed setting time.\r\n");
AzureIoTClient 5:f681a1af27c6 28 result = __LINE__;
AzureIoTClient 2:fc3132155be8 29 }
AzureIoTClient 2:fc3132155be8 30 else
AzureIoTClient 2:fc3132155be8 31 {
AzureIoTClient 2:fc3132155be8 32 (void)printf("set time correctly!\r\n");
AzureIoTClient 5:f681a1af27c6 33 result = 0;
AzureIoTClient 2:fc3132155be8 34 }
AzureIoTClient 2:fc3132155be8 35 (void)printf("setupRealTime NTP end\r\n");
AzureIoTClient 2:fc3132155be8 36 EthernetInterface::disconnect();
AzureIoTClient 2:fc3132155be8 37 }
AzureIoTClient 2:fc3132155be8 38 (void)printf("setupRealTime end\r\n");
AzureIoTClient 5:f681a1af27c6 39
AzureIoTClient 5:f681a1af27c6 40 return result;
AzureIoTClient 2:fc3132155be8 41 }
AzureIoTClient 0:caa8884fe136 42
AzureIoTClient 0:caa8884fe136 43 int main(void)
AzureIoTClient 0:caa8884fe136 44 {
AzureIoTClient 0:caa8884fe136 45 (void)printf("Initializing mbed specific things...\r\n");
AzureIoTClient 0:caa8884fe136 46
AzureIoTClient 11:6eac761707a0 47 /* These are needed in order to initialize the time provider for Proton-C */
AzureIoTClient 0:caa8884fe136 48 mbed_log_init();
AzureIoTClient 0:caa8884fe136 49 mbedtime_init();
AzureIoTClient 0:caa8884fe136 50
AzureIoTClient 2:fc3132155be8 51 if (EthernetInterface::init())
AzureIoTClient 2:fc3132155be8 52 {
AzureIoTClient 2:fc3132155be8 53 (void)printf("Error initializing EthernetInterface.\r\n");
AzureIoTClient 2:fc3132155be8 54 return -1;
AzureIoTClient 2:fc3132155be8 55 }
AzureIoTClient 2:fc3132155be8 56
AzureIoTClient 2:fc3132155be8 57 if (setupRealTime() != 0)
AzureIoTClient 2:fc3132155be8 58 {
AzureIoTClient 2:fc3132155be8 59 (void)printf("Failed setting up real time clock\r\n");
AzureIoTClient 2:fc3132155be8 60 return -1;
AzureIoTClient 2:fc3132155be8 61 }
AzureIoTClient 2:fc3132155be8 62
AzureIoTClient 2:fc3132155be8 63 if (EthernetInterface::connect())
AzureIoTClient 2:fc3132155be8 64 {
AzureIoTClient 2:fc3132155be8 65 (void)printf("Error connecting EthernetInterface.\r\n");
AzureIoTClient 2:fc3132155be8 66 return -1;
AzureIoTClient 2:fc3132155be8 67 }
AzureIoTClient 0:caa8884fe136 68
AzureIoTClient 0:caa8884fe136 69 simplesample_amqp_run();
AzureIoTClient 2:fc3132155be8 70
AzureIoTClient 2:fc3132155be8 71 (void)EthernetInterface::disconnect();
AzureIoTClient 2:fc3132155be8 72
AzureIoTClient 2:fc3132155be8 73 return 0;
AzureIoTClient 0:caa8884fe136 74 }