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

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

ESP8266のサンプルの追加.

File size: 2.0 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#include "ESP8266.h"
10
11ESP8266 wifi;
12
13void setup()
14{
15 Serial.println("Web Server Task : Start!");
16
17 wifi.begin(Serial5, 115200);
18
19 Serial.print("FW Version:");
20 Serial.println(wifi.getVersion().c_str());
21
22#if 1
23 if (wifi.setOprToStation()) {
24 Serial.print("to station ok\r\n");
25 } else {
26 Serial.print("to station err\r\n");
27 }
28
29 if (wifi.joinAP(SSID, PASSWORD)) {
30 Serial.print("Join AP success\r\n");
31 Serial.print("IP: ");
32 Serial.println(wifi.getLocalIP().c_str());
33 } else {
34 Serial.print("Join AP failure\r\n");
35 }
36#else
37 if (wifi.setOprToSoftAP()) {
38 Serial.print("to softap ok\r\n");
39 } else {
40 Serial.print("to softap err\r\n");
41 }
42
43 if(wifi.setSoftAPParam(AP_SSID, AP_PASSWORD, 7, 0)){
44 Serial.print("Set SoftAP success\r\n");
45 Serial.print("IP: ");
46 Serial.println(wifi.getLocalIP().c_str());
47 }
48 else {
49 Serial.print("Set SoftAP failure\r\n");
50 }
51#endif
52 if (wifi.enableMUX()) {
53 Serial.print("multiple ok\r\n");
54 } else {
55 Serial.print("multiple err\r\n");
56 }
57
58 if (wifi.startTCPServer(80)) {
59 Serial.print("start tcp server ok\r\n");
60 } else {
61 Serial.print("start tcp server err\r\n");
62 }
63
64 if (wifi.setTCPServerTimeout(10)) {
65 Serial.print("set tcp server timout 10 seconds\r\n");
66 } else {
67 Serial.print("set tcp server timout err\r\n");
68 }
69
70 Serial.print("setup end\r\n");
71}
72
73
74void loop()
75{
76 uint8_t mux_id;
77 uint8_t buffer[128] = {0};
78 uint32_t len = wifi.recv(&mux_id, buffer, sizeof(buffer));
79
80 if(len == 0) {
81 return;
82 }
83
84 Serial.println("Web Server Task : Recive Request");
85
86 String cmd = (char*)buffer;
87
88 wifi.send(mux_id, cmd);
89 wifi.releaseTCP(mux_id);
90}
Note: See TracBrowser for help on using the repository browser.