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.
Dependencies: ArduinoAPI
Fork of WeeESP8266 by
Revision 22:27be62d9d01f, committed 2015-04-27
- Comitter:
- jakpor
- Date:
- Mon Apr 27 18:37:27 2015 +0000
- Parent:
- 21:d1a7f48ab3ba
- Commit message:
- Wifi - 90% skuteczno?ci
Changed in this revision
| ESP8266.cpp | Show annotated file Show diff for this revision Revisions of this file |
| ESP8266.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ESP8266.cpp Wed Feb 11 06:04:07 2015 +0000
+++ b/ESP8266.cpp Mon Apr 27 18:37:27 2015 +0000
@@ -27,6 +27,13 @@
m_puart->flush();
}
+void ESP8266::clear_serial()
+{
+ m_puart->flush();
+ // 510 zer (długosc bufora)
+ m_puart->println("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
+}
+
bool ESP8266::kick(void)
{
@@ -137,11 +144,35 @@
return list;
}
-String ESP8266::getIPStatus(void)
+int ESP8266::getIPStatus(void)
{
- String list;
- eATCIPSTATUS(list);
- return list;
+ String komenda = "AT+CIPSTATUS";
+
+ String data;
+ char a;
+ unsigned long start;
+ m_puart->flush();
+ clear_serial();
+ m_puart -> println(komenda);
+ start = millis();
+ while (millis() - start < 1000) {
+ while(m_puart ->available() > 0) {
+ a = m_puart ->readChr();
+ data +=a;
+ }
+ if (data.indexOf("OK") != -1) {
+ break;
+ }
+ if (data.indexOf("ERROR") != -1 ) {
+ return -1; //jak zle to powtarzam;
+ }
+ }
+ char num;
+ num = data[21];
+ return num-48;
+// String list;
+// eATCIPSTATUS(list);
+// return list;
}
String ESP8266::getLocalIP(void)
@@ -486,14 +517,29 @@
bool ESP8266::sATCWJAP(String ssid, String pwd)
{
String data;
+ String komunikat = "";
+ komunikat += "AT+CWJAP=\"";
+ komunikat += ssid;
+ komunikat += "\",\"";
+ komunikat += pwd;
+ komunikat += "\"";
+ komunikat+="\r\n";
+//
+// for(int i = 0; i<=komunikat.length(); i++){
+// m_puart->printf("%c",komunikat[i]);
+// m_puart->flush();
+// }
+
+// m_puart->print("AT+CWJAP=\"");
+// m_puart->print(ssid);
+// m_puart->print("\",\"");
+// m_puart->print(pwd);
+
m_puart->flush();
- m_puart->print("AT+CWJAP=\"");
- m_puart->print(ssid);
- m_puart->print("\",\"");
- m_puart->print(pwd);
- m_puart->println("\"");
+ clear_serial();
+ m_puart->println(komunikat);
- data = recvString("OK", "FAIL", 10000);
+ data = recvString("OK", "FAIL", 20000);
if (data.indexOf("OK") != -1) {
return true;
}
@@ -572,17 +618,24 @@
{
String data;
m_puart->flush();
- m_puart->print("AT+CIPSTART=");
- m_puart->print(mux_id);
- m_puart->print(",\"");
- m_puart->print(type);
- m_puart->print("\",\"");
- m_puart->print(addr);
- m_puart->print("\",");
- m_puart->println(port);
-
- data = recvString("OK", "ERROR", "ALREADY CONNECT", 10000);
- if (data.indexOf("OK") != -1 || data.indexOf("ALREADY CONNECT") != -1) {
+ String komunikat = "";
+ komunikat += "AT+CIPSTART=";
+ komunikat += mux_id;
+ komunikat += ",\"";
+ komunikat += type;
+ komunikat += "\",\"";
+ komunikat += addr;
+ komunikat += "\",";
+ komunikat += port;
+ komunikat+="\r\n";
+
+ m_puart->flush();
+ clear_serial();
+ m_puart->println(komunikat);
+
+
+ data = recvString("OK", "ERROR", "CONNECT", 10000);
+ if ((data.indexOf("OK") != -1) ||(data.indexOf("CONNECT")!= -1)|| (data.indexOf("ALREADY CONNECT") != -1)) {
return true;
}
return false;
@@ -663,7 +716,7 @@
m_puart->print("AT+CIPSERVER=1,");
m_puart->println(port);
- data = recvString("OK", "no change");
+ data = recvString("OK", "no change",1000);
if (data.indexOf("OK") != -1 || data.indexOf("no change") != -1) {
return true;
}
--- a/ESP8266.h Wed Feb 11 06:04:07 2015 +0000
+++ b/ESP8266.h Mon Apr 27 18:37:27 2015 +0000
@@ -36,6 +36,9 @@
*/
ESP8266(ArduinoSerial &uart); /* baud rate is 9600 */
+ // funkcja do czyszczenia bufora (flush tylko zwalnia pamięć, a dużo zer ją wyzeruje)
+ void clear_serial();
+
/**
* Verify ESP8266 whether live or not.
*
@@ -43,7 +46,7 @@
*
* @retval true - alive.
* @retval false - dead.
- */
+ */
bool kick(void);
/**
@@ -139,8 +142,10 @@
* Get the current status of connection(UDP and TCP).
*
* @return the status.
+ true - connected
+ false - disconnected
*/
- String getIPStatus(void);
+ int getIPStatus(void);
/**
* Get the IP address of ESP8266.
