Connect to SSID, get ip by dhcp, ping google.com, display statistics
Dependencies: NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed
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 00020 using namespace mbed_cc3000; 00021 00022 /* cc3000 module declaration specific for user's board. Check also init() */ 00023 #if (MY_BOARD == WIGO) 00024 cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "ssid", "key", WPA2, false); 00025 Serial pc(USBTX, USBRX); 00026 #elif (MY_BOARD == WIFI_DIPCORTEX) 00027 cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), "ssid", "key", WPA2, false); 00028 Serial pc(UART_TX, UART_RX); 00029 #elif (MY_BOARD == MBED_BOARD_EXAMPLE) 00030 cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), "ssid", "key", WPA2, false); 00031 Serial pc(USBTX, USBRX); 00032 #else 00033 00034 #endif 00035 00036 /** 00037 * \brief Ping a site 00038 * \param none 00039 * \return int 00040 */ 00041 int main() { 00042 init(); /* board dependent init */ 00043 pc.baud(115200); 00044 00045 printf("CC3000 ping demo. \r\n"); 00046 wifi.init(); 00047 if (wifi.connect() == -1) { 00048 printf("Failed to connect. Please verify connection details and try again. \r\n"); 00049 } else { 00050 printf("IP address: %s \r\n",wifi.getIPAddress()); 00051 } 00052 00053 uint32_t ip; 00054 uint8_t *site = (uint8_t *)"google.com"; 00055 printf("Get an IP address of %s \r\n",site); 00056 if (wifi._socket.gethostbyname(site,strlen((const char *)site), &ip)) { 00057 uint8_t add0 = (ip >> 24); 00058 uint8_t add1 = (ip >> 16); 00059 uint8_t add2 = (ip >> 8); 00060 uint8_t add3 = (ip >> 0); 00061 printf("IP address of %s: %d:%d:%d:%d \r\n", site, add0, add1, add2, add3); 00062 } else { 00063 printf("Failed. \r\n"); 00064 } 00065 00066 printf("Starting sending ping. \r\n"); 00067 uint32_t reply_count = wifi.ping(ip, 5, 500, 32); 00068 printf("Received %d replies. \r\n", reply_count); 00069 printf("Ping demo completed. \r\n"); 00070 wifi.disconnect(); 00071 }
Generated on Wed Jul 13 2022 00:05:58 by 1.7.2