source: rtos_arduino/trunk/arduino_lib/libraries/ESP8266/examples/TCPClientMultiple/TCPClientMultiple.ino@ 141

Last change on this file since 141 was 141, checked in by ertl-honda, 7 years ago

サンプルが動作するよう修正.

File size: 3.0 KB
Line 
1/**
2 * @example TCPClientMultiple.ino
3 * @brief The TCPClientMultiple demo of library WeeESP8266.
4 * @author Wu Pengfei<pengfei.wu@itead.cc>
5 * @date 2015.02
6 *
7 * @par Copyright:
8 * Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\n
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. \n\n
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
21#include "ESP8266.h"
22
23#define SSID "ITEAD"
24#define PASSWORD "12345678"
25#define HOST_NAME "172.16.5.12"
26#define HOST_PORT (8090)
27
28ESP8266 wifi;
29
30void setup(void)
31{
32 Serial.begin(9600);
33 Serial.print("setup begin\r\n");
34
35 Serial.print("FW Version: ");
36 Serial.println(wifi.getVersion().c_str());
37
38
39 wifi.begin(Serial5);
40 if (wifi.setOprToStationSoftAP()) {
41 Serial.print("to station + softap ok\r\n");
42 } else {
43 Serial.print("to station + softap err\r\n");
44 }
45
46 if (wifi.joinAP(SSID, PASSWORD)) {
47 Serial.print("Join AP success\r\n");
48 Serial.print("IP: ");
49 Serial.println(wifi.getLocalIP().c_str());
50 } else {
51 Serial.print("Join AP failure\r\n");
52 }
53
54 if (wifi.enableMUX()) {
55 Serial.print("multiple ok\r\n");
56 } else {
57 Serial.print("multiple err\r\n");
58 }
59
60 Serial.print("setup end\r\n");
61}
62
63void loop(void)
64{
65 uint8_t buffer[128] = {0};
66 static uint8_t mux_id = 0;
67
68 if (wifi.createTCP(mux_id, HOST_NAME, HOST_PORT)) {
69 Serial.print("create tcp ");
70 Serial.print(mux_id);
71 Serial.println(" ok");
72 } else {
73 Serial.print("create tcp ");
74 Serial.print(mux_id);
75 Serial.println(" err");
76 }
77
78
79 char *hello = "Hello, this is client!";
80 if (wifi.send(mux_id, (const uint8_t*)hello, strlen(hello))) {
81 Serial.println("send ok");
82 } else {
83 Serial.println("send err");
84 }
85
86 uint32_t len = wifi.recv(mux_id, buffer, sizeof(buffer), 10000);
87 if (len > 0) {
88 Serial.print("Received:[");
89 for(uint32_t i = 0; i < len; i++) {
90 Serial.print((char)buffer[i]);
91 }
92 Serial.print("]\r\n");
93 }
94
95 if (wifi.releaseTCP(mux_id)) {
96 Serial.print("release tcp ");
97 Serial.print(mux_id);
98 Serial.println(" ok");
99 } else {
100 Serial.print("release tcp ");
101 Serial.print(mux_id);
102 Serial.println(" err");
103 }
104
105 delay(3000);
106 mux_id++;
107 if (mux_id >= 5) {
108 mux_id = 0;
109 }
110}
111
Note: See TracBrowser for help on using the repository browser.