Browse Source

Working to stop ESP from hanging

v_master
SRGDamia1 7 years ago
parent
commit
2055c4568f
5 changed files with 39 additions and 37 deletions
  1. +6
    -6
      TinyGsmClientA6.h
  2. +22
    -19
      TinyGsmClientESP8266.h
  3. +6
    -6
      TinyGsmClientM590.h
  4. +1
    -1
      TinyGsmClientSIM800.h
  5. +4
    -5
      TinyGsmClientXBee.h

+ 6
- 6
TinyGsmClientA6.h View File

@ -493,7 +493,7 @@ public:
if (!index) {
data.trim();
if (data.length()) {
DBG("### Unhandled:", data);
DBG(GSM_NL, "### Unhandled:", data);
}
}
else {
@ -512,13 +512,13 @@ public:
DBG(GSM_NL, "### Got: ", len, "->", sockets[mux]->rx.free());
}
while (len--) {
char c[2] = {0};
stream.readBytes(c, 1); // readBytes includes a timeout
if(c[0]) sockets[mux]->rx.put(c[0]);
// DBG(GSM_NL, c[0], " ", len, " ", stream.available(), " ", sockets[mux]->available());
TINY_GSM_YIELD();
int r = stream.read();
if (r <= 0) continue; // Skip 0x00 bytes, just in case
sockets[mux]->rx.put((char)r);
}
if (len_orig > sockets[mux]->available()) {
DBG(GSM_NL, "### Fewer characters received than expected: ", len_orig, "->", sockets[mux]->available());
DBG(GSM_NL, "### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig);
}
}
return index;


+ 22
- 19
TinyGsmClientESP8266.h View File

@ -12,7 +12,7 @@
//#define TINY_GSM_DEBUG Serial
#if !defined(TINY_GSM_RX_BUFFER)
#define TINY_GSM_RX_BUFFER 512
#define TINY_GSM_RX_BUFFER 256
#endif
#include <TinyGsmCommon.h>
@ -20,6 +20,7 @@
#define GSM_NL "\r\n"
static const char GSM_OK[] TINY_GSM_PROGMEM = "OK" GSM_NL;
static const char GSM_ERROR[] TINY_GSM_PROGMEM = "ERROR" GSM_NL;
static unsigned int TCP_KEEP_ALIVE = 120;
class TinyGsm
{
@ -78,6 +79,7 @@ public:
at->sendAT(GF("+CIPCLOSE="), mux);
sock_connected = false;
at->waitResponse();
at->waitResponse();
}
virtual size_t write(const uint8_t *buf, size_t size) {
@ -324,7 +326,7 @@ public:
if (!index) {
data.trim();
if (data.length()) {
DBG("### Unhandled:", data);
DBG(GSM_NL, "### Unhandled:", data);
}
}
else {
@ -335,23 +337,23 @@ public:
DBG(GSM_NL, "<<< ", data);
}
}
if (gotData) {
int len_orig = len;
if (len > sockets[mux]->rx.free()) {
DBG(GSM_NL, "### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
} else {
DBG(GSM_NL, "### Got: ", len, "->", sockets[mux]->rx.free());
}
while (len--) {
char c[2] = {0};
stream.readBytes(c, 1); // readBytes includes a timeout
if(c[0]) sockets[mux]->rx.put(c[0]);
// DBG(GSM_NL, c[0], " ", len, " ", stream.available(), " ", sockets[mux]->available());
}
if (len_orig > sockets[mux]->available()) {
DBG(GSM_NL, "### Fewer characters received than expected: ", len_orig, "->", sockets[mux]->available());
if (gotData) {
int len_orig = len;
if (len > sockets[mux]->rx.free()) {
DBG(GSM_NL, "### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
} else {
DBG(GSM_NL, "### Got: ", len, "->", sockets[mux]->rx.free());
}
while (len--) {
TINY_GSM_YIELD();
int r = stream.read();
if (r <= 0) continue; // Skip 0x00 bytes, just in case
sockets[mux]->rx.put((char)r);
}
if (len_orig > sockets[mux]->available()) {
DBG(GSM_NL, "### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig);
}
}
}
return index;
}
@ -371,11 +373,12 @@ public:
private:
int modemConnect(const char* host, uint16_t port, uint8_t mux) {
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port, GF(",120"));
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port, GF(","), TCP_KEEP_ALIVE);
int rsp = waitResponse(75000L,
GFP(GSM_OK),
GFP(GSM_ERROR),
GF(GSM_NL "ALREADY CONNECT" GSM_NL));
waitResponse(100, GF("1,CONNECT"));
return (1 == rsp);
}


+ 6
- 6
TinyGsmClientM590.h View File

@ -500,7 +500,7 @@ public:
if (!index) {
data.trim();
if (data.length()) {
DBG("### Unhandled:", data);
DBG(GSM_NL, "### Unhandled:", data);
}
}
else {
@ -519,13 +519,13 @@ public:
DBG(GSM_NL, "### Got: ", len, "->", sockets[mux]->rx.free());
}
while (len--) {
char c[2] = {0};
stream.readBytes(c, 1); // readBytes includes a timeout
if(c[0]) sockets[mux]->rx.put(c[0]);
// DBG(GSM_NL, c[0], " ", len, " ", stream.available(), " ", sockets[mux]->available());
TINY_GSM_YIELD();
int r = stream.read();
if (r <= 0) continue; // Skip 0x00 bytes, just in case
sockets[mux]->rx.put((char)r);
}
if (len_orig > sockets[mux]->available()) {
DBG(GSM_NL, "### Fewer characters received than expected: ", len_orig, "->", sockets[mux]->available());
DBG(GSM_NL, "### Fewer characters received than expected: ", sockets[mux]->available(), " vs ", len_orig);
}
}
return index;


+ 1
- 1
TinyGsmClientSIM800.h View File

@ -604,7 +604,7 @@ public:
if (!index) {
data.trim();
if (data.length()) {
DBG("### Unhandled:", data);
DBG(GSM_NL, "### Unhandled:", data);
}
}
else {


+ 4
- 5
TinyGsmClientXBee.h View File

@ -433,8 +433,8 @@ public:
data.replace(GSM_NL GSM_NL, GSM_NL);
data.replace(GSM_NL, "\r\n" " ");
if (data.length()) {
DBG("### Unhandled:", data);
}
DBG("### Unhandled:", data, "\r\n");
} else DBG(GSM_NL, "### NO RESPONSE!");
}
else {
data.trim();
@ -444,9 +444,6 @@ public:
DBG("<<< ", data, "\r\n");
}
}
// if (gotData) {
// sockets[mux]->sock_available = modemGetAvailable(mux);
// }
return index;
}
@ -518,12 +515,14 @@ private:
}
int streamRead() {
TINY_GSM_YIELD();
int c = stream.read();
DBG((char)c);
return c;
}
String streamReadUntil(char c) {
TINY_GSM_YIELD();
String return_string = stream.readStringUntil(c);
return_string.trim();
if (String(c) == GSM_NL){


Loading…
Cancel
Save