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:
- 6:96e92bfda33e
- Parent:
- 5:88cece84fb6e
- Child:
- 7:a33ce4fe1b91
diff -r 88cece84fb6e -r 96e92bfda33e main.cpp
--- a/main.cpp Tue Jan 03 13:02:14 2017 +0000
+++ b/main.cpp Tue Jan 03 16:26:45 2017 +0000
@@ -41,7 +41,7 @@
ctTime = time(NULL);
printf ("\n\rConnecting to WiFi ...\n\r");
- spwf.connect("ssid","passw", NSAPI_SECURITY_WPA2);
+ spwf.connect("crespan","Elfrontal1", NSAPI_SECURITY_WPA2);
NTPClient ntp(spwf);
printf("Initial System Time is: %s\r\n", ctime(&ctTime));
@@ -59,14 +59,12 @@
// so DNS doesnt answer as it requires unsecure UDP socket connection.
// workaroud: convert URL to IP quering DNS before secure socket creation, then connect
// the secure socket created to the retrieved IP.
- SocketAddress addr(&spwf, "www.amazon.it");
- const char *ip=addr.get_ip_address();
- printf ("www.amazon.it resolved to: %s\n\r", ip);
+ SocketAddress addr(&spwf, "www.amazon.it", 443); // must be called BEFORE set_secure_socket() to allow DNS udp connection
spwf.set_secure_sockets();
TCPSocket socket(&spwf);
- int err = socket.connect(ip,443);
+ int err = socket.connect(addr);
if (err != 0 )printf ("ERROR opening %d\n\r", err);
- else printf ("--->>> Secure socket CONNECTED to: %s\n\r", ip);
+ else printf ("--->>> Secure socket CONNECTED to: %s\n\r", addr.get_ip_address());
spwf.set_unsecure_sockets();
socket.close();
printf ("Socket closed\n\r");
