Clock display on app board LCD is set using an NTP network time server. DHCP service must be enabled for mbed to get an IP address. A network cable is needed.

Dependencies:   C12832_lcd EthernetInterface NTPClient mbed-rtos mbed

main.cpp

Committer:
4180_1
Date:
2013-10-01
Revision:
0:9653261dbcda
Child:
1:9095ffb76813

File content as of revision 0:9653261dbcda:

#include "mbed.h"
#include "EthernetInterface.h"
#include "NTPClient.h"
#include "C12832_lcd.h"

C12832_LCD lcd; //Graphics LCD
EthernetInterface eth;
NTPClient ntp;

int main()
{
    eth.init(); //Use DHCP
    wait(2);
    lcd.cls();
    lcd.printf("Getting IP Address\r\n");
    if(eth.connect(60000)!=0) {
        lcd.printf("DHCP error - No IP");
        wait(10);
    } else {
        lcd.printf("IP is %s\n", eth.getIPAddress());
        wait(2);
    }
    lcd.cls();
    lcd.printf("Trying to update time...\r\n");
    if (ntp.setTime("ca.pool.ntp.org") == 0) {
        lcd.printf("Set time successfully\r\n");
        while(1) {
            lcd.cls();
            lcd.locate(0,0);
            time_t ctTime;
            ctTime = time(NULL);
            lcd.printf("%s\r\n", ctime(&ctTime));
            lcd.printf("Current Time (UTC)");
            wait(1);
        }
    } else {
        lcd.printf("NTP Error\r\n");
    }

    eth.disconnect();

    while(1) {
    }
}