pengfei wu
/
ESP8266Program
For test
Diff: ESP8266.cpp
- Revision:
- 35:90be2bc2a492
- Parent:
- 33:f721a46ef2f2
--- a/ESP8266.cpp Thu Feb 05 03:38:10 2015 +0000 +++ b/ESP8266.cpp Thu Feb 05 06:48:45 2015 +0000 @@ -45,26 +45,22 @@ return confJAP(ssid, pwd); } -bool ESP8266::setSoftAPMode(String sap_ssid, String sap_pwd, - ESP8266Channel chl, ESP8266Encrypstion ecn) +bool ESP8266::setSoftAPMode(String sap_ssid, String sap_pwd, int chl, ESP8266Encrypstion ecn) { if (!confMode(ESP8266_MODE_SAP)) { return false; } - reset(); return confSAP(sap_ssid, sap_pwd, chl, ecn); } -bool ESP8266::setStationSoftAPMode(String ssid, String pwd, - String sap_ssid, String sap_pwd , - ESP8266Channel chl, ESP8266Encrypstion ecn) +bool ESP8266::setStationSoftAPMode(String ssid, String pwd, String sap_ssid, String sap_pwd , + int chl, ESP8266Encrypstion ecn) { if (!confMode(ESP8266_MODE_STA_SAP)) { return false; } - reset(); if (confJAP(ssid, pwd) && confSAP(sap_ssid, sap_pwd, chl, ecn)) { return true; } else { @@ -72,43 +68,24 @@ } } - -bool ESP8266::ipConfig(uint8_t type, String addr, int port, uint8_t mux, uint8_t id) +bool ESP8266::ipConfig(ESP8266CommType type, String addr, int port, ESP8266Mux mux, int id) { bool result = false; - if (mux == 0 ) + if (mux == ESP8266_MUX_SINGLE) { confMux(mux); - - long timeStart = millis(); - while (1) - { - long time0 = millis(); - if (time0 - timeStart > 5000) - { - break; - } - } + delay(5000); result = newMux(type, addr, port); } - else if (mux == 1) + else if (mux == ESP8266_MUX_MULTIPLE) { confMux(mux); - long timeStart = millis(); - while (1) - { - long time0 = millis(); - if (time0 - timeStart > 5000) - { - break; - } - } + delay(5000); result = newMux(id, type, addr, port); } return result; } - int ESP8266::recvData(char *buf) { String data = ""; @@ -215,7 +192,7 @@ } } -bool ESP8266::confMode(uint8_t mode) +bool ESP8266::confMode(ESP8266WorkMode mode) { String data; m_uart.flush(); @@ -395,7 +372,7 @@ return data; } -bool ESP8266::confSAP(String ssid , String pwd , uint8_t chl , uint8_t ecn) +bool ESP8266::confSAP(String ssid , String pwd , int chl , int ecn) { m_uart.print("AT+CWSAP="); m_uart.print("\""); //"ssid" @@ -484,7 +461,7 @@ return data; } -bool ESP8266::confMux(int mux) +bool ESP8266::confMux(ESP8266Mux mux) { m_uart.print("AT+CIPMUX="); m_uart.println(mux); @@ -500,7 +477,7 @@ return false; } -bool ESP8266::newMux(uint8_t type, String addr, int port) +bool ESP8266::newMux(ESP8266CommType type, String addr, int port) { String data; @@ -533,7 +510,7 @@ return false; } -bool ESP8266::newMux( uint8_t id, uint8_t type, String addr, int port) +bool ESP8266::newMux( int id, ESP8266CommType type, String addr, int port) { m_uart.print("AT+CIPSTART="); m_uart.print("\""); @@ -609,7 +586,7 @@ return false; } -bool ESP8266::send(uint8_t id, String str) +bool ESP8266::send(int id, String str) { m_uart.print("AT+CIPSEND="); @@ -672,7 +649,7 @@ } } -void ESP8266::closeMux(uint8_t id) +void ESP8266::closeMux(int id) { m_uart.print("AT+CIPCLOSE="); m_uart.println(String(id)); @@ -729,7 +706,7 @@ } } -bool ESP8266::confServer(uint8_t mode, int port) +bool ESP8266::confServer(int mode, int port) { m_uart.print("AT+CIPSERVER="); m_uart.print(String(mode));