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.

Revision:
2:fc3132155be8
Parent:
0:caa8884fe136
Child:
5:f681a1af27c6
--- a/main.cpp	Wed Sep 16 21:36:50 2015 +0000
+++ b/main.cpp	Wed Sep 16 22:43:21 2015 -0700
@@ -6,6 +6,32 @@
 #include "mbed/logging.h"
 #include "mbed/mbedtime.h"
 #include "simplesample_amqp.h"
+#include "NTPClient.h"
+
+void setupRealTime(void)
+{
+	(void)printf("setupRealTime begin\r\n");
+	if (EthernetInterface::connect())
+	{
+		(void)printf("Error initializing EthernetInterface.\r\n");
+	}
+	else
+	{
+		(void)printf("setupRealTime NTP begin\r\n");
+		NTPClient ntp;
+		if (ntp.setTime("0.pool.ntp.org") != 0)
+		{
+			(void)printf("Failed setting time.\r\n");
+		}
+		else
+		{
+			(void)printf("set time correctly!\r\n");
+		}
+		(void)printf("setupRealTime NTP end\r\n");
+		EthernetInterface::disconnect();
+	}
+	(void)printf("setupRealTime end\r\n");
+}
 
 int main(void)
 {
@@ -14,12 +40,27 @@
     mbed_log_init();
     mbedtime_init();
 
-    EthernetInterface eth;
-    if (eth.init() || eth.connect())
-    {
-        (void)printf("Error initializing EthernetInterface.\r\n");
-        return -1;
-    }
+	if (EthernetInterface::init())
+	{
+		(void)printf("Error initializing EthernetInterface.\r\n");
+		return -1;
+	}
+
+	if (setupRealTime() != 0)
+	{
+		(void)printf("Failed setting up real time clock\r\n");
+		return -1;
+	}
+
+	if (EthernetInterface::connect())
+	{
+		(void)printf("Error connecting EthernetInterface.\r\n");
+		return -1;
+	}
 
     simplesample_amqp_run();
+
+	(void)EthernetInterface::disconnect();
+
+	return 0;
 }