NTP client app setting system time and X-NUCLEO-IDW01M1 Wi-Fi board time connecting to internet NTP UTC time server.

Dependencies:   NTPClient NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed

Fork of NTPClient_HelloWorld by ST Expansion SW Team

Example of retrieval of current time using an NTP server. Time is then used to perform a TLS secure connection to https://mbed.org.
The application is meant to be used with mbed OS 2 ("Classic") only (no mbedOS 5 support).

Files at this revision

API Documentation at this revision

Comitter:
mapellil
Date:
Thu Dec 15 10:09:47 2016 +0000
Parent:
2:bf7dc5f5bca9
Child:
4:11f2b556765b
Commit message:
Replaced Ethernet interface with NetworkSocketAPI, added support to X_NUCLEO_IDWM01M1v2 wifi board

Changed in this revision

EthernetInterface.lib Show diff for this revision Revisions of this file
NTPClient.lib Show annotated file Show diff for this revision Revisions of this file
NetworkSocketAPI.lib Show annotated file Show diff for this revision Revisions of this file
X_NUCLEO_IDW01M1v2.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
mbed-rtos.lib Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.lib	Sun Aug 05 16:17:31 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#2a797ba9babe
--- a/NTPClient.lib	Sun Aug 05 16:17:31 2012 +0000
+++ b/NTPClient.lib	Thu Dec 15 10:09:47 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/donatien/code/NTPClient/#881559865a93
+https://developer.mbed.org/teams/ST-Expansion-SW-Team/code/NTPClient/#fe36718063a5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NetworkSocketAPI.lib	Thu Dec 15 10:09:47 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/#ea3a618e0818
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDW01M1v2.lib	Thu Dec 15 10:09:47 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/X_NUCLEO_IDW01M1v2/#0368732b5b9d
--- a/main.cpp	Sun Aug 05 16:17:31 2012 +0000
+++ b/main.cpp	Thu Dec 15 10:09:47 2016 +0000
@@ -1,31 +1,29 @@
 #include "mbed.h"
-#include "EthernetInterface.h"
+#include "SpwfInterface.h"
 #include "NTPClient.h"
 
-EthernetInterface eth;
-NTPClient ntp;
-
 int main() 
 {
-    eth.init(); //Use DHCP
+    time_t ctTime;
+    ctTime = time(NULL);
+    
+    SpwfSAInterface spwf(D8, D2, false);  
+    printf ("\n\rConnecting to WiFi ...\n\r");  
+//    spwf.connect("WIFI_NET_SSID","WIFI_NET_PASSW", NSAPI_SECURITY_WPA2);
+    spwf.connect("wifi_ssid","wifi_passw", NSAPI_SECURITY_WPA2);
+    NTPClient ntp(spwf);        
 
-    eth.connect();
-   
+    printf("Initial System Time is: %s\r\n", ctime(&ctTime));   
     printf("Trying to update time...\r\n");
     if (ntp.setTime("0.pool.ntp.org") == 0)
     {
       printf("Set time successfully\r\n");
-      time_t ctTime;
       ctTime = time(NULL);
       printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
     }
     else
     {
       printf("Error\r\n");
-    } 
-   
-    eth.disconnect();  
-
-    while(1) {
-    }
+    }    
+    spwf.disconnect();
 }
--- a/mbed-rtos.lib	Sun Aug 05 16:17:31 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90
--- a/mbed.bld	Sun Aug 05 16:17:31 2012 +0000
+++ b/mbed.bld	Thu Dec 15 10:09:47 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/976df7c37ad5
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/d75b3fe1f5cb
\ No newline at end of file