|
29 | 29 | #endif |
30 | 30 | #define TINY_GSM_SEND_MAX_SIZE 1360 |
31 | 31 | // 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. |
34 | 35 | #ifdef TINY_GSM_MIN_SEND_BUFFER |
35 | 36 | #undef TINY_GSM_MIN_SEND_BUFFER |
36 | 37 | #endif |
@@ -104,12 +105,13 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>, |
104 | 105 | } |
105 | 106 |
|
106 | 107 | 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; |
113 | 115 |
|
114 | 116 | // if it's a valid mux number, and that mux number isn't in use (or it's |
115 | 117 | // already this), accept the mux number |
@@ -156,6 +158,9 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>, |
156 | 158 | */ |
157 | 159 |
|
158 | 160 | String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED; |
| 161 | + |
| 162 | + protected: |
| 163 | + size_t realMaxSendSize; |
159 | 164 | }; |
160 | 165 |
|
161 | 166 | /* |
@@ -1022,6 +1027,15 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>, |
1022 | 1027 | int8_t res = streamGetIntBefore('\n'); |
1023 | 1028 | waitResponse(); |
1024 | 1029 |
|
| 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 | + |
1025 | 1039 | return 0 == res; |
1026 | 1040 | } |
1027 | 1041 |
|
@@ -1051,6 +1065,36 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>, |
1051 | 1065 | return leftsize; |
1052 | 1066 | } |
1053 | 1067 |
|
| 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 | + |
1054 | 1098 | size_t modemReadImpl(size_t size, uint8_t mux) { |
1055 | 1099 | if (!sockets[mux]) { return 0; } |
1056 | 1100 |
|
|
0 commit comments