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 40:0a83315aea0a, committed 2015-05-04
- Comitter:
- sam_grove
- Date:
- Mon May 04 12:04:54 2015 +0000
- Parent:
- 39:89e259295728
- Child:
- 41:264902b160ea
- Commit message:
- Update so close exits transparent mode without depending on state from the application
Changed in this revision
--- a/ESP8266/ESP8266.cpp Sat May 02 04:08:30 2015 +0000
+++ b/ESP8266/ESP8266.cpp Mon May 04 12:04:54 2015 +0000
@@ -42,13 +42,11 @@
#define ESP_MAX_TRY_JOIN 3
#define ESP_MAXID 4 // the largest possible ID Value (max num of sockets possible)
-extern Serial pc;
-
ESP8266 * ESP8266::inst;
char* ip = NULL;
-ESP8266::ESP8266( PinName tx, PinName rx, PinName _reset, const char * ssid, const char * phrase, uint32_t baud):
- wifi(tx, rx), reset_pin(_reset), buf_ESP8266(ESP_MBUFFE_MAX)
+ESP8266::ESP8266(PinName tx, PinName rx, PinName reset, const char *ssid, const char *phrase, uint32_t baud) :
+ wifi(tx, rx), reset_pin(reset), buf_ESP8266(ESP_MBUFFE_MAX)
{
INFO("Initializing ESP8266 object");
memset(&state, 0, sizeof(state));
@@ -59,13 +57,13 @@
if (this->ssid[i] == ' ')
this->ssid[i] = '$';
}
+
strcpy(this->phrase, phrase);
for (int i = 0; i < strlen(phrase); i++) {
if (this->phrase[i] == ' ')
this->phrase[i] = '$';
}
-
inst = this;
attach_rx(false);
@@ -167,7 +165,6 @@
char portstr[5];
sprintf(portstr, "%d", port);
sendCommand(( "AT+CIPSTART=\"UDP\",\"" + (string) ip + "\"," + (string) portstr ).c_str(), "OK", NULL, 10000);
-
sendCommand("AT+CIPMODE=1", "OK", NULL, 1000);// go into transparent mode
sendCommand("AT+CIPSEND", ">", NULL, 1000);// go into transparent mode
//DBG("Data Mode");
@@ -178,8 +175,9 @@
bool ESP8266::close()
{
+ wait(0.1f);
send("+++",3);
- wait(1);
+ wait(1.0f);
state.cmdMode = true;
sendCommand("AT+CIPCLOSE","OK", NULL, 10000);
return true;
@@ -257,9 +255,9 @@
void ESP8266::reset()
{
reset_pin = 0;
- wait(0.2);
+ wait_us(20);
reset_pin = 1;
- wait(1);
+ //wait(1);
//send("+++",3);
//wait(1);
@@ -289,10 +287,12 @@
void ESP8266::attach_rx(bool callback)
{
- if (!callback)
+ if (!callback) {
wifi.attach(NULL);
- else
+ }
+ else {
wifi.attach(this, &ESP8266::handler_rx);
+ }
}
int ESP8266::readable()
@@ -338,7 +338,7 @@
{
char read;
size_t found = string::npos;
- string checking;
+ string checking = "";
Timer tmr;
int result = 0;
@@ -353,10 +353,10 @@
if (!ACK || !strcmp(ACK, "NO")) {
for (int i = 0; i < strlen(cmd); i++) {
result = (putc(cmd[i]) == cmd[i]) ? result + 1 : result;
- wait(.005); // prevents stuck recieve ready (?) need to let echoed character get read first
+ wait(0.005f); // prevents stuck recieve ready (?) need to let echoed character get read first
}
putc(13); //CR
- wait(.005); // wait for echo
+ wait(0.005f); // wait for echo
putc(10); //LF
} else {
@@ -370,7 +370,7 @@
wait(.005); // wait for echo
}
putc(13); //CR
- wait(.005); // wait for echo
+ wait(0.005f); // wait for echo
putc(10); //LF
while (1) {
@@ -385,17 +385,17 @@
return -1;
} else if (readable()) {
read = getc();
- printf("%c",read); //debug echo
+ //printf("%c",read); //debug echo
if ( read != '\r' && read != '\n') {
checking += read;
found = checking.find(ACK);
if (found != string::npos) {
- wait(0.01);
+ wait(0.01f);
//We flush the buffer
while (readable())
read = getc();
- printf("%c",read); //debug echo
+ //printf("%c",read); //debug echo
break;
}
}
--- a/Socket/Endpoint.cpp Sat May 02 04:08:30 2015 +0000 +++ b/Socket/Endpoint.cpp Mon May 04 12:04:54 2015 +0000 @@ -19,8 +19,6 @@ #include "Socket/Endpoint.h" #include <cstring> -extern Serial pc; - using std::memset; Endpoint::Endpoint()
--- a/Socket/Socket.cpp Sat May 02 04:08:30 2015 +0000
+++ b/Socket/Socket.cpp Mon May 04 12:04:54 2015 +0000
@@ -20,7 +20,7 @@
#include <cstring>
//Debug is disabled by default
-#if 1
+#if 0
//Enable debug
#include <cstdio>
#define DBG(x, ...) std::printf("[Socket : DBG]"x" [%s,%d]\r\n", ##__VA_ARGS__,__FILE__,__LINE__);
@@ -35,8 +35,6 @@
#endif
-extern Serial pc;
-
Socket::Socket() : _blocking(true), _timeout(1500) {
wifi = ESP8266::getInstance();
if (wifi == NULL)
@@ -50,6 +48,7 @@
}
int Socket::close() {
+
return (wifi->close()) ? 0 : -1;
}
--- a/Socket/TCPSocketConnection.cpp Sat May 02 04:08:30 2015 +0000
+++ b/Socket/TCPSocketConnection.cpp Mon May 04 12:04:54 2015 +0000
@@ -23,7 +23,7 @@
using std::memcpy;
//Debug is disabled by default
-#ifdef DEBUG
+#if 0
#define DBG(x, ...) printf("[TCPConnection : DBG]"x"\r\n", ##__VA_ARGS__);
#define WARN(x, ...) printf("[TCPConnection: WARN]"x"\r\n", ##__VA_ARGS__);
#define ERR(x, ...) printf("[TCPConnection : ERR]"x"\r\n", ##__VA_ARGS__);
--- a/Socket/UDPSocket.cpp Sat May 02 04:08:30 2015 +0000
+++ b/Socket/UDPSocket.cpp Mon May 04 12:04:54 2015 +0000
@@ -21,8 +21,6 @@
#include <string>
#include <algorithm>
-extern Serial pc;
-
UDPSocket::UDPSocket()
{
endpoint_configured = false;
