source: rtos_arduino/trunk/examples/WifiEcho/rca_app.cpp@ 179

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

コード修正

File size: 3.3 KB
Line 
1#include "rca.h"
2
3//#define SSID "0024_MYNET"
4//#define PASSWORD "yf-19_yf-21_plus"
5
6//#define SSID "RX501NC_0B8C"
7//#define PASSWORD "50229567"
8
9#define SSID "ERTL_GLOBAL"
10#define PASSWORD "ertl__toppers"
11
12#define AP_SSID "M0_AP"
13#define AP_PASSWORD "none"
14
15#define WMODE_STATION
16
17#include "ESP8266.h"
18
19ESP8266 wifi;
20
21void setup()
22{
23 int ret;
24
25 Serial.println("Web Server Task : Start!");
26
27 ret = wifi.begin(Serial5, 115200);
28
29 if(ret == 1) {
30 Serial.print("Cannot communicate with ESP8266.");
31 while(1);
32 } else if(ret == 2) {
33 Serial.println("FW Version mismatch.");
34 Serial.print("FW Version:");
35 Serial.println(wifi.getVersion().c_str());
36 Serial.print("Supported FW Version:");
37 Serial.println(ESP8266_SUPPORT_VERSION);
38 while(1);
39 } else {
40 Serial.print("begin ok\r\n");
41 }
42
43 Serial.print("FW Version:");
44 Serial.println(wifi.getVersion().c_str());
45
46#ifdef WMODE_STATION
47 if (wifi.setOprToStation()) {
48 Serial.print("to station ok\r\n");
49 } else {
50 Serial.print("to station err\r\n");
51 }
52
53 if (wifi.joinAP(SSID, PASSWORD)) {
54 Serial.print("Join AP success\r\n");
55 Serial.print("IP: ");
56 Serial.println(wifi.getLocalIP().c_str());
57 } else {
58 Serial.print("Join AP failure\r\n");
59 }
60#else /* !WMODE_STATION */
61 if (wifi.setOprToSoftAP()) {
62 Serial.print("to softap ok\r\n");
63 } else {
64 Serial.print("to softap err\r\n");
65 }
66 if(wifi.setSoftAPParam(AP_SSID, AP_PASSWORD, 7, 0)){
67 Serial.print("Set SoftAP success\r\n");
68 Serial.print("IP: ");
69 Serial.println(wifi.getLocalIP().c_str());
70 }
71 else {
72 Serial.print("Set SoftAP failure\r\n");
73 }
74#endif /* WMODE_STATION */
75
76 if (wifi.enableMUX()) {
77 Serial.print("multiple ok\r\n");
78 } else {
79 Serial.print("multiple err\r\n");
80 }
81
82 if (wifi.startTCPServer(80)) {
83 Serial.print("start tcp server ok\r\n");
84 } else {
85 Serial.print("start tcp server err\r\n");
86 }
87
88 if (wifi.setTCPServerTimeout(10)) {
89 Serial.print("set tcp server timout 10 seconds\r\n");
90 } else {
91 Serial.print("set tcp server timout err\r\n");
92 }
93
94 Serial.print("setup end\r\n");
95}
96
97uint8_t mux_id_ptn;
98
99void loop()
100{
101 uint8_t mux_id;
102 uint8_t buffer[128] = {0};
103 uint8_t pre_mux_id_ptn;
104 uint32_t len
105
106 pre_mux_id_ptn = mux_id_ptn;
107
108 if(!wifi.getMuxCStatus(&mux_id_ptn)) {
109 Serial.println("isConnected(&mux_id_ptn) : Error!");
110 while(1);
111 }
112
113 if (pre_mux_id_ptn != mux_id_ptn) {
114 Serial.print("Connection Status changed! : 0x");
115 Serial.println(mux_id_ptn, HEX);
116 }
117
118 if(!wifi.isDataAvailable()) {
119 return;
120 }
121
122 if((len = wifi.recv(&mux_id, buffer, sizeof(buffer))) == 0) {
123 return;
124 }
125
126 String cmd = (char*)buffer;
127
128 Serial.print("Web Server Task : Recive Request from mux : ");
129 Serial.println(mux_id);
130 Serial.print("Web Server Task : Recive len : ");
131 Serial.println(len);
132 Serial.print("Web Server Task : Recive Data : ");
133 Serial.println(cmd);
134
135 if(!wifi.send(mux_id, cmd)) {
136 Serial.println("send(mux_id, cmd) : Error!");
137 while(1);
138 }
139
140 wifi.releaseTCP(mux_id);
141}
Note: See TracBrowser for help on using the repository browser.