Totally different attempt
This commit is contained in:
@@ -476,13 +476,11 @@ public:
|
|||||||
while (!stream.available()) {}
|
while (!stream.available()) {}
|
||||||
sockets[mux]->rx.put(stream.read());
|
sockets[mux]->rx.put(stream.read());
|
||||||
}
|
}
|
||||||
data = "";
|
|
||||||
return index;
|
return index;
|
||||||
} else if (data.endsWith(GF("+TCPCLOSED:"))) {
|
} else if (data.endsWith(GF("+TCPCLOSED:"))) {
|
||||||
int mux = streamReadUntil(',').toInt();
|
int mux = streamReadUntil(',').toInt();
|
||||||
streamReadUntil('\n');
|
streamReadUntil('\n');
|
||||||
sockets[mux]->sock_connected = false;
|
sockets[mux]->sock_connected = false;
|
||||||
data = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (millis() - startMillis < timeout);
|
} while (millis() - startMillis < timeout);
|
||||||
@@ -492,7 +490,6 @@ public:
|
|||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG("### Unhandled:", data);
|
DBG("### Unhandled:", data);
|
||||||
}
|
}
|
||||||
data = "";
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data.trim();
|
data.trim();
|
||||||
@@ -501,7 +498,6 @@ public:
|
|||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG(GSM_NL, "<<< ", data);
|
DBG(GSM_NL, "<<< ", data);
|
||||||
}
|
}
|
||||||
data = "";
|
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
@@ -521,8 +517,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int modemConnect(const char* host, uint16_t port, uint8_t* mux) {
|
int modemConnect(const char* host, uint16_t port, uint8_t* mux, bool isUDP=false) {
|
||||||
sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
||||||
|
if (isUDP) sendAT(GF("+CIPSTART="), GF("\"UDP"), GF("\",\""), host, GF("\","), port);
|
||||||
|
else sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
||||||
|
|
||||||
if (waitResponse(75000L, GF(GSM_NL "+CIPNUM:")) != 1) {
|
if (waitResponse(75000L, GF(GSM_NL "+CIPNUM:")) != 1) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -370,8 +370,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int modemConnect(const char* host, uint16_t port, uint8_t mux) {
|
int modemConnect(const char* host, uint16_t port, uint8_t mux, bool isUDP=false) {
|
||||||
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port, GF(",120"));
|
if (isUDP) sendAT(GF("+CIPSTART="), mux, ',', GF("\"UDP"), GF("\",\""), host, GF("\","), port, GF(",120"));
|
||||||
|
else sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port, GF(",120"));
|
||||||
int rsp = waitResponse(75000L,
|
int rsp = waitResponse(75000L,
|
||||||
GFP(GSM_OK),
|
GFP(GSM_OK),
|
||||||
GFP(GSM_ERROR),
|
GFP(GSM_ERROR),
|
||||||
|
|||||||
@@ -398,8 +398,8 @@ public:
|
|||||||
/*
|
/*
|
||||||
* Messaging functions
|
* Messaging functions
|
||||||
*/
|
*/
|
||||||
|
bool gprsConnect(const char* apn, const char* user, const char* pwd) {
|
||||||
void sendUSSD() {
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendSMS() {
|
void sendSMS() {
|
||||||
@@ -448,6 +448,9 @@ public:
|
|||||||
String r5s(r5); r5s.trim();
|
String r5s(r5); r5s.trim();
|
||||||
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
|
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
|
||||||
data.reserve(64);
|
data.reserve(64);
|
||||||
|
bool gotData = false;
|
||||||
|
int mux = -1;
|
||||||
|
int len = 0;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
do {
|
do {
|
||||||
@@ -472,24 +475,24 @@ public:
|
|||||||
index = 5;
|
index = 5;
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (data.endsWith(GF("+TCPRECV:"))) {
|
} else if (data.endsWith(GF("+TCPRECV:"))) {
|
||||||
int mux = streamReadUntil(',').toInt();
|
mux = stream.readStringUntil(',').toInt();
|
||||||
int len = streamReadUntil(',').toInt();
|
data += mux;
|
||||||
if (len > sockets[mux]->rx.free()) {
|
data += (',');
|
||||||
DBG("### Buffer overflow: ", len, "->", sockets[mux]->rx.free());
|
len = stream.readStringUntil(',').toInt();
|
||||||
} else {
|
data += len;
|
||||||
DBG("### Got: ", len, "->", sockets[mux]->rx.free());
|
data += (',');
|
||||||
}
|
gotData = true;
|
||||||
while (len--) {
|
index = 6;
|
||||||
while (!stream.available()) {}
|
goto finish;
|
||||||
sockets[mux]->rx.put(stream.read());
|
|
||||||
}
|
|
||||||
data = "";
|
|
||||||
return index;
|
|
||||||
} else if (data.endsWith(GF("+TCPCLOSE:"))) {
|
} else if (data.endsWith(GF("+TCPCLOSE:"))) {
|
||||||
int mux = streamReadUntil(',').toInt();
|
mux = stream.readStringUntil(',').toInt();
|
||||||
streamReadUntil('\n');
|
data += mux;
|
||||||
|
data += (',');
|
||||||
|
String concl = stream.readStringUntil('\n');
|
||||||
|
data += concl;
|
||||||
sockets[mux]->sock_connected = false;
|
sockets[mux]->sock_connected = false;
|
||||||
data = "";
|
index = 7;
|
||||||
|
goto finish;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (millis() - startMillis < timeout);
|
} while (millis() - startMillis < timeout);
|
||||||
@@ -499,7 +502,6 @@ public:
|
|||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG("### Unhandled:", data);
|
DBG("### Unhandled:", data);
|
||||||
}
|
}
|
||||||
data = "";
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data.trim();
|
data.trim();
|
||||||
@@ -508,7 +510,23 @@ public:
|
|||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG(GSM_NL, "<<< ", data);
|
DBG(GSM_NL, "<<< ", data);
|
||||||
}
|
}
|
||||||
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -636,8 +636,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int modemConnect(const char* host, uint16_t port, uint8_t mux) {
|
int modemConnect(const char* host, uint16_t port, uint8_t mux, bool isUDP=false) {
|
||||||
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
if (isUDP) sendAT(GF("+CIPSTART="), mux, ',', GF("\"UDP"), GF("\",\""), host, GF("\","), port);
|
||||||
|
else sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
||||||
int rsp = waitResponse(75000L,
|
int rsp = waitResponse(75000L,
|
||||||
GF("CONNECT OK" GSM_NL),
|
GF("CONNECT OK" GSM_NL),
|
||||||
GF("CONNECT FAIL" GSM_NL),
|
GF("CONNECT FAIL" GSM_NL),
|
||||||
|
|||||||
@@ -312,10 +312,6 @@ public:
|
|||||||
|
|
||||||
commandMode();
|
commandMode();
|
||||||
|
|
||||||
sendAT(GF("AP"), 0); // Put in transparent mode
|
|
||||||
waitResponse();
|
|
||||||
sendAT(GF("IP"), 1); // Put in TCP mode
|
|
||||||
waitResponse();
|
|
||||||
sendAT(GF("EE"), 2); // Set security to WPA2
|
sendAT(GF("EE"), 2); // Set security to WPA2
|
||||||
waitResponse();
|
waitResponse();
|
||||||
|
|
||||||
@@ -348,10 +344,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool gprsConnect(const char* apn, const char* user = "", const char* pw = "") {
|
bool gprsConnect(const char* apn, const char* user = "", const char* pw = "") {
|
||||||
commandMode();
|
commandMode();
|
||||||
sendAT(GF("AP"), 0); // Put in transparent mode
|
|
||||||
waitResponse();
|
|
||||||
sendAT(GF("IP"), 1); // Put in TCP mode
|
|
||||||
waitResponse();
|
|
||||||
sendAT(GF("AN"), apn); // Set the APN
|
sendAT(GF("AN"), apn); // Set the APN
|
||||||
waitResponse();
|
waitResponse();
|
||||||
writeChanges();
|
writeChanges();
|
||||||
@@ -375,8 +367,6 @@ public:
|
|||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) {
|
bool sendSMS(const String& number, const String& text) {
|
||||||
commandMode();
|
commandMode();
|
||||||
sendAT(GF("AP"), 0); // Put in transparent mode
|
|
||||||
waitResponse();
|
|
||||||
sendAT(GF("IP"), 2); // Put in text messaging mode
|
sendAT(GF("IP"), 2); // Put in text messaging mode
|
||||||
waitResponse();
|
waitResponse();
|
||||||
sendAT(GF("PH"), number); // Set the phone number
|
sendAT(GF("PH"), number); // Set the phone number
|
||||||
@@ -475,16 +465,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int modemConnect(const char* host, uint16_t port, uint8_t mux = 1) {
|
int modemConnect(const char* host, uint16_t port, uint8_t mux = 1, bool isUDP=false) {
|
||||||
sendAT(GF("LA"), host);
|
sendAT(GF("LA"), host);
|
||||||
String ipadd; ipadd.reserve(16);
|
String ipadd; ipadd.reserve(16);
|
||||||
ipadd = streamReadUntil('\r');
|
ipadd = streamReadUntil('\r');
|
||||||
IPAddress ip;
|
IPAddress ip;
|
||||||
ip.fromString(ipadd);
|
ip.fromString(ipadd);
|
||||||
return modemConnect(ip, port);
|
return modemConnect(ip, port, mux, isUDP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 1) {
|
int modemConnect(IPAddress ip, uint16_t port, uint8_t mux = 1, bool isUDP=false) {
|
||||||
String host; host.reserve(16);
|
String host; host.reserve(16);
|
||||||
host += ip[0];
|
host += ip[0];
|
||||||
host += ".";
|
host += ".";
|
||||||
@@ -493,6 +483,13 @@ private:
|
|||||||
host += ip[2];
|
host += ip[2];
|
||||||
host += ".";
|
host += ".";
|
||||||
host += ip[3];
|
host += ip[3];
|
||||||
|
if (isUDP) {
|
||||||
|
sendAT(GF("IP"), 0); // Put in UDP mode
|
||||||
|
waitResponse();
|
||||||
|
} else {
|
||||||
|
sendAT(GF("IP"), 1); // Put in TCP mode
|
||||||
|
waitResponse();
|
||||||
|
}
|
||||||
sendAT(GF("DL"), host);
|
sendAT(GF("DL"), host);
|
||||||
waitResponse();
|
waitResponse();
|
||||||
sendAT(GF("DE"), String(port, HEX));
|
sendAT(GF("DE"), String(port, HEX));
|
||||||
|
|||||||
Reference in New Issue
Block a user