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

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

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

File size: 2.6 KB
Line 
1/**
2 * @example TCPClientSingle.ino
3 * @brief The TCPClientSingle 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 wifi.begin(Serial5);
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.disableMUX()) {
54 Serial.print("single ok\r\n");
55 } else {
56 Serial.print("single err\r\n");
57 }
58
59 Serial.print("setup end\r\n");
60}
61
62void loop(void)
63{
64 uint8_t buffer[128] = {0};
65
66 if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
67 Serial.print("create tcp ok\r\n");
68 } else {
69 Serial.print("create tcp err\r\n");
70 }
71
72 char *hello = "Hello, this is client!";
73 wifi.send((const uint8_t*)hello, strlen(hello));
74
75 uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
76 if (len > 0) {
77 Serial.print("Received:[");
78 for(uint32_t i = 0; i < len; i++) {
79 Serial.print((char)buffer[i]);
80 }
81 Serial.print("]\r\n");
82 }
83
84 if (wifi.releaseTCP()) {
85 Serial.print("release tcp ok\r\n");
86 } else {
87 Serial.print("release tcp err\r\n");
88 }
89 delay(5000);
90}
91
Note: See TracBrowser for help on using the repository browser.