More quectel fixes

This commit is contained in:
Sara Damiano
2019-09-06 18:06:11 -04:00
parent 7087a31e6e
commit aeb7579fd2
6 changed files with 104 additions and 56 deletions

View File

@@ -23,7 +23,7 @@ with your board before submitting any issues.
Main processor board: <!-- Uno, Zero, ESP32, Particle, etc --> Main processor board: <!-- Uno, Zero, ESP32, Particle, etc -->
Modem: <!-- Brand, model, variant, firmware version --> Modem: <!-- Brand, model, variant, firmware version -->
TinyGSM version: <!-- always try to use the latest (0.9.14) --> TinyGSM version: <!-- always try to use the latest (0.9.15) -->
Code: <!-- Example name or paste in your code --> Code: <!-- Example name or paste in your code -->
### Scenario, steps to reproduce ### Scenario, steps to reproduce

View File

@@ -1,6 +1,6 @@
{ {
"name": "TinyGSM", "name": "TinyGSM",
"version": "0.9.14", "version": "0.9.15",
"description": "A small Arduino library for GPRS modules, that just works. Includes examples for Blynk, MQTT, File Download, and Web Client. Supports many GSM, LTE, and WiFi modules with AT command interfaces.", "description": "A small Arduino library for GPRS modules, that just works. Includes examples for Blynk, MQTT, File Download, and Web Client. Supports many GSM, LTE, and WiFi modules with AT command interfaces.",
"keywords": "GSM, AT commands, AT, SIM800, SIM900, A6, A7, M590, ESP8266, SIM7000, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900A, SIM900D, SIM908, SIM968, M95, MC60, MC60E, BG96, ublox, Quectel, SIMCOM, AI Thinker, LTE, LTE-M", "keywords": "GSM, AT commands, AT, SIM800, SIM900, A6, A7, M590, ESP8266, SIM7000, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900A, SIM900D, SIM908, SIM968, M95, MC60, MC60E, BG96, ublox, Quectel, SIMCOM, AI Thinker, LTE, LTE-M",
"authors": "authors":

View File

@@ -1,5 +1,5 @@
name=TinyGSM name=TinyGSM
version=0.9.14 version=0.9.15
author=Volodymyr Shymanskyy author=Volodymyr Shymanskyy
maintainer=Volodymyr Shymanskyy maintainer=Volodymyr Shymanskyy
sentence=A small Arduino library for GPRS modules, that just works. sentence=A small Arduino library for GPRS modules, that just works.

View File

@@ -64,7 +64,6 @@ public:
this->mux = mux; this->mux = mux;
sock_available = 0; sock_available = 0;
sock_connected = false; sock_connected = false;
got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
@@ -110,7 +109,6 @@ private:
uint8_t mux; uint8_t mux;
uint16_t sock_available; uint16_t sock_available;
bool sock_connected; bool sock_connected;
bool got_data;
RxFifo rx; RxFifo rx;
}; };
@@ -369,17 +367,41 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
return false; return false;
} }
//Set Method to Handle Received TCP/IP Data - Retrieve Data by Command // Set Method to Handle Received TCP/IP Data
// Mode = 1 - Output a notification when data is received
// “+QIRDI: <id>,<sc>,<sid>”
sendAT(GF("+QINDI=1")); sendAT(GF("+QINDI=1"));
if (waitResponse() != 1) { if (waitResponse() != 1) {
return false; return false;
} }
//Request an IP header for received data ("IPD(data length):") // // Request an IP header for received data
sendAT(GF("+QIHEAD=1")); // // "IPD(data length):"
if (waitResponse() != 1) { // sendAT(GF("+QIHEAD=1"));
return false; // if (waitResponse() != 1) {
} // return false;
// }
//
// // Do NOT show the IP address of the sender when receiving data
// // The format to show the address is: RECV FROM: <IP ADDRESS>:<PORT>
// sendAT(GF("+QISHOWRA=0"));
// if (waitResponse() != 1) {
// return false;
// }
//
// // Do NOT show the protocol type at the end of the header for received data
// // IPD(data length)(TCP/UDP):
// sendAT(GF("+QISHOWPT=0"));
// if (waitResponse() != 1) {
// return false;
// }
//
// // Do NOT show the destination address before receiving data
// // The format to show the address is: TO:<IP ADDRESS>
// sendAT(GF("+QISHOWLA=0"));
// if (waitResponse() != 1) {
// return false;
// }
return true; return true;
} }
@@ -637,15 +659,23 @@ protected:
// sid = index of connection = mux // sid = index of connection = mux
// len = maximum length of data to retrieve // len = maximum length of data to retrieve
sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size); sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size);
// sendAT(GF("+QIRD="), mux, ',', (uint16_t)size); // If it replies only OK for the write command, it means there is no
if (waitResponse(GF("+QIRD:")) != 1) { // received data in the buffer of the connection.
return 0; int res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR));
} if (res == 1) {
streamSkipUntil(':'); // skip IP address streamSkipUntil(':'); // skip IP address
streamSkipUntil(','); // skip port streamSkipUntil(','); // skip port
streamSkipUntil(','); // skip connection type (TCP/UDP) streamSkipUntil(','); // skip connection type (TCP/UDP)
int len = stream.readStringUntil('\n').toInt(); // read length // read the real length of the retrieved data
for (int i=0; i<len; i++) { uint16_t len = stream.readStringUntil('\n').toInt();
// We have no way of knowing in advance how much data will be in the buffer
// so when data is received we always assume the buffer is completely full.
// Chances are, this is not true and there's really not that much there.
// In that case, make sure we make sure we re-set the amount of data available.
if (len < size) {
sockets[mux]->sock_available = len;
}
for (uint16_t i=0; i<len; i++) {
TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
sockets[mux]->sock_available--; sockets[mux]->sock_available--;
// ^^ One less character available after moving from modem's FIFO to our FIFO // ^^ One less character available after moving from modem's FIFO to our FIFO
@@ -653,6 +683,10 @@ protected:
waitResponse(); // ends with an OK waitResponse(); // ends with an OK
DBG("### READ:", len, "from", mux); DBG("### READ:", len, "from", mux);
return len; return len;
} else {
sockets[mux]->sock_available = 0;
return 0;
}
} }
bool modemGetConnected(uint8_t mux) { bool modemGetConnected(uint8_t mux) {
@@ -725,7 +759,9 @@ TINY_GSM_MODEM_STREAM_UTILITIES()
int mux = stream.readStringUntil('\n').toInt(); int mux = stream.readStringUntil('\n').toInt();
DBG("### Got Data:", mux); DBG("### Got Data:", mux);
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; // We have no way of knowing how much data actually came in, so
// we set the value to 1500, the maximum possible size.
sockets[mux]->sock_available = 1500;
} }
data = ""; data = "";
} else if (data.endsWith(GF("CLOSED" GSM_NL))) { } else if (data.endsWith(GF("CLOSED" GSM_NL))) {

View File

@@ -68,7 +68,6 @@ public:
this->mux = mux; this->mux = mux;
sock_available = 0; sock_available = 0;
sock_connected = false; sock_connected = false;
got_data = false;
at->sockets[mux] = this; at->sockets[mux] = this;
@@ -114,7 +113,6 @@ private:
uint8_t mux; uint8_t mux;
uint16_t sock_available; uint16_t sock_available;
bool sock_connected; bool sock_connected;
bool got_data;
RxFifo rx; RxFifo rx;
}; };
@@ -381,14 +379,10 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
return false; return false;
} }
//Set Method to Handle Received TCP/IP Data - Retrieve Data by Command //Set Method to Handle Received TCP/IP Data
sendAT(GF("+QINDI=1")); // Mode=2 - Output a notification statement:
if (waitResponse() != 1) { // “+QIRDI: <id>,<sc>,<sid>,<num>,<len>,< tlen>”
return false; sendAT(GF("+QINDI=2"));
}
//Request an IP header for received data ("IPD(data length):")
sendAT(GF("+QIHEAD=1"));
if (waitResponse() != 1) { if (waitResponse() != 1) {
return false; return false;
} }
@@ -638,15 +632,23 @@ protected:
// sid = index of connection - mux // sid = index of connection - mux
// len = maximum length of data to send // len = maximum length of data to send
sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size); sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size);
// sendAT(GF("+QIRD="), mux, ',', (uint16_t)size); // If it replies only OK for the write command, it means there is no
if (waitResponse(GF("+QIRD:")) != 1) { // received data in the buffer of the connection.
return 0; int res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR));
} if (res == 1) {
streamSkipUntil(':'); // skip IP address streamSkipUntil(':'); // skip IP address
streamSkipUntil(','); // skip port streamSkipUntil(','); // skip port
streamSkipUntil(','); // skip connection type (TCP/UDP) streamSkipUntil(','); // skip connection type (TCP/UDP)
int len = stream.readStringUntil('\n').toInt(); // read length // read the real length of the retrieved data
for (int i=0; i<len; i++) { uint16_t len = stream.readStringUntil('\n').toInt();
// It's possible that the real length available is less than expected
// This is quite likely if the buffer is broken into packets - which may
// be different sizes.
// If so, make sure we make sure we re-set the amount of data available.
if (len < size) {
sockets[mux]->sock_available = len;
}
for (uint16_t i=0; i<len; i++) {
TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
sockets[mux]->sock_available--; sockets[mux]->sock_available--;
// ^^ One less character available after moving from modem's FIFO to our FIFO // ^^ One less character available after moving from modem's FIFO to our FIFO
@@ -654,6 +656,10 @@ protected:
waitResponse(); waitResponse();
DBG("### READ:", len, "from", mux); DBG("### READ:", len, "from", mux);
return len; return len;
} else {
sockets[mux]->sock_available = 0;
return 0;
}
} }
bool modemGetConnected(uint8_t mux) { bool modemGetConnected(uint8_t mux) {
@@ -725,14 +731,20 @@ TINY_GSM_MODEM_STREAM_UTILITIES()
index = 6; index = 6;
goto finish; goto finish;
} else if (data.endsWith(GF(GSM_NL "+QIRD:"))) { // TODO: QIRD? or QIRDI? } else if (data.endsWith(GF(GSM_NL "+QIRD:"))) { // TODO: QIRD? or QIRDI?
// +QIRDI: <id>,<sc>,<sid>,<num>,<len>,< tlen>
streamSkipUntil(','); // Skip the context streamSkipUntil(','); // Skip the context
streamSkipUntil(','); // Skip the role streamSkipUntil(','); // Skip the role
int mux = stream.readStringUntil('\n').toInt(); // read the connection id
DBG("### Got Data:", mux); int mux = stream.readStringUntil(',').toInt();
// read the number of packets in the buffer
int num_packets = stream.readStringUntil(',').toInt();
// read the length of the current packet
int len_packet = stream.readStringUntil('\n').toInt();
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) { if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
sockets[mux]->got_data = true; sockets[mux]->sock_available = len_packet*num_packets;
} }
data = ""; data = "";
DBG("### Got Data:", len, "on", mux);
} else if (data.endsWith(GF("CLOSED" GSM_NL))) { } else if (data.endsWith(GF("CLOSED" GSM_NL))) {
int nl = data.lastIndexOf(GSM_NL, data.length()-8); int nl = data.lastIndexOf(GSM_NL, data.length()-8);
int coma = data.indexOf(',', nl+2); int coma = data.indexOf(',', nl+2);

View File

@@ -10,7 +10,7 @@
#define TinyGsmCommon_h #define TinyGsmCommon_h
// The current library version number // The current library version number
#define TINYGSM_VERSION "0.9.14" #define TINYGSM_VERSION "0.9.15"
#if defined(SPARK) || defined(PARTICLE) #if defined(SPARK) || defined(PARTICLE)
#include "Particle.h" #include "Particle.h"