Mark Radbourne / Mbed 2 deprecated FXOS8700CQ_To_Azure_IoT

Dependencies:   azure_umqtt_c iothub_mqtt_transport mbed-rtos mbed wolfSSL Socket lwip-eth lwip-sys lwip

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 <stdlib.h>
00005 #ifdef _CRTDBG_MAP_ALLOC
00006 #include <crtdbg.h>
00007 #endif
00008 #include "azure_c_shared_utility/platform.h"
00009 #include "EthernetInterface.h"
00010 #include "NTPClient.h"
00011 #include "azure_c_shared_utility/xio.h"
00012 #include "azure_c_shared_utility/tlsio_wolfssl.h"
00013 
00014 #include <mbed.h>
00015 
00016 int setupRealTime(void)
00017 {
00018     int result;
00019 
00020     if (EthernetInterface::connect())
00021     {
00022         result = __LINE__;
00023     }
00024     else
00025     {
00026         NTPClient ntp;
00027         if (ntp.setTime("0.pool.ntp.org") != 0)
00028         {
00029             result = __LINE__;
00030         }
00031         else
00032         {
00033             result = 0;
00034         }
00035         EthernetInterface::disconnect();
00036     }
00037 
00038     return result;
00039 }
00040 
00041 int platform_init()
00042 {
00043     printf("In platform_init\r\n");
00044     int result = 0;
00045 
00046     printf("EthernetInterface::init\r\n");
00047     if (EthernetInterface::init())
00048     {
00049         printf("EthernetInterface::init failed\r\n");
00050         result = __LINE__;
00051     }
00052 
00053     if (result == 0)
00054     {
00055         float waitPeriod = 1.0;
00056         printf("EthernetInterface::connect\r\n");
00057         while (EthernetInterface::connect())
00058         {
00059             printf("EthernetInterface::connect failed\r\n");
00060             wait(waitPeriod);
00061             //waitPeriod = (waitPeriod > 120)? waitPeriod : waitPeriod * 2.0;
00062             //EthernetInterface::init();
00063         }        
00064     }
00065     
00066     if (result == 0)
00067     {
00068         NTPClient ntp;
00069         
00070         printf("ntp.setTime\r\n");
00071         if (ntp.setTime("0.pool.ntp.org") != 0)
00072         {
00073             result = __LINE__;
00074             printf("ntp.setTime failed\r\n");
00075         }
00076     }
00077 
00078     return result;
00079 }
00080 
00081 const IO_INTERFACE_DESCRIPTION* platform_get_default_tlsio(void)
00082 {
00083     return tlsio_wolfssl_get_interface_description();
00084 }
00085 
00086 void platform_deinit(void)
00087 {
00088     EthernetInterface::disconnect();
00089 }