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

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

初期化の場所を修正.

File size: 2.9 KB
Line 
1/**
2 * @example UDPClientMultiple.ino
3 * @brief The UDPClientMultiple 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#define HOST_NAME "172.16.5.12"
27#define HOST_PORT (5416)
28
29ESP8266 wifi;
30
31void setup(void)
32{
33 Serial.begin(9600);
34 Serial.print("setup begin\r\n");
35
36 wifi.begin(Serial5);
37
38 Serial.print("FW Version:");
39 Serial.println(wifi.getVersion().c_str());
40
41 if (wifi.setOprToStationSoftAP()) {
42 Serial.print("to station + softap ok\r\n");
43 } else {
44 Serial.print("to station + softap err\r\n");
45 }
46
47 if (wifi.joinAP(SSID, PASSWORD)) {
48 Serial.print("Join AP success\r\n");
49 Serial.print("IP: ");
50 Serial.println(wifi.getLocalIP().c_str());
51 } else {
52 Serial.print("Join AP failure\r\n");
53 }
54
55 if (wifi.enableMUX()) {
56 Serial.print("multiple ok\r\n");
57 } else {
58 Serial.print("multiple err\r\n");
59 }
60
61 Serial.print("setup end\r\n");
62}
63
64void loop(void)
65{
66 uint8_t buffer[128] = {0};
67 static uint8_t mux_id = 0;
68
69 if (wifi.registerUDP(mux_id, HOST_NAME, HOST_PORT)) {
70 Serial.print("register udp ");
71 Serial.print(mux_id);
72 Serial.println(" ok");
73 } else {
74 Serial.print("register udp ");
75 Serial.print(mux_id);
76 Serial.println(" err");
77 }
78
79 char *hello = "Hello, this is client!";
80 wifi.send(mux_id, (const uint8_t*)hello, strlen(hello));
81
82 uint32_t len = wifi.recv(mux_id, buffer, sizeof(buffer), 10000);
83 if (len > 0) {
84 Serial.print("Received:[");
85 for(uint32_t i = 0; i < len; i++) {
86 Serial.print((char)buffer[i]);
87 }
88 Serial.print("]\r\n");
89 }
90
91 if (wifi.unregisterUDP(mux_id)) {
92 Serial.print("unregister udp ");
93 Serial.print(mux_id);
94 Serial.println(" ok");
95 } else {
96 Serial.print("unregister udp ");
97 Serial.print(mux_id);
98 Serial.println(" err");
99 }
100 delay(5000);
101 mux_id++;
102 if (mux_id >= 5) {
103 mux_id = 0;
104 }
105}
106
Note: See TracBrowser for help on using the repository browser.