Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ESP8266.cpp
- Revision:
- 28:c25aff31dcc5
- Parent:
- 27:dc7ad070c5b1
- Child:
- 29:75185b05d6a4
--- a/ESP8266.cpp Wed Feb 04 11:30:09 2015 +0000
+++ b/ESP8266.cpp Wed Feb 04 13:35:35 2015 +0000
@@ -10,7 +10,7 @@
bool ESP8266::begin(void)
{
- m_esp_uart.begin(9600); //The default baud rate of ESP8266 is 115200
+ m_esp_uart.begin(9600);
m_esp_uart.flush();
m_esp_uart.setTimeout(5000);
m_esp_uart.println("AT+RST");
@@ -18,19 +18,6 @@
}
-/*************************************************************************
-//init port
-
- mode: setting operation mode
-
- chl: channel number
- ecn: encryption
-
- return:
- true - successfully
- false - unsuccessfully
-
-***************************************************************************/
bool ESP8266::init(uint8_t mode, String ssid, String pwd, uint8_t chl, uint8_t ecn)
{
if (mode == ESP8266_MODE_STA)
@@ -68,26 +55,7 @@
return true;
}
-/*************************************************************************
-//Set up tcp or udp connection
- type: tcp or udp
-
- addr: ip address
-
- port: port number
-
- a: set multiple connection
- 0 for sigle connection
- 1 for multiple connection
-
- id: id number(0-4)
-
- return:
- true - successfully
- false - unsuccessfully
-
-***************************************************************************/
bool ESP8266::ipConfig(uint8_t type, String addr, int port, uint8_t mux, uint8_t id)
{
bool result = false;
@@ -123,21 +91,9 @@
return result;
}
-/*************************************************************************
-//receive message from wifi
- buf: buffer for receiving data
-
- m_chl_id: <id>(0-4)
-
- return: size of the buffer
-
-
-***************************************************************************/
int ESP8266::recvData(char *buf)
{
- //+IPD,<len>:<data>
- //+IPD,<id>,<len>:<data>
String data = "";
if (m_esp_uart.available()>0)
{
@@ -160,7 +116,7 @@
break;
}
}
- //Serial.println(data);
+
int sLen = strlen(data.c_str());
int i,j;
for (i = 0; i <= sLen; i++)
@@ -211,15 +167,7 @@
return 0;
}
-//////////////////////////////////////////////////////////////////////////
-
-/*************************************************************************
-//reboot the wifi module
-
-
-
-***************************************************************************/
void ESP8266::reset(void)
{
m_esp_uart.println("AT+RST");
@@ -233,24 +181,7 @@
}
}
-/*********************************************
- *********************************************
- *********************************************
- ESP8266 Function Commands
- *********************************************
- *********************************************
- *********************************************
- */
-/*************************************************************************
-//inquire the current mode of wifi module
-
- return: string of current mode
- Station
- AP
- AP+Station
-
-***************************************************************************/
String ESP8266::showMode()
{
String data;
@@ -282,22 +213,6 @@
}
}
-
-
-/*************************************************************************
-//configure the operation mode
-
- a:
- 1 - Station
- 2 - AP
- 3 - AP+Station
-
- return:
- true - successfully
- false - unsuccessfully
-
-***************************************************************************/
-
bool ESP8266::confMode(uint8_t mode)
{
String data;
@@ -324,16 +239,6 @@
return false;
}
-
-/*************************************************************************
-//show the list of wifi hotspot
-
- return: string of wifi information
- encryption,SSID,RSSI
-
-
-***************************************************************************/
-
String ESP8266::showAP(void)
{
String data;
@@ -371,15 +276,6 @@
}
}
-
-/*************************************************************************
-//show the name of current wifi access port
-
- return: string of access port name
- AP:<SSID>
-
-
-***************************************************************************/
String ESP8266::showJAP(void)
{
bool ret = false;
@@ -416,16 +312,6 @@
}
}
-
-/*************************************************************************
-//configure the SSID and password of the access port
-
- return:
- true - successfully
- false - unsuccessfully
-
-
-***************************************************************************/
bool ESP8266::confJAP(String ssid , String pwd)
{
@@ -452,15 +338,6 @@
}
return false;
}
-/*************************************************************************
-//quite the access port
-
- return:
- true - successfully
- false - unsuccessfully
-
-
-***************************************************************************/
bool ESP8266::quitAP(void)
{
@@ -478,13 +355,6 @@
}
-/*************************************************************************
-//show the parameter of ssid, password, channel, encryption in AP mode
-
- return:
- mySAP:<SSID>,<password>,<channel>,<encryption>
-
-***************************************************************************/
String ESP8266::showSAP()
{
m_esp_uart.println("AT+CWSAP?");
@@ -513,15 +383,6 @@
return data;
}
-/*************************************************************************
-//configure the parameter of ssid, password, channel, encryption in AP mode
-
- return:
- true - successfully
- false - unsuccessfully
-
-***************************************************************************/
-
bool ESP8266::confSAP(String ssid , String pwd , uint8_t chl , uint8_t ecn)
{
m_esp_uart.print("AT+CWSAP=");
@@ -554,26 +415,6 @@
}
-/*********************************************
- *********************************************
- *********************************************
- TPC/IP Function Command
- *********************************************
- *********************************************
- *********************************************
- */
-
-/*************************************************************************
-//inquire the connection status
-
- return: string of connection status
- <ID> 0-4
- <type> tcp or udp
- <addr> ip
- <port> port number
-
-***************************************************************************/
-
String ESP8266::showStatus(void)
{
m_esp_uart.println("AT+CIPSTATUS");
@@ -602,14 +443,6 @@
return data;
}
-/*************************************************************************
-//show the current connection mode(sigle or multiple)
-
- return: string of connection mode
- 0 - sigle
- 1 - multiple
-
-***************************************************************************/
String ESP8266::showMux(void)
{
String data;
@@ -639,17 +472,6 @@
return data;
}
-/*************************************************************************
-//configure the current connection mode(sigle or multiple)
-
- a: connection mode
- 0 - sigle
- 1 - multiple
-
- return:
- true - successfully
- false - unsuccessfully
-***************************************************************************/
bool ESP8266::confMux(int mux)
{
m_esp_uart.print("AT+CIPMUX=");
@@ -666,33 +488,15 @@
return false;
}
-
-/*************************************************************************
-//Set up tcp or udp connection (signle connection mode)
-
- type: tcp or udp
-
- addr: ip address
-
- port: port number
-
-
- return:
- true - successfully
- false - unsuccessfully
-
-***************************************************************************/
bool ESP8266::newMux(uint8_t type, String addr, int port)
{
String data;
m_esp_uart.flush();
m_esp_uart.print("AT+CIPSTART=");
- if(type>0)
- {
+ if(ESP8266_COMM_TCP == type) {
m_esp_uart.print("\"TCP\"");
- }else
- {
+ } else if (ESP8266_COMM_UDP == type) {
m_esp_uart.print("\"UDP\"");
}
m_esp_uart.print(",");
@@ -700,9 +504,7 @@
m_esp_uart.print(addr);
m_esp_uart.print("\"");
m_esp_uart.print(",");
-// m_esp_uart.print("\"");
m_esp_uart.println(String(port));
-// m_esp_uart.println("\"");
unsigned long start;
start = millis();
while (millis()-start<10000) {
@@ -718,36 +520,16 @@
}
return false;
}
-/*************************************************************************
-//Set up tcp or udp connection (multiple connection mode)
- type: tcp or udp
-
- addr: ip address
-
- port: port number
-
- id: id number(0-4)
-
- return:
- true - successfully
- false - unsuccessfully
-
-***************************************************************************/
bool ESP8266::newMux( uint8_t id, uint8_t type, String addr, int port)
-
{
-
m_esp_uart.print("AT+CIPSTART=");
m_esp_uart.print("\"");
m_esp_uart.print(String(id));
m_esp_uart.print("\"");
- if(type>0)
- {
+ if(ESP8266_COMM_TCP == type) {
m_esp_uart.print("\"TCP\"");
- }
- else
- {
+ } else if (ESP8266_COMM_UDP == type) {
m_esp_uart.print("\"UDP\"");
}
m_esp_uart.print(",");
@@ -755,9 +537,7 @@
m_esp_uart.print(addr);
m_esp_uart.print("\"");
m_esp_uart.print(",");
-// m_esp_uart.print("\"");
m_esp_uart.println(String(port));
-// m_esp_uart.println("\"");
String data;
unsigned long start;
start = millis();
@@ -776,23 +556,12 @@
}
-/*************************************************************************
-//send data in sigle connection mode
- str: string of message
-
- return:
- true - successfully
- false - unsuccessfully
-
-***************************************************************************/
bool ESP8266::send(String str)
{
- m_esp_uart.flush();
+ m_esp_uart.flush();
m_esp_uart.print("AT+CIPSEND=");
-// m_esp_uart.print("\"");
m_esp_uart.println(str.length());
-// m_esp_uart.println("\"");
unsigned long start;
start = millis();
bool found = false;
@@ -828,18 +597,6 @@
return false;
}
-/*************************************************************************
-//send data in multiple connection mode
-
- id: <id>(0-4)
-
- str: string of message
-
- return:
- true - successfully
- false - unsuccessfully
-
-***************************************************************************/
bool ESP8266::send(uint8_t id, String str)
{
m_esp_uart.print("AT+CIPSEND=");
@@ -882,11 +639,7 @@
return false;
}
-/*************************************************************************
-//Close up tcp or udp connection (sigle connection mode)
-
-***************************************************************************/
void ESP8266::closeMux(void)
{
m_esp_uart.println("AT+CIPCLOSE");
@@ -907,13 +660,6 @@
}
}
-
-/*************************************************************************
-//Set up tcp or udp connection (multiple connection mode)
-
- id: id number(0-4)
-
-***************************************************************************/
void ESP8266::closeMux(uint8_t id)
{
m_esp_uart.print("AT+CIPCLOSE=");
@@ -971,21 +717,6 @@
}
}
-/*************************************************************************
-////set the parameter of server
-
- mode:
- 0 - close server mode
- 1 - open server mode
-
- port: <port>
-
- return:
- true - successfully
- false - unsuccessfully
-
-***************************************************************************/
-
bool ESP8266::confServer(uint8_t mode, int port)
{
m_esp_uart.print("AT+CIPSERVER=");