![](/media/cache/profiles/8b649862360f1c2b5ccee333c282b1d4.jpg.50x50_q85.jpg)
cc3000_ntp_demo_F446RE
Dependencies: NTPClient2 NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed
Fork of cc3000_ntp_demo by
main.cpp@6:4cc48f349aed, 2013-11-06 (annotated)
- Committer:
- Kojto
- Date:
- Wed Nov 06 20:52:00 2013 +0000
- Revision:
- 6:4cc48f349aed
- Parent:
- 5:6d9d149b01cd
- Child:
- 8:6870e6801838
- update NVIC set all priorities
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 0:606d6c8dcb58 | 1 | /* mbed Microcontroller Library |
Kojto | 0:606d6c8dcb58 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Kojto | 0:606d6c8dcb58 | 3 | * |
Kojto | 0:606d6c8dcb58 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Kojto | 0:606d6c8dcb58 | 5 | * you may not use this file except in compliance with the License. |
Kojto | 0:606d6c8dcb58 | 6 | * You may obtain a copy of the License at |
Kojto | 0:606d6c8dcb58 | 7 | * |
Kojto | 0:606d6c8dcb58 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Kojto | 0:606d6c8dcb58 | 9 | * |
Kojto | 0:606d6c8dcb58 | 10 | * Unless required by applicable law or agreed to in writing, software |
Kojto | 0:606d6c8dcb58 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Kojto | 0:606d6c8dcb58 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Kojto | 0:606d6c8dcb58 | 13 | * See the License for the specific language governing permissions and |
Kojto | 0:606d6c8dcb58 | 14 | * limitations under the License. |
Kojto | 0:606d6c8dcb58 | 15 | */ |
Kojto | 0:606d6c8dcb58 | 16 | #include "mbed.h" |
Kojto | 0:606d6c8dcb58 | 17 | #include "cc3000.h" |
Kojto | 0:606d6c8dcb58 | 18 | #include "main.h" |
Kojto | 0:606d6c8dcb58 | 19 | #include "NTPClient.h" |
Kojto | 0:606d6c8dcb58 | 20 | |
Kojto | 0:606d6c8dcb58 | 21 | using namespace mbed_cc3000; |
Kojto | 0:606d6c8dcb58 | 22 | |
Kojto | 2:f163731f852a | 23 | /* cc3000 module declaration specific for user's board. Check also init() */ |
Kojto | 2:f163731f852a | 24 | #if (MY_BOARD == WIGO) |
Kojto | 5:6d9d149b01cd | 25 | cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "ssid", "key", WPA2, false); |
Kojto | 3:4a2dfa38a61e | 26 | Serial pc(USBTX, USBRX); |
Kojto | 2:f163731f852a | 27 | #elif (MY_BOARD == WIFI_DIPCORTEX) |
Kojto | 5:6d9d149b01cd | 28 | cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), "ssid", "key", WPA2, false); |
Kojto | 3:4a2dfa38a61e | 29 | Serial pc(UART_TX, UART_RX); |
Kojto | 5:6d9d149b01cd | 30 | #elif (MY_BOARD == MBED_BOARD_EXAMPLE) |
Kojto | 5:6d9d149b01cd | 31 | cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), "ssid", "key", WPA2, false); |
Kojto | 5:6d9d149b01cd | 32 | Serial pc(USBTX, USBRX); |
Kojto | 2:f163731f852a | 33 | #else |
Kojto | 2:f163731f852a | 34 | |
Kojto | 2:f163731f852a | 35 | #endif |
Kojto | 2:f163731f852a | 36 | |
Kojto | 3:4a2dfa38a61e | 37 | /** |
Kojto | 3:4a2dfa38a61e | 38 | * \brief NTP client demo |
Kojto | 0:606d6c8dcb58 | 39 | * \param none |
Kojto | 0:606d6c8dcb58 | 40 | * \return int |
Kojto | 0:606d6c8dcb58 | 41 | */ |
Kojto | 0:606d6c8dcb58 | 42 | int main() { |
Kojto | 2:f163731f852a | 43 | init(); /* board dependent init */ |
Kojto | 0:606d6c8dcb58 | 44 | pc.baud(115200); |
Kojto | 5:6d9d149b01cd | 45 | |
Kojto | 3:4a2dfa38a61e | 46 | printf("cc3000 NTP client demo. \r\n"); |
Kojto | 5:6d9d149b01cd | 47 | wifi.init(); |
Kojto | 5:6d9d149b01cd | 48 | if (wifi.connect() == -1) { |
Kojto | 5:6d9d149b01cd | 49 | printf("Failed to connect. Please verify connection details and try again. \r\n"); |
Kojto | 0:606d6c8dcb58 | 50 | } else { |
Kojto | 5:6d9d149b01cd | 51 | printf("IP address: %s \r\n",wifi.getIPAddress()); |
Kojto | 0:606d6c8dcb58 | 52 | } |
Kojto | 0:606d6c8dcb58 | 53 | |
Kojto | 3:4a2dfa38a61e | 54 | NTPClient ntp; |
Kojto | 3:4a2dfa38a61e | 55 | |
Kojto | 2:f163731f852a | 56 | printf("Getting time, 10s timeout. \r\n"); |
Kojto | 1:fd70c76e74b2 | 57 | if (ntp.setTime("0.uk.pool.ntp.org") == 0) |
Kojto | 0:606d6c8dcb58 | 58 | { |
Kojto | 3:4a2dfa38a61e | 59 | printf("Set time successfully. \r\n"); |
Kojto | 3:4a2dfa38a61e | 60 | time_t ctTime; |
Kojto | 3:4a2dfa38a61e | 61 | ctTime = time(NULL); |
Kojto | 3:4a2dfa38a61e | 62 | printf("Time is set to (UTC): %s \r\n", ctime(&ctTime)); |
Kojto | 0:606d6c8dcb58 | 63 | } |
Kojto | 0:606d6c8dcb58 | 64 | else |
Kojto | 0:606d6c8dcb58 | 65 | { |
Kojto | 3:4a2dfa38a61e | 66 | printf("Error. \r\n"); |
Kojto | 3:4a2dfa38a61e | 67 | } |
Kojto | 0:606d6c8dcb58 | 68 | |
Kojto | 2:f163731f852a | 69 | wifi.disconnect(); |
Kojto | 0:606d6c8dcb58 | 70 | } |
Kojto | 0:606d6c8dcb58 | 71 |