![](/media/cache/profiles/bongjun_profile_500.png.50x50_q85.jpg)
offset value is ok, but set_time is not working. on going...
Dependencies: NTPClient WIZ550ioInterface mbed
Fork of NTPClient_HelloWorld_WIZ550io by
main.cpp@5:ebe17f7798ea, 2014-07-08 (annotated)
- Committer:
- Bongjun
- Date:
- Tue Jul 08 01:08:14 2014 +0000
- Revision:
- 5:ebe17f7798ea
- Parent:
- 4:25394528b7a6
NTPClient test, but set_time is not working.; But getting offset time from NTP Server is ok.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:0e0debc29569 | 1 | #include "mbed.h" |
ban4jp | 3:c6741dc3b6c0 | 2 | //#include "EthernetInterface.h" |
ban4jp | 3:c6741dc3b6c0 | 3 | #include "WIZ550ioInterface.h" |
donatien | 2:bf7dc5f5bca9 | 4 | #include "NTPClient.h" |
donatien | 0:0e0debc29569 | 5 | |
ban4jp | 3:c6741dc3b6c0 | 6 | //EthernetInterface eth; |
ban4jp | 3:c6741dc3b6c0 | 7 | #if defined(TARGET_LPC1114) |
ban4jp | 3:c6741dc3b6c0 | 8 | SPI spi(dp2, dp1, dp6); // mosi, miso, sclk |
ban4jp | 3:c6741dc3b6c0 | 9 | WIZ550ioInterface eth(&spi, dp25, dp26); // spi, cs, reset |
ban4jp | 3:c6741dc3b6c0 | 10 | |
ban4jp | 3:c6741dc3b6c0 | 11 | #elif defined(TARGET_LPC1768) |
ban4jp | 3:c6741dc3b6c0 | 12 | SPI spi(p11, p12, p13); // mosi, miso, sclk |
ban4jp | 3:c6741dc3b6c0 | 13 | WIZ550ioInterface eth(&spi, p14, p15); // spi, cs, reset |
ban4jp | 3:c6741dc3b6c0 | 14 | |
Bongjun | 4:25394528b7a6 | 15 | #elif defined(TARGET_LPC11U68) |
Bongjun | 4:25394528b7a6 | 16 | SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk |
Bongjun | 4:25394528b7a6 | 17 | //WIZnetInterface eth(&spi, P0_2, P1_25); // spi, cs, reset |
Bongjun | 4:25394528b7a6 | 18 | //SPI spi(p5, p6, p7); // mosi, miso, sclk |
Bongjun | 4:25394528b7a6 | 19 | WIZ550ioInterface eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io |
Bongjun | 4:25394528b7a6 | 20 | |
ban4jp | 3:c6741dc3b6c0 | 21 | #endif |
ban4jp | 3:c6741dc3b6c0 | 22 | |
donatien | 2:bf7dc5f5bca9 | 23 | NTPClient ntp; |
donatien | 1:d263603373ac | 24 | |
donatien | 0:0e0debc29569 | 25 | int main() |
donatien | 0:0e0debc29569 | 26 | { |
Bongjun | 4:25394528b7a6 | 27 | //pc.baud(9600); |
Bongjun | 4:25394528b7a6 | 28 | spi.format(8,0); // 8bit, mode 0 |
Bongjun | 4:25394528b7a6 | 29 | spi.frequency(7000000); // 7MHz |
Bongjun | 4:25394528b7a6 | 30 | wait(1); // 1 second for stable state |
Bongjun | 4:25394528b7a6 | 31 | |
Bongjun | 4:25394528b7a6 | 32 | #ifdef _DHCP |
ban4jp | 3:c6741dc3b6c0 | 33 | int ret = eth.init(); //Use DHCP |
ban4jp | 3:c6741dc3b6c0 | 34 | if (!ret) |
ban4jp | 3:c6741dc3b6c0 | 35 | { |
ban4jp | 3:c6741dc3b6c0 | 36 | printf("Initialized, MAC: %s\n", eth.getMACAddress()); |
ban4jp | 3:c6741dc3b6c0 | 37 | } |
ban4jp | 3:c6741dc3b6c0 | 38 | else |
ban4jp | 3:c6741dc3b6c0 | 39 | { |
ban4jp | 3:c6741dc3b6c0 | 40 | printf("Error eth.init() - ret = %d\n", ret); |
ban4jp | 3:c6741dc3b6c0 | 41 | return -1; |
ban4jp | 3:c6741dc3b6c0 | 42 | } |
donatien | 0:0e0debc29569 | 43 | |
ban4jp | 3:c6741dc3b6c0 | 44 | ret = eth.connect(); |
ban4jp | 3:c6741dc3b6c0 | 45 | if (!ret) |
ban4jp | 3:c6741dc3b6c0 | 46 | { |
ban4jp | 3:c6741dc3b6c0 | 47 | printf("Connected, IP: %s, MASK: %s, GW: %s\n", |
ban4jp | 3:c6741dc3b6c0 | 48 | eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); |
ban4jp | 3:c6741dc3b6c0 | 49 | } |
ban4jp | 3:c6741dc3b6c0 | 50 | else |
ban4jp | 3:c6741dc3b6c0 | 51 | { |
ban4jp | 3:c6741dc3b6c0 | 52 | printf("Error eth.connect() - ret = %d\n", ret); |
ban4jp | 3:c6741dc3b6c0 | 53 | return -1; |
ban4jp | 3:c6741dc3b6c0 | 54 | } |
Bongjun | 4:25394528b7a6 | 55 | #else |
Bongjun | 4:25394528b7a6 | 56 | uint32_t gw; |
Bongjun | 4:25394528b7a6 | 57 | uint32_t sn; |
Bongjun | 4:25394528b7a6 | 58 | uint32_t ip; |
ban4jp | 3:c6741dc3b6c0 | 59 | |
Bongjun | 4:25394528b7a6 | 60 | /* |
Bongjun | 4:25394528b7a6 | 61 | gw = 192; |
Bongjun | 4:25394528b7a6 | 62 | gw = (gw<<8) + 168; |
Bongjun | 4:25394528b7a6 | 63 | gw = (gw<<8) + 1; |
Bongjun | 4:25394528b7a6 | 64 | gw = (gw<<8) + 1; |
Bongjun | 4:25394528b7a6 | 65 | sn = 0xffffff00; |
Bongjun | 4:25394528b7a6 | 66 | ip = 192; |
Bongjun | 4:25394528b7a6 | 67 | ip = (ip<<8) + 168; |
Bongjun | 4:25394528b7a6 | 68 | ip = (ip<<8) + 1; |
Bongjun | 4:25394528b7a6 | 69 | ip = (ip<<8) + 212; |
Bongjun | 4:25394528b7a6 | 70 | */ |
Bongjun | 4:25394528b7a6 | 71 | // for the NTP ex, i use real IP.. |
Bongjun | 4:25394528b7a6 | 72 | gw = 222; |
Bongjun | 4:25394528b7a6 | 73 | gw = (gw<<8) + 98; |
Bongjun | 4:25394528b7a6 | 74 | gw = (gw<<8) + 173; |
Bongjun | 4:25394528b7a6 | 75 | gw = (gw<<8) + 254; |
Bongjun | 4:25394528b7a6 | 76 | sn = 0xffffffc0; |
Bongjun | 4:25394528b7a6 | 77 | ip = 222; |
Bongjun | 4:25394528b7a6 | 78 | ip = (ip<<8) + 98; |
Bongjun | 4:25394528b7a6 | 79 | ip = (ip<<8) + 173; |
Bongjun | 4:25394528b7a6 | 80 | ip = (ip<<8) + 212; |
Bongjun | 4:25394528b7a6 | 81 | |
Bongjun | 4:25394528b7a6 | 82 | int ret = eth.init(ip, sn, gw); |
Bongjun | 4:25394528b7a6 | 83 | if (!ret) |
Bongjun | 4:25394528b7a6 | 84 | { |
Bongjun | 4:25394528b7a6 | 85 | printf("Initialized, MAC: %s\n", eth.getMACAddress()); |
Bongjun | 4:25394528b7a6 | 86 | printf("Connected, IP: %s, MASK: %s, GW: %s\n", |
Bongjun | 4:25394528b7a6 | 87 | eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); |
Bongjun | 4:25394528b7a6 | 88 | } |
Bongjun | 4:25394528b7a6 | 89 | else |
Bongjun | 4:25394528b7a6 | 90 | { |
Bongjun | 4:25394528b7a6 | 91 | printf("Error eth.init() - ret = %d\n", ret); |
Bongjun | 4:25394528b7a6 | 92 | return -1; |
Bongjun | 4:25394528b7a6 | 93 | } |
Bongjun | 4:25394528b7a6 | 94 | #endif |
donatien | 2:bf7dc5f5bca9 | 95 | |
donatien | 2:bf7dc5f5bca9 | 96 | printf("Trying to update time...\r\n"); |
Bongjun | 4:25394528b7a6 | 97 | |
Bongjun | 4:25394528b7a6 | 98 | // i don't use dns or something, so change to ipaddress |
Bongjun | 4:25394528b7a6 | 99 | // if (ntp.setTime("0.pool.ntp.org") == 0) |
Bongjun | 4:25394528b7a6 | 100 | if (ntp.setTime("61.110.197.50") == 0) |
donatien | 0:0e0debc29569 | 101 | { |
donatien | 2:bf7dc5f5bca9 | 102 | printf("Set time successfully\r\n"); |
donatien | 2:bf7dc5f5bca9 | 103 | time_t ctTime; |
donatien | 2:bf7dc5f5bca9 | 104 | ctTime = time(NULL); |
donatien | 2:bf7dc5f5bca9 | 105 | printf("Time is set to (UTC): %s\r\n", ctime(&ctTime)); |
donatien | 0:0e0debc29569 | 106 | } |
donatien | 0:0e0debc29569 | 107 | else |
donatien | 0:0e0debc29569 | 108 | { |
donatien | 2:bf7dc5f5bca9 | 109 | printf("Error\r\n"); |
donatien | 2:bf7dc5f5bca9 | 110 | } |
donatien | 2:bf7dc5f5bca9 | 111 | |
donatien | 0:0e0debc29569 | 112 | eth.disconnect(); |
donatien | 0:0e0debc29569 | 113 | |
donatien | 0:0e0debc29569 | 114 | while(1) { |
donatien | 0:0e0debc29569 | 115 | } |
donatien | 0:0e0debc29569 | 116 | } |