School project.

Dependencies:   Timezone NTPClient BSP_DISCO_F746NG Grove_temperature

Revision:
17:01ebfd8ab87a
Child:
18:11db143c0502
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/time_functions.h	Wed Jan 20 14:22:46 2021 +0000
@@ -0,0 +1,41 @@
+/**
+@file    time_functions.h
+@author  Tu Tri Huynh
+@date    January 20, 2021
+@brief   Functions related to getting and displaying the time
+*/
+
+/**
+Connects to an NTP server and updates the time to display.
+Currently only works with UTC time.
+1/20/2021
+*/
+void time_update_current_time() 
+{
+    char current_time[32];
+    /// Ethernet connection declared in main.cpp
+    eth.connect();
+ 
+    if (ntp.setTime("0.pool.ntp.org") == 0) 
+    {
+        printf("Time successfully retrieved\n");        
+    } 
+    else 
+    {
+        printf("Failed to retrieve time from NTP server.\n");
+    }
+
+    eth.disconnect();
+    while(1)
+    {
+        time_t seconds = time(NULL);
+
+        char buffer[32];
+        strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
+        //printf("Time as a custom formatted string = %s", buffer);
+        sprintf(current_time, "%s", buffer);
+        lcd_update_upper_left(current_time);
+
+        ThisThread::sleep_for(20s);
+    }
+}
\ No newline at end of file