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
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 #include "TCPSocketConnection.h" 00021 #include "TCPSocketServer.h" 00022 00023 using namespace mbed_cc3000; 00024 00025 /* cc3000 module declaration specific for user's board. Check also init() */ 00026 #if (MY_BOARD == WIGO) 00027 cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), "ssid", "key", WPA2, false); 00028 Serial pc(USBTX, USBRX); 00029 #elif (MY_BOARD == WIFI_DIPCORTEX) 00030 cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), "ssid", "key", WPA2, false); 00031 Serial pc(UART_TX, UART_RX); 00032 #elif (MY_BOARD == MBED_BOARD_EXAMPLE) 00033 cc3000 wifi(p9, p10, p8, SPI(p5, p6, p7), "ssid", "key", WPA2, false); 00034 Serial pc(USBTX, USBRX); 00035 #else 00036 00037 #endif 00038 00039 /** 00040 * \brief TCP client demo 00041 * \param none 00042 * \return int 00043 */ 00044 int main() { 00045 init(); /* board dependent init */ 00046 pc.baud(115200); 00047 00048 printf("cc3000 tcp client demo. \r\n"); 00049 wifi.init(); 00050 if (wifi.connect() == -1) { 00051 printf("Failed to connect. Please verify connection details and try again. \r\n"); 00052 } else { 00053 printf("IP address: %s \r\n", wifi.getIPAddress()); 00054 } 00055 00056 const char* ECHO_SERVER_ADDRESS = "192.168.1.10"; 00057 const int ECHO_SERVER_PORT = 1895; 00058 00059 TCPSocketConnection socket; 00060 while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) { 00061 printf("Unable to connect to (%s) on port (%d) \r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); 00062 wait(1); 00063 } 00064 00065 char hello[] = "Hello World\n"; 00066 socket.send_all(hello, sizeof(hello) - 1); 00067 00068 char buf[256]; 00069 int n = socket.receive(buf, 256); 00070 buf[n] = '\0'; 00071 printf("%s", buf); 00072 00073 socket.close(); 00074 printf("Completed. \r\n"); 00075 wifi.disconnect(); 00076 }
Generated on Fri Jul 15 2022 20:21:37 by
1.7.2