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

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

修正

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