![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ECE4180 Lab 4
Dependencies: 4DGL-uLCD-SE NTPClient WiflyInterface mbed
Fork of Wifly_HelloWorld by
main.cpp@6:9e564d0336a8, 2014-10-20 (annotated)
- Committer:
- prabbat3
- Date:
- Mon Oct 20 17:23:49 2014 +0000
- Revision:
- 6:9e564d0336a8
- Parent:
- 5:867d16e948eb
WirelessUTC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
prabbat3 | 6:9e564d0336a8 | 1 | /** |
prabbat3 | 6:9e564d0336a8 | 2 | * Paul Rabbat (prabbat3@gatech.edu) and Himanshu Pandey (hpandey3@gatech.edu) |
prabbat3 | 6:9e564d0336a8 | 3 | * ECE4180 - Georgia Institute of Technology |
prabbat3 | 6:9e564d0336a8 | 4 | * Lab 4 |
prabbat3 | 6:9e564d0336a8 | 5 | * October 21, 2014 |
prabbat3 | 6:9e564d0336a8 | 6 | */ |
prabbat3 | 6:9e564d0336a8 | 7 | |
samux | 0:90ba0f51aa64 | 8 | #include "mbed.h" |
samux | 3:3b84102f022e | 9 | #include "WiflyInterface.h" |
prabbat3 | 6:9e564d0336a8 | 10 | #include "NTPClient.h" |
prabbat3 | 6:9e564d0336a8 | 11 | #include "uLCD_4DGL.h" |
samux | 1:49e1e9ed6e39 | 12 | |
samux | 1:49e1e9ed6e39 | 13 | /* wifly object where: |
samux | 1:49e1e9ed6e39 | 14 | * - p9 and p10 are for the serial communication |
samux | 3:3b84102f022e | 15 | * - p25 is for the reset pin |
samux | 3:3b84102f022e | 16 | * - p26 is for the connection status |
samux | 1:49e1e9ed6e39 | 17 | * - "mbed" is the ssid of the network |
samux | 1:49e1e9ed6e39 | 18 | * - "password" is the password |
samux | 5:867d16e948eb | 19 | * - WPA is the security |
samux | 1:49e1e9ed6e39 | 20 | */ |
prabbat3 | 6:9e564d0336a8 | 21 | WiflyInterface wifly(p9, p10, p25, p26, "Los Pollos Hermanos", "", NONE); |
samux | 0:90ba0f51aa64 | 22 | |
prabbat3 | 6:9e564d0336a8 | 23 | //SET UP ULCD |
prabbat3 | 6:9e564d0336a8 | 24 | uLCD_4DGL uLCD(p28, p27, p29); // serial tx, serial rx, reset pin; |
prabbat3 | 6:9e564d0336a8 | 25 | NTPClient ntpClient; |
prabbat3 | 6:9e564d0336a8 | 26 | |
samux | 1:49e1e9ed6e39 | 27 | int main() { |
prabbat3 | 6:9e564d0336a8 | 28 | time_t ctTime; //system time structure |
prabbat3 | 6:9e564d0336a8 | 29 | uLCD.baudrate(2000000); //Crank up Baudrate |
prabbat3 | 6:9e564d0336a8 | 30 | uLCD.cls(); //Clear uLCD screen |
prabbat3 | 6:9e564d0336a8 | 31 | uLCD.background_color(BLACK); //SET BACKGROUND COLOR TO WHITE |
prabbat3 | 6:9e564d0336a8 | 32 | //SETS THE BACKGROUND COLOR OF TEXT TO WHITE ON THE ULCD |
prabbat3 | 6:9e564d0336a8 | 33 | uLCD.textbackground_color(BLACK); |
prabbat3 | 6:9e564d0336a8 | 34 | uLCD.locate(0,0); //Start printing on col0, row0 |
prabbat3 | 6:9e564d0336a8 | 35 | uLCD.printf("Getting IP Address\n"); //Print to uLCD |
prabbat3 | 6:9e564d0336a8 | 36 | wifly.init(); //USE DHCP to get local IP address |
prabbat3 | 6:9e564d0336a8 | 37 | wifly.connect(); //Connect to the network |
prabbat3 | 6:9e564d0336a8 | 38 | uLCD.printf("IP ADDRESS is %s\n",wifly.getIPAddress()); //Get Ethernet Address and display It on ULCD |
prabbat3 | 6:9e564d0336a8 | 39 | wait(3.0); |
prabbat3 | 6:9e564d0336a8 | 40 | uLCD.printf("Reading Time...\n"); |
prabbat3 | 6:9e564d0336a8 | 41 | char* domainName="us.pool.ntp.org"; //SET TO DOMAIN NAME OF SERVER GETTING TIME FROM |
prabbat3 | 6:9e564d0336a8 | 42 | //GETS THE TIME FROM THE SERVER |
prabbat3 | 6:9e564d0336a8 | 43 | //setTime(DOMAIN_NAME,PORT_NUMBER,TIME_OUT) |
prabbat3 | 6:9e564d0336a8 | 44 | //DOMAIN_NAME= domain name |
prabbat3 | 6:9e564d0336a8 | 45 | //PORT NUMBER=port number (123 for NTP) |
prabbat3 | 6:9e564d0336a8 | 46 | //TIME_OUT= timeout value for request |
prabbat3 | 6:9e564d0336a8 | 47 | ntpClient.setTime(domainName,123,0x00005000); |
prabbat3 | 6:9e564d0336a8 | 48 | uLCD.printf("Time Set\n"); |
prabbat3 | 6:9e564d0336a8 | 49 | //Delay for human time to read LCD display |
prabbat3 | 6:9e564d0336a8 | 50 | wait(3.0); |
prabbat3 | 6:9e564d0336a8 | 51 | uLCD.cls(); |
prabbat3 | 6:9e564d0336a8 | 52 | //SETS THE BACKGROUND COLOR OF TEXT TO WHITE ON THE ULCD |
prabbat3 | 6:9e564d0336a8 | 53 | uLCD.textbackground_color(BLACK); |
prabbat3 | 6:9e564d0336a8 | 54 | char buffer[80]; //BUFFER TO HOLD FORMATTED TIME DATA |
prabbat3 | 6:9e564d0336a8 | 55 | uLCD.color(RED); |
prabbat3 | 6:9e564d0336a8 | 56 | wifly.disconnect(); //DISCONNECT FROM THE NETWORK |
prabbat3 | 6:9e564d0336a8 | 57 | uLCD.text_height(2); //2x Text Height |
prabbat3 | 6:9e564d0336a8 | 58 | while (1) { |
prabbat3 | 6:9e564d0336a8 | 59 | // loop and periodically update the LCD's time display |
prabbat3 | 6:9e564d0336a8 | 60 | uLCD.locate(0,0); |
prabbat3 | 6:9e564d0336a8 | 61 | ctTime = time(NULL)-(3600*4); //TIME with offset for eastern time US |
prabbat3 | 6:9e564d0336a8 | 62 | //FORMAT TIME FOR DISPLAY AND STORE FORMATTED RESULT IN BUFFER |
prabbat3 | 6:9e564d0336a8 | 63 | strftime(buffer,80,"%a %b %d\n%T %p %z\n %Z\n",localtime(&ctTime)); |
prabbat3 | 6:9e564d0336a8 | 64 | uLCD.printf("Univ Time Clock\n%s", buffer); |
prabbat3 | 6:9e564d0336a8 | 65 | wait(.1); |
prabbat3 | 6:9e564d0336a8 | 66 | } |
samux | 1:49e1e9ed6e39 | 67 | } |