NTPClient using the mbed_official WiflyInterface
Dependencies: NTPClient WiflyInterface mbed
main.cpp@0:42b732f6238c, 2012-08-24 (annotated)
- Committer:
- samux
- Date:
- Fri Aug 24 15:26:15 2012 +0000
- Revision:
- 0:42b732f6238c
- Child:
- 1:8b6ea44e02bb
NTPClient with the mbed_official WiflyInterface
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:42b732f6238c | 1 | #include "mbed.h" |
samux | 0:42b732f6238c | 2 | #include "WiflyInterface.h" |
samux | 0:42b732f6238c | 3 | #include "NTPClient.h" |
samux | 0:42b732f6238c | 4 | |
samux | 0:42b732f6238c | 5 | /* wifly interface: |
samux | 0:42b732f6238c | 6 | * - p9 and p10 are for the serial communication |
samux | 0:42b732f6238c | 7 | * - p19 is for the reset pin |
samux | 0:42b732f6238c | 8 | * - p26 is for the connection status |
samux | 0:42b732f6238c | 9 | * - "mbed" is the ssid of the network |
samux | 0:42b732f6238c | 10 | * - "password" is the password |
samux | 0:42b732f6238c | 11 | * - WPA is the security |
samux | 0:42b732f6238c | 12 | */ |
samux | 0:42b732f6238c | 13 | WiflyInterface wifly(p28, p27, p25, p26, "mbed", "password", WPA); |
samux | 0:42b732f6238c | 14 | NTPClient ntp; |
samux | 0:42b732f6238c | 15 | |
samux | 0:42b732f6238c | 16 | int main() |
samux | 0:42b732f6238c | 17 | { |
samux | 0:42b732f6238c | 18 | wifly.init(); //Use DHCP |
samux | 0:42b732f6238c | 19 | |
samux | 0:42b732f6238c | 20 | wifly.connect(); |
samux | 0:42b732f6238c | 21 | |
samux | 0:42b732f6238c | 22 | printf("Trying to update time...\r\n"); |
samux | 0:42b732f6238c | 23 | if (ntp.setTime("0.pool.ntp.org") == 0) |
samux | 0:42b732f6238c | 24 | { |
samux | 0:42b732f6238c | 25 | printf("Set time successfully\r\n"); |
samux | 0:42b732f6238c | 26 | time_t ctTime; |
samux | 0:42b732f6238c | 27 | ctTime = time(NULL); |
samux | 0:42b732f6238c | 28 | printf("Time is set to (UTC): %s\r\n", ctime(&ctTime)); |
samux | 0:42b732f6238c | 29 | } |
samux | 0:42b732f6238c | 30 | else |
samux | 0:42b732f6238c | 31 | { |
samux | 0:42b732f6238c | 32 | printf("Error\r\n"); |
samux | 0:42b732f6238c | 33 | } |
samux | 0:42b732f6238c | 34 | |
samux | 0:42b732f6238c | 35 | wifly.disconnect(); |
samux | 0:42b732f6238c | 36 | |
samux | 0:42b732f6238c | 37 | while(1) { |
samux | 0:42b732f6238c | 38 | } |
samux | 0:42b732f6238c | 39 | } |