Bhavin Darji / Mbed 2 deprecated Eg12_NTPclient_Time_stm32f4test

Dependencies:   NTPClient mbed-rtos mbed

Fork of Eg12_NTPclient_Time by Edutech IoT Team

Files at this revision

API Documentation at this revision

Comitter:
brdarji
Date:
Thu Mar 22 07:35:01 2018 +0000
Parent:
1:039c06964ad9
Commit message:
STM32f4 Eth example;

Changed in this revision

C12832_lcd.lib Show diff for this revision Revisions of this file
EthernetInterface.lib 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/C12832_lcd.lib	Sat Oct 10 09:23:23 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
--- a/EthernetInterface.lib	Sat Oct 10 09:23:23 2015 +0000
+++ b/EthernetInterface.lib	Thu Mar 22 07:35:01 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
+https://os.mbed.com/users/brdarji/code/EthernetInterface/#c7159cfc078a
--- a/main.cpp	Sat Oct 10 09:23:23 2015 +0000
+++ b/main.cpp	Thu Mar 22 07:35:01 2018 +0000
@@ -1,41 +1,53 @@
 #include "mbed.h"                   // Basic Library required for onchip peripherals
 #include "EthernetInterface.h"      // Ethernet Library 
 #include "NTPClient.h"              // Network Time Protocol client Library
-#include "C12832_lcd.h"             // Library for SPI based LCD
+//#include "C12832_lcd.h"             // Library for SPI based LCD
 
 /* Create Objects */  
-C12832_LCD lcd;         // Initialize lcd object with SPI pins
+
 EthernetInterface eth;  // Initialize Ethernet object
 NTPClient ntp;          // Initialize NTP object
-
+Serial pc(PC_6,PC_7);
+//Serial pc(USBTX,USBRX);
 // For Static IP
-static const char* mbedIp       = "192.168.0.160";  //IP
+static const char* mbedIp       = "192.168.1.160";  //IP
 static const char* mbedMask     = "255.255.255.0";  // Mask
-static const char* mbedGateway  = "192.168.0.254";  //Gateway
+static const char* mbedGateway  = "192.168.1.1";  //Gateway
 
 int main()
 {
     EthernetInterface eth;
-    // eth.init(); // For DHCP uncomment this line
-    eth.init(mbedIp,mbedMask,mbedGateway); //Use these parameters for static IP (Comment for DHCP)
-    eth.connect(); //Connect with Network and get IP address
-    lcd.printf("Connected! IP Address is %s\n", eth.getIPAddress());
-    
-    lcd.cls();
-    lcd.printf("Trying to update time...\r\n");
+     int s = eth.init(); // For DHCP uncomment this line
+//    int s = eth.init(mbedIp,mbedMask,mbedGateway); //Use these parameters for static IP
+    if( s != NULL )
+    {
+        pc.printf( "Could not initialise. Will halt!\n\r" );        
+        exit( 0 );
+    }    
+    s = eth.connect();
+    if( s != NULL )
+    {
+        pc.printf( "Could not connect. Will halt!\n\r" );
+        exit( 0 );
+    }
+    else 
+    {
+        pc.printf( "IP: %s\n\r", eth.getIPAddress() );    
+    }
+    pc.printf("Connected! IP Address is %s\r\n", eth.getIPAddress());
+    pc.printf("Trying to update time...\r\n");
     if (ntp.setTime("0.pool.ntp.org") == 0) { // ntp server
-        lcd.printf("Set time successfully\r\n");
+        pc.printf("Set time successfully\r\n");
         while(1) {
-            lcd.cls();
-            lcd.locate(0,0);
+            
             time_t ctTime;
             ctTime = time(NULL);
-            lcd.printf("%s\r\n", ctime(&ctTime));
-            lcd.printf("Current Time (UTC)");
+            pc.printf("%s\r\n", ctime(&ctTime));
+            pc.printf("Current Time (UTC)");
             wait(1);
         }
     } else {
-        lcd.printf("NTP Error\r\n");
+        pc.printf("NTP Error\r\n");
     }
 
     eth.disconnect();