ECE4180 Lab 4

Dependencies:   4DGL-uLCD-SE NTPClient WiflyInterface mbed

Fork of Wifly_HelloWorld by Samuel Mokrani

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**
00002 *   Paul Rabbat (prabbat3@gatech.edu) and Himanshu Pandey (hpandey3@gatech.edu)
00003 *   ECE4180 - Georgia Institute of Technology
00004 *   Lab 4
00005 *   October 21, 2014
00006 */
00007 
00008 #include "mbed.h"
00009 #include "WiflyInterface.h"
00010 #include "NTPClient.h"
00011 #include "uLCD_4DGL.h"
00012 
00013 /* wifly object where:
00014 *     - p9 and p10 are for the serial communication
00015 *     - p25 is for the reset pin
00016 *     - p26 is for the connection status
00017 *     - "mbed" is the ssid of the network
00018 *     - "password" is the password
00019 *     - WPA is the security
00020 */
00021 WiflyInterface wifly(p9, p10, p25, p26, "Los Pollos Hermanos", "", NONE);
00022 
00023 //SET UP ULCD
00024 uLCD_4DGL uLCD(p28, p27, p29); // serial tx, serial rx, reset pin;
00025 NTPClient ntpClient;
00026  
00027 int main() {
00028     time_t ctTime; //system time structure
00029     uLCD.baudrate(2000000); //Crank up Baudrate
00030     uLCD.cls();    //Clear uLCD screen
00031     uLCD.background_color(BLACK); //SET BACKGROUND COLOR TO WHITE
00032     //SETS THE BACKGROUND COLOR OF TEXT TO WHITE ON THE ULCD
00033     uLCD.textbackground_color(BLACK);
00034     uLCD.locate(0,0);  //Start printing on col0, row0
00035     uLCD.printf("Getting IP Address\n"); //Print to uLCD
00036     wifly.init(); //USE DHCP to get local IP address
00037     wifly.connect(); //Connect to the network
00038     uLCD.printf("IP ADDRESS is %s\n",wifly.getIPAddress()); //Get Ethernet Address and display It on ULCD
00039     wait(3.0);
00040     uLCD.printf("Reading Time...\n");
00041     char* domainName="us.pool.ntp.org"; //SET TO DOMAIN NAME OF SERVER GETTING TIME FROM
00042     //GETS THE TIME FROM THE SERVER
00043     //setTime(DOMAIN_NAME,PORT_NUMBER,TIME_OUT)
00044     //DOMAIN_NAME= domain name
00045     //PORT NUMBER=port number (123 for NTP)
00046     //TIME_OUT= timeout value for request
00047     ntpClient.setTime(domainName,123,0x00005000);
00048     uLCD.printf("Time Set\n");
00049     //Delay for human time to read LCD display
00050     wait(3.0);
00051     uLCD.cls();
00052     //SETS THE BACKGROUND COLOR OF TEXT TO WHITE ON THE ULCD
00053     uLCD.textbackground_color(BLACK);
00054     char buffer[80]; //BUFFER TO HOLD FORMATTED TIME DATA
00055     uLCD.color(RED);
00056     wifly.disconnect(); //DISCONNECT FROM THE NETWORK 
00057     uLCD.text_height(2); //2x Text Height
00058     while (1) {
00059         // loop and periodically update the LCD's time display
00060         uLCD.locate(0,0);
00061         ctTime = time(NULL)-(3600*4);  //TIME with offset for eastern time US
00062         //FORMAT TIME FOR DISPLAY AND STORE FORMATTED RESULT IN BUFFER
00063         strftime(buffer,80,"%a %b %d\n%T %p %z\n %Z\n",localtime(&ctTime));
00064         uLCD.printf("Univ Time Clock\n%s", buffer);
00065         wait(.1);
00066     }  
00067 }