Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed
main.cpp
- Committer:
- Kojto
- Date:
- 2013-11-06
- Revision:
- 7:fbc17364ea63
- Parent:
- 5:864a193bd778
File content as of revision 7:fbc17364ea63:
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "cc3000.h"
#include "main.h"
using namespace mbed_cc3000;
/* cc3000 module declaration specific for user's board. Check also init() */
#if (MY_BOARD == WIGO)
cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "ssid", "key", WPA2, false);
Serial pc(USBTX, USBRX);
#elif (MY_BOARD == WIFI_DIPCORTEX)
cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), "ssid", "key", WPA2, false);
Serial pc(UART_TX, UART_RX);
#elif (MY_BOARD == MBED_BOARD_EXAMPLE)
cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), "ssid", "key", WPA2, false);
Serial pc(USBTX, USBRX);
#else
#endif
/**
* \brief Ping a site
* \param none
* \return int
*/
int main() {
init(); /* board dependent init */
pc.baud(115200);
printf("CC3000 ping demo. \r\n");
wifi.init();
if (wifi.connect() == -1) {
printf("Failed to connect. Please verify connection details and try again. \r\n");
} else {
printf("IP address: %s \r\n",wifi.getIPAddress());
}
uint32_t ip;
uint8_t *site = (uint8_t *)"google.com";
printf("Get an IP address of %s \r\n",site);
if (wifi._socket.gethostbyname(site,strlen((const char *)site), &ip)) {
uint8_t add0 = (ip >> 24);
uint8_t add1 = (ip >> 16);
uint8_t add2 = (ip >> 8);
uint8_t add3 = (ip >> 0);
printf("IP address of %s: %d:%d:%d:%d \r\n", site, add0, add1, add2, add3);
} else {
printf("Failed. \r\n");
}
printf("Starting sending ping. \r\n");
uint32_t reply_count = wifi.ping(ip, 5, 500, 32);
printf("Received %d replies. \r\n", reply_count);
printf("Ping demo completed. \r\n");
wifi.disconnect();
}