School project.

Dependencies:   Timezone NTPClient BSP_DISCO_F746NG Grove_temperature

time_functions.h

Committer:
tuxx0046
Date:
2021-01-20
Revision:
17:01ebfd8ab87a
Child:
18:11db143c0502

File content as of revision 17:01ebfd8ab87a:

/**
@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);
    }
}