Mark Radbourne / Mbed 2 deprecated iothub_client_sample_amqp

Dependencies:   EthernetInterface NTPClient iothub_amqp_transport iothub_client mbed-rtos mbed

Fork of iothub_client_sample_amqp by Azure IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers platform_mbed.cpp Source File

platform_mbed.cpp

00001 // Copyright (c) Microsoft. All rights reserved.
00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
00003 
00004 #include "azure_c_shared_utility/tlsio_mbedconfig.h"
00005 
00006 #include <stdlib.h>
00007 #include <stdio.h>
00008 #ifdef _CRTDBG_MAP_ALLOC
00009 #include <crtdbg.h>
00010 #endif
00011 #include "azure_c_shared_utility/platform.h"
00012 #include "EthernetInterface.h"
00013 #include "NTPClient.h"
00014 #include "azure_c_shared_utility/xio.h"
00015 
00016 #if defined(USE_WOLF_SSL)
00017 #include "azure_c_shared_utility/tlsio_wolfssl.h"
00018 #elif defined(USE_MBED_TLS)
00019 #include "azure_c_shared_utility/tlsio_mbedtls.h"
00020 #else
00021 #error No TLS/SSL library has been specified (see tlsio_mbedconfig.h)
00022 #endif
00023 
00024 int setupRealTime(void)
00025 {
00026     int result;
00027 
00028     if (EthernetInterface::connect())
00029     {
00030         result = __LINE__;
00031     }
00032     else
00033     {
00034         NTPClient ntp;
00035         if (ntp.setTime("0.pool.ntp.org") != 0)
00036         {
00037             result = __LINE__;
00038         }
00039         else
00040         {
00041             result = 0;
00042         }
00043         EthernetInterface::disconnect();
00044     }
00045 
00046     return result;
00047 }
00048 
00049 int platform_init(void)
00050 {
00051     printf("Initializing platform\r\n");
00052     int result;
00053 
00054     if (EthernetInterface::init())
00055     {
00056         result = __LINE__;
00057     }
00058     else if (setupRealTime() != 0)
00059     {
00060         result = __LINE__;
00061     } 
00062     else if (EthernetInterface::connect())
00063     {
00064         result = __LINE__;
00065     }
00066     else
00067     {
00068         result = 0;
00069     }
00070 
00071     return result;
00072 }
00073 
00074 const IO_INTERFACE_DESCRIPTION* platform_get_default_tlsio(void)
00075 {
00076     printf("Returning tlsio\r\n");
00077 #if defined(USE_WOLF_SSL)
00078     return tlsio_wolfssl_get_interface_description();
00079 #else
00080     return tlsio_mbedtls_get_interface_description();
00081 #endif
00082 }
00083 
00084 void platform_deinit(void)
00085 {
00086     EthernetInterface::disconnect();
00087 }