ntp demo for cc3000

Dependencies:   NVIC_set_all_priorities NTPClient cc3000_hostdriver_mbedsocket mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "mbed.h"
00017 #include "cc3000.h"
00018 #include "main.h"
00019 #include "NTPClient.h"
00020 
00021 using namespace mbed_cc3000;
00022 
00023 /* cc3000 module declaration specific for user's board. Check also init() */
00024 #if (MY_BOARD == WIGO)
00025 cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "ssid", "key", WPA2, false);
00026 Serial pc(USBTX, USBRX);
00027 #elif (MY_BOARD == WIFI_DIPCORTEX)
00028 cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), "ssid", "key", WPA2, false);
00029 Serial pc(UART_TX, UART_RX);
00030 #elif (MY_BOARD == MBED_BOARD_EXAMPLE)
00031 cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), "ssid", "key", WPA2, false);
00032 Serial pc(USBTX, USBRX);
00033 #else
00034 
00035 #endif
00036 
00037 /**
00038  *  \brief NTP client demo
00039  *  \param  none
00040  *  \return int
00041  */
00042 int main() {
00043     init(); /* board dependent init */
00044     pc.baud(115200);
00045     
00046     printf("cc3000 NTP client demo. \r\n");
00047     wifi.init();
00048     if (wifi.connect() == -1) {
00049         printf("Failed to connect. Please verify connection details and try again. \r\n");
00050     } else {
00051         printf("IP address: %s \r\n",wifi.getIPAddress());
00052     }
00053 
00054     NTPClient ntp;
00055 
00056     printf("Getting time, 10s timeout. \r\n");
00057     if (ntp.setTime("0.uk.pool.ntp.org") == 0)
00058     {
00059         printf("Set time successfully. \r\n");
00060         time_t ctTime;
00061         ctTime = time(NULL);
00062         printf("Time is set to (UTC): %s \r\n", ctime(&ctTime));
00063     }
00064     else
00065     {
00066         printf("Error. \r\n");
00067     }
00068 
00069     wifi.disconnect();
00070 }
00071