Changeset 179 for rtos_arduino


Ignore:
Timestamp:
Mar 28, 2016, 2:24:53 PM (8 years ago)
Author:
ertl-honda
Message:

コード修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtos_arduino/trunk/examples/WifiEcho/rca_app.cpp

    r146 r179  
    11#include "rca.h"
    22
    3 #define SSID       ""
    4 #define PASSWORD   ""
     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"
    511
    612#define AP_SSID       "M0_AP"
    713#define AP_PASSWORD   "none"
     14
     15#define WMODE_STATION
    816
    917#include "ESP8266.h"
     
    1321void setup()
    1422{
     23    int ret;
     24   
    1525    Serial.println("Web Server Task : Start!");
    1626   
    17     wifi.begin(Serial5, 115200);
    18    
     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
    1943    Serial.print("FW Version:");
    2044    Serial.println(wifi.getVersion().c_str());
    2145   
    22 #if 1
     46#ifdef  WMODE_STATION
    2347    if (wifi.setOprToStation()) {
    2448        Serial.print("to station ok\r\n");
     
    3458        Serial.print("Join AP failure\r\n");
    3559    }
    36 #else
     60#else /* !WMODE_STATION */
    3761    if (wifi.setOprToSoftAP()) {
    3862        Serial.print("to softap ok\r\n");
    3963    } else {
    4064        Serial.print("to softap err\r\n");
    41     }
    42    
     65    }   
    4366    if(wifi.setSoftAPParam(AP_SSID, AP_PASSWORD, 7, 0)){
    4467        Serial.print("Set SoftAP success\r\n");
     
    4972        Serial.print("Set SoftAP failure\r\n");
    5073    }
    51 #endif
     74#endif /* WMODE_STATION */
     75   
    5276    if (wifi.enableMUX()) {
    5377        Serial.print("multiple ok\r\n");
     
    5579        Serial.print("multiple err\r\n");
    5680    }
    57    
     81
    5882    if (wifi.startTCPServer(80)) {
    5983        Serial.print("start tcp server ok\r\n");
     
    6791        Serial.print("set tcp server timout err\r\n");
    6892    }
    69    
     93
    7094    Serial.print("setup end\r\n");
    7195}
    7296
     97uint8_t mux_id_ptn;
    7398
    7499void loop()
     
    76101    uint8_t mux_id;
    77102    uint8_t buffer[128] = {0};
    78     uint32_t len = wifi.recv(&mux_id, buffer, sizeof(buffer));
     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    }
    79112   
    80     if(len == 0) {
     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()) {
    81119        return;
    82120    }
     121     
     122    if((len = wifi.recv(&mux_id, buffer, sizeof(buffer))) == 0) {
     123        return;
     124    }
     125
     126    String cmd = (char*)buffer;
    83127   
    84     Serial.println("Web Server Task : Recive Request");
    85        
    86     String cmd = (char*)buffer;
    87 
    88     wifi.send(mux_id, cmd);
     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   
    89140    wifi.releaseTCP(mux_id);
    90141}
Note: See TracChangeset for help on using the changeset viewer.