Skip to content

Commit cd07c84

Browse files
committed
Stupid 7080G with variable send buffer sizes
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
1 parent 49f8e26 commit cd07c84

File tree

1 file changed

+52
-8
lines changed

1 file changed

+52
-8
lines changed

src/TinyGsmClientSIM7080.h

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
#endif
3030
#define TINY_GSM_SEND_MAX_SIZE 1360
3131
// Up to 1460 bytes can be sent at a time with CASEND
32-
// NOTE: The manual says 1460, but my module never reports more than 1360
33-
// available, even without SSL.
32+
// NOTE: The manual says 1460, but the actual value seems to be variable.
33+
// I have modules P/N S2-108HB-Z3037 that never report more than 1360 available
34+
// and P/N S2-108HB-Z30GJ that top out at 1318.
3435
#ifdef TINY_GSM_MIN_SEND_BUFFER
3536
#undef TINY_GSM_MIN_SEND_BUFFER
3637
#endif
@@ -104,12 +105,13 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
104105
}
105106

106107
bool init(TinyGsmSim7080* modem, uint8_t mux = 0) {
107-
this->at = modem;
108-
sock_available = 0;
109-
prev_check = 0;
110-
sock_connected = false;
111-
got_data = false;
112-
is_mid_send = false;
108+
this->at = modem;
109+
sock_available = 0;
110+
prev_check = 0;
111+
sock_connected = false;
112+
got_data = false;
113+
is_mid_send = false;
114+
realMaxSendSize = TINY_GSM_SEND_MAX_SIZE;
113115

114116
// if it's a valid mux number, and that mux number isn't in use (or it's
115117
// already this), accept the mux number
@@ -156,6 +158,9 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
156158
*/
157159

158160
String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
161+
162+
protected:
163+
size_t realMaxSendSize;
159164
};
160165

161166
/*
@@ -1022,6 +1027,15 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
10221027
int8_t res = streamGetIntBefore('\n');
10231028
waitResponse();
10241029

1030+
// Immediately after connecting, before sending any data, we need to check
1031+
// actual the send buffer size, so we can wait for it to be available. The
1032+
// actual size is smaller than the size in the manual and seems to be
1033+
// variable, so we need to account for that when waiting for the buffer to
1034+
// be available.
1035+
sockets[mux]->realMaxSendSize = modemGetSendLength(mux);
1036+
DBG(GF("### Real max send size for mux"), mux, GF("is"),
1037+
sockets[mux]->realMaxSendSize);
1038+
10251039
return 0 == res;
10261040
}
10271041

@@ -1051,6 +1065,36 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
10511065
return leftsize;
10521066
}
10531067

1068+
size_t modemWaitForSendImpl(uint8_t mux, uint32_t timeout_ms = 15000L) {
1069+
size_t sendLength = modemGetSendLength(mux);
1070+
#if defined(TINY_GSM_DEBUG)
1071+
if (sendLength != sockets[mux]->realMaxSendSize) {
1072+
DBG(GF("### Full send buffer not available! Expected it to have"),
1073+
sockets[mux]->realMaxSendSize, GF("bytes, but it has"), sendLength);
1074+
}
1075+
if (sendLength < sockets[mux]->realMaxSendSize) {
1076+
DBG(GF(
1077+
"### Waiting up to 15s for sufficient available send buffer space"));
1078+
}
1079+
#endif
1080+
uint32_t start = millis();
1081+
while (sendLength < sockets[mux]->realMaxSendSize &&
1082+
millis() - start < timeout_ms && sockets[mux]->sock_connected) {
1083+
delay(250);
1084+
sendLength = modemGetSendLength(mux);
1085+
#if defined(TINY_GSM_DEBUG)
1086+
if (sendLength >= sockets[mux]->realMaxSendSize) {
1087+
DBG(GF("### Send buffer has"), sendLength, GF("available after"),
1088+
millis() - start, GF("ms"));
1089+
}
1090+
#endif
1091+
}
1092+
#if defined(TINY_GSM_DEBUG)
1093+
if (sendLength == 0) { DBG(GF("### No available send buffer!")); }
1094+
#endif
1095+
return sendLength;
1096+
}
1097+
10541098
size_t modemReadImpl(size_t size, uint8_t mux) {
10551099
if (!sockets[mux]) { return 0; }
10561100

0 commit comments

Comments
 (0)