cc3000_ntp_demo_F446RE

Dependencies:   NTPClient2 NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed

Fork of cc3000_ntp_demo by Martin Kojtal

Committer:
Kojto
Date:
Wed Nov 06 20:46:24 2013 +0000
Revision:
5:6d9d149b01cd
Parent:
4:580582a7ce1a
Child:
6:4cc48f349aed
- update to the host driver rev45; - the new EthernetInterface used

Who changed what in which revision?

UserRevisionLine numberNew 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 5:6d9d149b01cd 52 printf("\r\ncc3000 connected to the Internet. Demo completed. \r\n");
Kojto 0:606d6c8dcb58 53 }
Kojto 0:606d6c8dcb58 54
Kojto 3:4a2dfa38a61e 55 NTPClient ntp;
Kojto 3:4a2dfa38a61e 56
Kojto 2:f163731f852a 57 printf("Getting time, 10s timeout. \r\n");
Kojto 1:fd70c76e74b2 58 if (ntp.setTime("0.uk.pool.ntp.org") == 0)
Kojto 0:606d6c8dcb58 59 {
Kojto 3:4a2dfa38a61e 60 printf("Set time successfully. \r\n");
Kojto 3:4a2dfa38a61e 61 time_t ctTime;
Kojto 3:4a2dfa38a61e 62 ctTime = time(NULL);
Kojto 3:4a2dfa38a61e 63 printf("Time is set to (UTC): %s \r\n", ctime(&ctTime));
Kojto 0:606d6c8dcb58 64 }
Kojto 0:606d6c8dcb58 65 else
Kojto 0:606d6c8dcb58 66 {
Kojto 3:4a2dfa38a61e 67 printf("Error. \r\n");
Kojto 3:4a2dfa38a61e 68 }
Kojto 0:606d6c8dcb58 69
Kojto 2:f163731f852a 70 wifi.disconnect();
Kojto 0:606d6c8dcb58 71 }
Kojto 0:606d6c8dcb58 72