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.
Fork of ESP8266Interface by
Revision 50:3e59ddd16330, committed 2017-02-06
- Comitter:
- blownelco
- Date:
- Mon Feb 06 08:33:32 2017 +0000
- Parent:
- 49:c5c9899c0255
- Commit message:
- test arne
Changed in this revision
| ESP8266/ESP8266.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/ESP8266/ESP8266.cpp Tue Dec 06 15:41:58 2016 +0000
+++ b/ESP8266/ESP8266.cpp Mon Feb 06 08:33:32 2017 +0000
@@ -21,22 +21,25 @@
#include "Endpoint.h"
#include <string>
#include <algorithm>
+#include <test.h>
//Debug is disabled by default
-
+#if 0
#define DBG(x, ...) printf("[ESP8266 : DBG]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
#define WARN(x, ...) printf("[ESP8266 : WARN]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
#define ERR(x, ...) printf("[ESP8266 : ERR]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
-//#else
-//#define DBG(x, ...) //wait_us(10);
-//#define WARN(x, ...) //wait_us(10);
-//#define ERR(x, ...)
+#else
+#define DBG(x, ...) //wait_us(10);
+#define WARN(x, ...) //wait_us(10);
+#define ERR(x, ...)
+#endif
-
+#if 0
#define INFO(x, ...) printf("[ESP8266 : INFO]"x" \t[%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
-//#else
-//#define INFO(x, ...)
+#else
+#define INFO(x, ...)
+#endif
#define ESP_MAX_TRY_JOIN 3
@@ -47,8 +50,6 @@
DigitalOut led3(PTA13); // RGB LED
-
-
ESP8266 * ESP8266::inst;
char* ip = NULL;
@@ -64,7 +65,7 @@
inst = this;
attach_rx(false);
- wifi.baud(baud); // initial baud rate of the ESP8266
+ wifi.baud(9600); // initial baud rate of the ESP8266
state.associated = false;
state.cmdMode = false;
@@ -72,16 +73,21 @@
bool ESP8266::join()
{
+ int d;
sendCommand( "AT+CWMODE=1", "change", NULL, 1000);
string cmd="AT+CWJAP=\""+(string)this->ssid+"\",\""+(string)this->phrase+"\"";
if( sendCommand( cmd.c_str(), "OK", NULL, 10000) ) {
// successfully joined the network
state.associated = true;
INFO("ssid: %s, phrase: %s", this->ssid, this->phrase);
- sendCommand("AT+CIFSR", "OK", NULL, 1000);
-
-
-
+
+ //ESP8266::getIPAddress();
+ // printf("after get ip address \n");
+ /*for(d = 0;d<cnt;d++)
+ {
+ printf("%c",data[d]);
+ }*/
+
return true;
}
return false;
@@ -233,6 +239,7 @@
*/
char* ESP8266::getIPAddress()
{
+
char result[30] = {0};
int check = 0;
check = sendCommand("AT+CIFSR", NULL, result, 1000);
@@ -287,9 +294,9 @@
{
reset_pin = 0;
wait_us(20);
- reset_pin = 1;
- //wait(1);
- //reset_pin = !reset_pin
+ reset_pin = 0;
+ wait(1);
+ reset_pin = !reset_pin;
//send("+++",3);
wait(1);
state.cmdMode = true;
@@ -375,6 +382,7 @@
string checking = "";
Timer tmr;
int result = 0;
+ led3 = !led3;
DBG("sendCmd:\t %s",cmd);
@@ -413,13 +421,15 @@
while (readable())
getc();
led4 = !led4;
- DBG("check:\t %s", checking.c_str());
+ //DBG("check:\t %s", checking.c_str());
attach_rx(true);
return -1;
} else if (readable()) {
read = getc();
- printf("%c",read); //debug echo
+ DBG("check:\t %c", read);
+
+ //printf("%c",read); //debug echo
if ( read != '\r' && read != '\n') {
checking += read;
found = checking.find(ACK);
@@ -429,14 +439,14 @@
//We flush the buffer
while (readable())
read = getc();
+ DBG("check:\t %c", read);
led4 = !led4;
- printf("%c",read); //debug echo
break;
}
}
}
}
- DBG("check: %s", checking.c_str());
+ //DBG("check: %s", checking.c_str());
attach_rx(true);
return result;
@@ -455,20 +465,20 @@
break;
}
res[i] = '\0';
- DBG("user str 1: %s", res);
+ //DBG("user str 1: %s", res);
break;
} else {
if (tmr.read_ms() > 300) {
res[i] = '\0';
- DBG("user str: %s", res);
+ //DBG("user str: %s", res);
break;
}
if (readable()) {
tmr.start();
read = getc();
-
+ //DBG("read:\t %c", read);
// we drop \r and \n
if ( read != '\r' && read != '\n') {
res[i++] = read;
@@ -476,7 +486,7 @@
}
}
}
- DBG("user str: %s", res);
+ //DBG("user str: %s", res);
}
//We flush the buffer
@@ -484,6 +494,6 @@
getc();
attach_rx(true);
- DBG("result: %d", result)
+ //DBG("result: %d", result)
return result;
}
