Fixed UDP Client. Allow interfacing with WebSocketClient. General improvements.
Fork of ESP8266Interface by
Revision 17:d11fa4c3ac65, committed 2014-12-01
- Comitter:
- michaeljkoster
- Date:
- Mon Dec 01 08:02:38 2014 +0000
- Parent:
- 16:3f0efaa57a12
- Child:
- 18:60422852e99c
- Commit message:
- working sort of
Changed in this revision
ESP8266/ESP8266.cpp | Show annotated file Show diff for this revision Revisions of this file |
Socket/Endpoint.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/ESP8266/ESP8266.cpp Mon Dec 01 06:22:00 2014 +0000 +++ b/ESP8266/ESP8266.cpp Mon Dec 01 08:02:38 2014 +0000 @@ -92,18 +92,20 @@ } bool ESP8266::startUDP(char* ip, int port){ - char* portstr = ""; + char portstr[5]; sprintf(portstr, "%d", port); + sendCommand(( "AT+CIPSTART=\"UDP\",\"" + (string) ip + "\",\"" + (string) portstr + "\"").c_str(), "OK", NULL, 10000); - sendCommand(( "AT+CIPSTART=\"UDP\",\"" + (string) ip + "\"" + (string) portstr + "\"").c_str(), "OK", NULL, 10000); - - sendCommand("AT+CIPSEND", "OK", NULL, 1000);// go into transparent mode + sendCommand("AT+CIPMODE=1", "OK", NULL, 1000);// go into transparent mode + sendCommand("AT+CIPSEND", ">", NULL, 1000);// go into transparent mode return true; } bool ESP8266::close() { + send("+++",3); + wait(1); sendCommand("AT+CIPCLOSE","OK", NULL, 10000); return true; } @@ -171,7 +173,7 @@ while (wifi.readable()){ c=wifi.getc(); buf_ESP8266.queue(c); - //pc.printf("%c",c); + pc.printf("%c",c); } } @@ -203,7 +205,7 @@ int ESP8266::putc(char c) { - while (!wifi.writeable()); + while (!wifi.writeable() || wifi.readable()); return wifi.putc(c); } @@ -215,10 +217,8 @@ int ESP8266::send(const char * buf, int len) { const char* bufptr=buf; - while(!wifi.writeable()){} for(int i=0; i<len; i++){ - wifi.putc((int)*bufptr++); - while(!wifi.writeable()){} + putc((int)*bufptr++); }return true; } @@ -230,52 +230,49 @@ Timer tmr; int result = 0; - DBG("will send: %s\r\n",cmd); + //pc.printf("will send: %s\r\n",cmd); - attach_rx(false); + attach_rx(true); //We flush the buffer - while (wifi.readable()) - wifi.getc(); + while (readable()) + getc(); - while(!wifi.writeable()){}; - if (!ACK || !strcmp(ACK, "NO")) { - for (int i = 0; i < sizeof(cmd); i++){ + for (int i = 0; i < strlen(cmd); i++){ result = (putc(cmd[i]) == cmd[i]) ? result + 1 : result; - while(!wifi.writeable()){}; + wait(.005); } putc(13); //CR - while(!wifi.writeable()){}; + wait(.005); putc(10); //LF } else { //We flush the buffer - while (wifi.readable()) - wifi.getc(); + while (readable()) + getc(); tmr.start(); - for (int i = 0; i < sizeof(cmd); i++){ + for (int i = 0; i < strlen(cmd); i++){ result = (putc(cmd[i]) == cmd[i]) ? result + 1 : result; - while(!wifi.writeable()){}; + wait(.005); } putc(13); //CR - while(!wifi.writeable()){}; + wait(.005); putc(10); //LF while (1) { if (tmr.read_ms() > timeout) { //We flush the buffer - while (wifi.readable()) - wifi.getc(); + while (readable()) + getc(); DBG("check: %s\r\n", checking.c_str()); attach_rx(true); return -1; - } else if (wifi.readable()) { - read = wifi.getc(); - pc.putc(read);//debug + } else if (readable()) { + read = getc(); if ( read != '\r' && read != '\n') { checking += read; found = checking.find(ACK); @@ -283,8 +280,8 @@ wait(0.01); //We flush the buffer - while (wifi.readable()) - wifi.getc(); + while (readable()) + getc(); break; } @@ -320,9 +317,9 @@ break; } - if (wifi.readable()) { + if (readable()) { tmr.start(); - read = wifi.getc(); + read = getc(); // we drop \r and \n if ( read != '\r' && read != '\n') { @@ -335,8 +332,8 @@ } //We flush the buffer - while (wifi.readable()) - wifi.getc(); + while (readable()) + getc(); attach_rx(true); DBG("result: %d\r\n", result)
--- a/Socket/Endpoint.cpp Mon Dec 01 06:22:00 2014 +0000 +++ b/Socket/Endpoint.cpp Mon Dec 01 08:02:38 2014 +0000 @@ -19,6 +19,8 @@ #include "Socket/Endpoint.h" #include <cstring> +extern Serial pc; + using std::memset; Endpoint::Endpoint() {