Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NTPClient NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed
Fork of NTPClient_HelloWorld by
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).
Diff: main.cpp
- Revision:
- 3:ca8860f482e0
- Parent:
- 2:bf7dc5f5bca9
- Child:
- 4:11f2b556765b
diff -r bf7dc5f5bca9 -r ca8860f482e0 main.cpp
--- 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();
}
