source: rtos_arduino/trunk/arduino_lib/libraries/ESP8266/examples/TCPServer/TCPServer.ino@ 142

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

初期化の場所を修正.

File size: 3.2 KB
Line 
1/**
2 * @example TCPServer.ino
3 * @brief The TCPServer 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
22#include "ESP8266.h"
23
24#define SSID "ITEAD"
25#define PASSWORD "12345678"
26
27ESP8266 wifi;
28
29void setup(void)
30{
31 Serial.begin(9600);
32 Serial.print("setup begin\r\n");
33
34 wifi.begin(Serial5);
35
36 Serial.print("FW Version:");
37 Serial.println(wifi.getVersion().c_str());
38
39 if (wifi.setOprToStationSoftAP()) {
40 Serial.print("to station + softap ok\r\n");
41 } else {
42 Serial.print("to station + softap err\r\n");
43 }
44
45 if (wifi.joinAP(SSID, PASSWORD)) {
46 Serial.print("Join AP success\r\n");
47 Serial.print("IP: ");
48 Serial.println(wifi.getLocalIP().c_str());
49 } else {
50 Serial.print("Join AP failure\r\n");
51 }
52
53 if (wifi.enableMUX()) {
54 Serial.print("multiple ok\r\n");
55 } else {
56 Serial.print("multiple err\r\n");
57 }
58
59 if (wifi.startTCPServer(8090)) {
60 Serial.print("start tcp server ok\r\n");
61 } else {
62 Serial.print("start tcp server err\r\n");
63 }
64
65 if (wifi.setTCPServerTimeout(10)) {
66 Serial.print("set tcp server timout 10 seconds\r\n");
67 } else {
68 Serial.print("set tcp server timout err\r\n");
69 }
70
71 Serial.print("setup end\r\n");
72}
73
74void loop(void)
75{
76 uint8_t buffer[128] = {0};
77 uint8_t mux_id;
78 uint32_t len = wifi.recv(&mux_id, buffer, sizeof(buffer), 100);
79 if (len > 0) {
80 Serial.print("Status:[");
81 Serial.print(wifi.getIPStatus().c_str());
82 Serial.println("]");
83
84 Serial.print("Received from :");
85 Serial.print(mux_id);
86 Serial.print("[");
87 for(uint32_t i = 0; i < len; i++) {
88 Serial.print((char)buffer[i]);
89 }
90 Serial.print("]\r\n");
91
92 if(wifi.send(mux_id, buffer, len)) {
93 Serial.print("send back ok\r\n");
94 } else {
95 Serial.print("send back err\r\n");
96 }
97
98 if (wifi.releaseTCP(mux_id)) {
99 Serial.print("release tcp ");
100 Serial.print(mux_id);
101 Serial.println(" ok");
102 } else {
103 Serial.print("release tcp");
104 Serial.print(mux_id);
105 Serial.println(" err");
106 }
107
108 Serial.print("Status:[");
109 Serial.print(wifi.getIPStatus().c_str());
110 Serial.println("]");
111 }
112}
113
Note: See TracBrowser for help on using the repository browser.