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