ITEAD STUDIO
/
WeeESP8266_TCPClientMultiple
Program of WeeESP8266 library.
Embed:
(wiki syntax)
Show/hide line numbers
TCPClientMultiple.cpp
Go to the documentation of this file.
00001 /** 00002 * @file TCPClientMultiple.cpp 00003 * @brief The TCPClientMultiple demo of library WeeESP8266. 00004 * @author Wu Pengfei<pengfei.wu@itead.cc> 00005 * @date 2015.02 00006 * 00007 * @par Copyright: 00008 * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\n 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License as 00011 * published by the Free Software Foundation; either version 2 of 00012 * the License, or (at your option) any later version. \n\n 00013 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00014 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00015 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00016 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00017 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00018 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00019 * THE SOFTWARE. 00020 */ 00021 #include "mbed.h" 00022 #include "ArduinoAPI.h" 00023 #include "ESP8266.h" 00024 00025 extern void setup(void); 00026 extern void loop(void); 00027 00028 ArduinoSerial esp_uart(p28, p27); 00029 ESP8266 wifi(esp_uart); 00030 Serial pc(USBTX, USBRX); 00031 00032 int main () { 00033 setup(); 00034 while(1) { 00035 loop(); 00036 } 00037 } 00038 00039 void setup(void) 00040 { 00041 printf("setup begin\r\n"); 00042 00043 printf("FW Version: %s\r\n", wifi.getVersion().c_str()); 00044 00045 if (wifi.setOprToStationSoftAP()) { 00046 printf("to station + softap ok\r\n"); 00047 } else { 00048 printf("to station + softap err\r\n"); 00049 } 00050 00051 if (wifi.joinAP("ITEAD", "12345678")) { 00052 printf("Join AP success\r\n"); 00053 printf("IP: [%s]\r\n", wifi.getLocalIP().c_str()); 00054 } else { 00055 printf("Join AP failure\r\n"); 00056 } 00057 00058 if (wifi.enableMUX()) { 00059 printf("multiple ok\r\n"); 00060 } else { 00061 printf("multiple err\r\n"); 00062 } 00063 00064 printf("setup end\r\n"); 00065 } 00066 00067 void loop(void) 00068 { 00069 uint8_t buffer[1024] = {0}; 00070 static uint8_t mux_id = 0; 00071 00072 if (wifi.createTCP(mux_id, "172.16.5.12", 8090)) { 00073 printf("create tcp %u ok\r\n", mux_id); 00074 } else { 00075 printf("create tcp %u err\r\n", mux_id); 00076 } 00077 00078 char *hello = "Hello, this is client!"; 00079 wifi.send(mux_id, (const uint8_t*)hello, strlen(hello)); 00080 00081 uint32_t len = wifi.recv(mux_id, buffer, sizeof(buffer), 10000); 00082 if (len > 0) { 00083 printf("Received:["); 00084 for(uint32_t i = 0; i < len; i++) { 00085 printf("%c", buffer[i]); 00086 } 00087 printf("]\r\n"); 00088 } 00089 00090 if (wifi.releaseTCP(mux_id)) { 00091 printf("release tcp %u ok\r\n", mux_id); 00092 } else { 00093 printf("release tcp %u err\r\n", mux_id); 00094 } 00095 delay(5000); 00096 mux_id++; 00097 if (mux_id >= 5) { 00098 mux_id = 0; 00099 } 00100 }
Generated on Thu Jul 14 2022 01:09:36 by 1.7.2