Got 7000SSL and 7080 sort of working again
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
@@ -61,16 +61,17 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
|
|||||||
#define TINY_GSM_TEST_WIFI false
|
#define TINY_GSM_TEST_WIFI false
|
||||||
#define TINY_GSM_TEST_TCP true
|
#define TINY_GSM_TEST_TCP true
|
||||||
#define TINY_GSM_TEST_SSL true
|
#define TINY_GSM_TEST_SSL true
|
||||||
// #define TINY_GSM_TEST_CALL true
|
#define TINY_GSM_TEST_CALL false
|
||||||
// #define TINY_GSM_TEST_SMS true
|
#define TINY_GSM_TEST_SMS false
|
||||||
// #define TINY_GSM_TEST_USSD true
|
#define TINY_GSM_TEST_USSD false
|
||||||
#define TINY_GSM_TEST_BATTERY true
|
#define TINY_GSM_TEST_BATTERY true
|
||||||
#define TINY_GSM_TEST_TEMPERATURE true
|
#define TINY_GSM_TEST_TEMPERATURE true
|
||||||
#define TINY_GSM_TEST_GSM_LOCATION true
|
#define TINY_GSM_TEST_GSM_LOCATION true
|
||||||
|
#define TINY_GSM_TEST_NTP true
|
||||||
#define TINY_GSM_TEST_TIME true
|
#define TINY_GSM_TEST_TIME true
|
||||||
#define TINY_GSM_TEST_GPS false
|
#define TINY_GSM_TEST_GPS true
|
||||||
// powerdown modem after tests
|
// disconnect and power down modem after tests
|
||||||
#define TINY_GSM_POWERDOWN true
|
#define TINY_GSM_POWERDOWN false
|
||||||
|
|
||||||
// set GSM PIN, if any
|
// set GSM PIN, if any
|
||||||
#define GSM_PIN ""
|
#define GSM_PIN ""
|
||||||
@@ -183,7 +184,7 @@ void loop() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
DBG("Waiting for network...");
|
DBG("Waiting for network...");
|
||||||
if (!modem.waitForNetwork(600000L)) {
|
if (!modem.waitForNetwork(600000L, true)) {
|
||||||
delay(10000);
|
delay(10000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -230,7 +231,7 @@ void loop() {
|
|||||||
#if TINY_GSM_TEST_TCP && defined TINY_GSM_MODEM_HAS_TCP
|
#if TINY_GSM_TEST_TCP && defined TINY_GSM_MODEM_HAS_TCP
|
||||||
TinyGsmClient client(modem, 0);
|
TinyGsmClient client(modem, 0);
|
||||||
const int port = 80;
|
const int port = 80;
|
||||||
DBG("Connecting to ", server);
|
DBG("Connecting to", server);
|
||||||
if (!client.connect(server, port)) {
|
if (!client.connect(server, port)) {
|
||||||
DBG("... failed");
|
DBG("... failed");
|
||||||
} else {
|
} else {
|
||||||
@@ -248,12 +249,16 @@ void loop() {
|
|||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
start = millis();
|
start = millis();
|
||||||
|
char logo[634];
|
||||||
|
int read_chars = 0;
|
||||||
while (client.connected() && millis() - start < 10000L) {
|
while (client.connected() && millis() - start < 10000L) {
|
||||||
while (client.available()) {
|
while (client.available()) {
|
||||||
SerialMon.write(client.read());
|
logo[read_chars] = client.read();
|
||||||
|
read_chars++;
|
||||||
start = millis();
|
start = millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SerialMon.println(logo);
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -261,7 +266,7 @@ void loop() {
|
|||||||
#if TINY_GSM_TEST_SSL && defined TINY_GSM_MODEM_HAS_SSL
|
#if TINY_GSM_TEST_SSL && defined TINY_GSM_MODEM_HAS_SSL
|
||||||
TinyGsmClientSecure secureClient(modem, 1);
|
TinyGsmClientSecure secureClient(modem, 1);
|
||||||
const int securePort = 443;
|
const int securePort = 443;
|
||||||
DBG("Connecting to ", server);
|
DBG("Connecting securely to", server);
|
||||||
if (!secureClient.connect(server, securePort)) {
|
if (!secureClient.connect(server, securePort)) {
|
||||||
DBG("... failed");
|
DBG("... failed");
|
||||||
} else {
|
} else {
|
||||||
@@ -279,12 +284,16 @@ void loop() {
|
|||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
startS = millis();
|
startS = millis();
|
||||||
while (secureClient.connected() && millis() - startS < 5000L) {
|
char logoS[634];
|
||||||
|
int read_charsS = 0;
|
||||||
|
while (secureClient.connected() && millis() - startS < 10000L) {
|
||||||
while (secureClient.available()) {
|
while (secureClient.available()) {
|
||||||
SerialMon.write(secureClient.read());
|
logoS[read_charsS] = secureClient.read();
|
||||||
|
read_charsS++;
|
||||||
startS = millis();
|
startS = millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SerialMon.println(logoS);
|
||||||
secureClient.stop();
|
secureClient.stop();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -398,6 +407,11 @@ void loop() {
|
|||||||
modem.disableGPS();
|
modem.disableGPS();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if TINY_GSM_TEST_NTP && defined TINY_GSM_MODEM_HAS_NTP
|
||||||
|
DBG("Asking modem to sync with NTP");
|
||||||
|
modem.NTPServerSync("132.163.96.5", 20);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if TINY_GSM_TEST_TIME && defined TINY_GSM_MODEM_HAS_TIME
|
#if TINY_GSM_TEST_TIME && defined TINY_GSM_MODEM_HAS_TIME
|
||||||
int year3 = 0;
|
int year3 = 0;
|
||||||
int month3 = 0;
|
int month3 = 0;
|
||||||
@@ -424,21 +438,6 @@ void loop() {
|
|||||||
DBG("Current Network Time:", time);
|
DBG("Current Network Time:", time);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TINY_GSM_TEST_GPRS
|
|
||||||
modem.gprsDisconnect();
|
|
||||||
delay(5000L);
|
|
||||||
if (!modem.isGprsConnected()) {
|
|
||||||
DBG("GPRS disconnected");
|
|
||||||
} else {
|
|
||||||
DBG("GPRS disconnect: Failed.");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TINY_GSM_TEST_WIFI
|
|
||||||
modem.networkDisconnect();
|
|
||||||
DBG("WiFi disconnected");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TINY_GSM_TEST_BATTERY && defined TINY_GSM_MODEM_HAS_BATTERY
|
#if TINY_GSM_TEST_BATTERY && defined TINY_GSM_MODEM_HAS_BATTERY
|
||||||
uint8_t chargeState = -99;
|
uint8_t chargeState = -99;
|
||||||
int8_t percent = -99;
|
int8_t percent = -99;
|
||||||
@@ -455,6 +454,22 @@ void loop() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TINY_GSM_POWERDOWN
|
#if TINY_GSM_POWERDOWN
|
||||||
|
|
||||||
|
#if TINY_GSM_TEST_GPRS
|
||||||
|
modem.gprsDisconnect();
|
||||||
|
delay(5000L);
|
||||||
|
if (!modem.isGprsConnected()) {
|
||||||
|
DBG("GPRS disconnected");
|
||||||
|
} else {
|
||||||
|
DBG("GPRS disconnect: Failed.");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TINY_GSM_TEST_WIFI
|
||||||
|
modem.networkDisconnect();
|
||||||
|
DBG("WiFi disconnected");
|
||||||
|
#endif
|
||||||
|
|
||||||
// Try to power-off (modem may decide to restart automatically)
|
// Try to power-off (modem may decide to restart automatically)
|
||||||
// To turn off modem completely, please use Reset/Enable pins
|
// To turn off modem completely, please use Reset/Enable pins
|
||||||
modem.poweroff();
|
modem.poweroff();
|
||||||
|
@@ -39,10 +39,10 @@ typedef TinyGsmSim7000SSL::GsmClientSecureSIM7000SSL TinyGsmClientSecure;
|
|||||||
|
|
||||||
#elif defined(TINY_GSM_MODEM_SIM7070) || defined(TINY_GSM_MODEM_SIM7080) || \
|
#elif defined(TINY_GSM_MODEM_SIM7070) || defined(TINY_GSM_MODEM_SIM7080) || \
|
||||||
defined(TINY_GSM_MODEM_SIM7090)
|
defined(TINY_GSM_MODEM_SIM7090)
|
||||||
#include "TinyGsmClientSIM70x0.h"
|
#include "TinyGsmClientSIM7080.h"
|
||||||
typedef TinyGsmSim70x0 TinyGsm;
|
typedef TinyGsmSim7080 TinyGsm;
|
||||||
typedef TinyGsmSim70x0::GsmClientSim70x0 TinyGsmClient;
|
typedef TinyGsmSim7080::GsmClientSim7080 TinyGsmClient;
|
||||||
typedef TinyGsmSim70x0::GsmClientSecureSIM70x0 TinyGsmClientSecure;
|
typedef TinyGsmSim7080::GsmClientSecureSIM7080 TinyGsmClientSecure;
|
||||||
|
|
||||||
#elif defined(TINY_GSM_MODEM_SIM5320) || defined(TINY_GSM_MODEM_SIM5360) || \
|
#elif defined(TINY_GSM_MODEM_SIM5320) || defined(TINY_GSM_MODEM_SIM5360) || \
|
||||||
defined(TINY_GSM_MODEM_SIM5300) || defined(TINY_GSM_MODEM_SIM7100)
|
defined(TINY_GSM_MODEM_SIM5300) || defined(TINY_GSM_MODEM_SIM7100)
|
||||||
|
@@ -163,6 +163,23 @@ class TinyGsmSim7000SSL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void maintainImpl() {
|
||||||
|
// Keep listening for modem URC's and proactively iterate through
|
||||||
|
// sockets asking if any data is avaiable
|
||||||
|
bool check_socks = false;
|
||||||
|
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
||||||
|
GsmClientSim7000SSL* sock = sockets[mux];
|
||||||
|
if (sock && sock->got_data) {
|
||||||
|
sock->got_data = false;
|
||||||
|
check_socks = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// modemGetAvailable checks all socks, so we only want to do it once
|
||||||
|
// modemGetAvailable calls modemGetConnected(), which also checks allf
|
||||||
|
if (check_socks) { modemGetAvailable(0); }
|
||||||
|
while (stream.available()) { waitResponse(15, NULL, NULL); }
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
@@ -228,9 +245,9 @@ class TinyGsmSim7000SSL
|
|||||||
sendAT(GF("+CGATT=1"));
|
sendAT(GF("+CGATT=1"));
|
||||||
if (waitResponse(60000L) != 1) { return false; }
|
if (waitResponse(60000L) != 1) { return false; }
|
||||||
|
|
||||||
// Activate the PDP context
|
// NOTE: **DO NOT** activate the PDP context
|
||||||
sendAT(GF("+CGACT=1,1"));
|
// For who only knows what reason, doing so screws up the rest of the
|
||||||
waitResponse(60000L);
|
// process
|
||||||
|
|
||||||
// Open the definied GPRS bearer context
|
// Open the definied GPRS bearer context
|
||||||
sendAT(GF("+SAPBR=1,1"));
|
sendAT(GF("+SAPBR=1,1"));
|
||||||
@@ -279,8 +296,7 @@ class TinyGsmSim7000SSL
|
|||||||
ntries++;
|
ntries++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return res == 1;
|
return res == 1;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gprsDisconnectImpl() {
|
bool gprsDisconnectImpl() {
|
||||||
@@ -352,12 +368,24 @@ class TinyGsmSim7000SSL
|
|||||||
// 3: QAPI_NET_SSL_PROTOCOL_TLS_1_2
|
// 3: QAPI_NET_SSL_PROTOCOL_TLS_1_2
|
||||||
// 4: QAPI_NET_SSL_PROTOCOL_DTLS_1_0
|
// 4: QAPI_NET_SSL_PROTOCOL_DTLS_1_0
|
||||||
// 5: QAPI_NET_SSL_PROTOCOL_DTLS_1_2
|
// 5: QAPI_NET_SSL_PROTOCOL_DTLS_1_2
|
||||||
|
// NOTE: despite docs using caps, "sslversion" must be in lower case
|
||||||
sendAT(GF("+CSSLCFG=\"sslversion\",0,3")); // TLS 1.2
|
sendAT(GF("+CSSLCFG=\"sslversion\",0,3")); // TLS 1.2
|
||||||
if (waitResponse(5000L) != 1) return false;
|
if (waitResponse(5000L) != 1) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable or disable ssl
|
||||||
|
// AT+CASSLCFG=<cid>,"SSL",<sslFlag>
|
||||||
|
// <cid> Application connection ID (set with AT+CACID above)
|
||||||
|
// <sslFlag> 0: Not support SSL
|
||||||
|
// 1: Support SSL
|
||||||
|
sendAT(GF("+CASSLCFG="), mux, ',', GF("ssl,"), ssl);
|
||||||
|
waitResponse();
|
||||||
|
|
||||||
|
if (ssl) {
|
||||||
// set the PDP context to apply SSL to
|
// set the PDP context to apply SSL to
|
||||||
// AT+CSSLCFG="CTXINDEX",<ctxindex>
|
// AT+CSSLCFG="CTXINDEX",<ctxindex>
|
||||||
// <ctxindex> PDP context identifier
|
// <ctxindex> PDP context identifier
|
||||||
|
// NOTE: despite docs using caps, "ctxindex" must be in lower case
|
||||||
sendAT(GF("+CSSLCFG=\"ctxindex\",0"));
|
sendAT(GF("+CSSLCFG=\"ctxindex\",0"));
|
||||||
if (waitResponse(5000L, GF("+CSSLCFG:")) != 1) return false;
|
if (waitResponse(5000L, GF("+CSSLCFG:")) != 1) return false;
|
||||||
streamSkipUntil('\n'); // read out the certificate information
|
streamSkipUntil('\n'); // read out the certificate information
|
||||||
@@ -372,30 +400,24 @@ class TinyGsmSim7000SSL
|
|||||||
"\"");
|
"\"");
|
||||||
if (waitResponse(5000L) != 1) return false;
|
if (waitResponse(5000L) != 1) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set the protocol
|
||||||
|
// 0: TCP; 1: UDP
|
||||||
|
sendAT(GF("+CASSLCFG="), mux, ',', GF("protocol,0"));
|
||||||
|
waitResponse();
|
||||||
|
|
||||||
|
// set the SSL SNI (server name indication)
|
||||||
|
// NOTE: despite docs using caps, "sni" must be in lower case
|
||||||
|
sendAT(GF("+CSSLCFG=\"sni\","), mux, ',', GF("\""), host, GF("\""));
|
||||||
|
waitResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable or disable ssl
|
|
||||||
// AT+CASSLCFG=<cid>,"SSL",<sslFlag>
|
|
||||||
// <cid> Application connection ID (set with AT+CACID above)
|
|
||||||
// <sslFlag> 0: Not support SSL
|
|
||||||
// 1: Support SSL
|
|
||||||
sendAT(GF("+CASSLCFG="), mux, ',', GF("ssl,"), ssl);
|
|
||||||
waitResponse();
|
|
||||||
|
|
||||||
// set the protocol
|
|
||||||
// 0: TCP; 1: UDP
|
|
||||||
sendAT(GF("+CASSLCFG="), mux, ',', GF("protocol,0"));
|
|
||||||
waitResponse();
|
|
||||||
|
|
||||||
// set the SSL SNI (server name indication)
|
|
||||||
sendAT(GF("+CSSLCFG=\"sni\","), mux, ',', GF("\""), host, GF("\""));
|
|
||||||
waitResponse();
|
|
||||||
|
|
||||||
// actually open the connection
|
// actually open the connection
|
||||||
// AT+CAOPEN=<cid>[,<conn_type>],<server>,<port>
|
// AT+CAOPEN=<cid>[,<conn_type>],<server>,<port>
|
||||||
// <cid> TCP/UDP identifier
|
// <cid> TCP/UDP identifier
|
||||||
// <conn_type> "TCP" or "UDP"
|
// <conn_type> "TCP" or "UDP"
|
||||||
sendAT(GF("+CAOPEN="), mux, GF(",\"TCP\",\""), host, GF("\","), port);
|
// NOTE: the "TCP" can't be included
|
||||||
|
sendAT(GF("+CAOPEN="), mux, GF(",\""), host, GF("\","), port);
|
||||||
if (waitResponse(timeout_ms, GF(GSM_NL "+CAOPEN:")) != 1) { return 0; }
|
if (waitResponse(timeout_ms, GF(GSM_NL "+CAOPEN:")) != 1) { return 0; }
|
||||||
// returns OK/r/n/r/n+CAOPEN: <cid>,<result>
|
// returns OK/r/n/r/n+CAOPEN: <cid>,<result>
|
||||||
// <result> 0: Success
|
// <result> 0: Success
|
||||||
@@ -424,12 +446,15 @@ class TinyGsmSim7000SSL
|
|||||||
}
|
}
|
||||||
|
|
||||||
int16_t modemSend(const void* buff, size_t len, uint8_t mux) {
|
int16_t modemSend(const void* buff, size_t len, uint8_t mux) {
|
||||||
|
// send data on prompt
|
||||||
sendAT(GF("+CASEND="), mux, ',', (uint16_t)len);
|
sendAT(GF("+CASEND="), mux, ',', (uint16_t)len);
|
||||||
if (waitResponse(GF(">")) != 1) { return 0; }
|
if (waitResponse(GF(">")) != 1) { return 0; }
|
||||||
|
|
||||||
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
|
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
|
||||||
stream.flush();
|
stream.flush();
|
||||||
|
|
||||||
|
// after posting data, module responds with:
|
||||||
|
//+CASEND: <cid>,<result>,<sendlen>
|
||||||
if (waitResponse(GF(GSM_NL "+CASEND:")) != 1) { return 0; }
|
if (waitResponse(GF(GSM_NL "+CASEND:")) != 1) { return 0; }
|
||||||
streamSkipUntil(','); // Skip mux
|
streamSkipUntil(','); // Skip mux
|
||||||
if (streamGetIntBefore(',') != 0) { return 0; } // If result != success
|
if (streamGetIntBefore(',') != 0) { return 0; } // If result != success
|
||||||
@@ -437,26 +462,32 @@ class TinyGsmSim7000SSL
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
if (!sockets[mux]) return 0;
|
if (!sockets[mux]) { return 0; }
|
||||||
|
|
||||||
sendAT(GF("+CARECV="), mux, ',', (uint16_t)size);
|
sendAT(GF("+CARECV="), mux, ',', (uint16_t)size);
|
||||||
|
|
||||||
if (waitResponse(GF("+CARECV:")) != 1) {
|
if (waitResponse(GF("+CARECV:")) != 1) { return 0; }
|
||||||
sockets[mux]->sock_available = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
stream.read();
|
// uint8_t ret_mux = stream.parseInt();
|
||||||
if (stream.peek() == '0') {
|
// streamSkipUntil(',');
|
||||||
waitResponse();
|
// const int16_t len_confirmed = streamGetIntBefore('\n');
|
||||||
sockets[mux]->sock_available = 0;
|
// DBG("### READING:", len_confirmed, "from", ret_mux);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int16_t len_confirmed = streamGetIntBefore(',');
|
// if (ret_mux != mux) {
|
||||||
|
// DBG("### Data from wrong mux! Got", ret_mux, "expected", mux);
|
||||||
|
// waitResponse();
|
||||||
|
// sockets[mux]->sock_available = modemGetAvailable(mux);
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// NOTE: manual says the mux number is returned before the number of
|
||||||
|
// characters available, but in tests only the number is returned
|
||||||
|
|
||||||
|
int16_t len_confirmed = stream.parseInt();
|
||||||
|
streamSkipUntil(','); // skip the comma
|
||||||
if (len_confirmed <= 0) {
|
if (len_confirmed <= 0) {
|
||||||
sockets[mux]->sock_available = 0;
|
|
||||||
waitResponse();
|
waitResponse();
|
||||||
|
sockets[mux]->sock_available = modemGetAvailable(mux);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,54 +500,106 @@ class TinyGsmSim7000SSL
|
|||||||
char c = stream.read();
|
char c = stream.read();
|
||||||
sockets[mux]->rx.put(c);
|
sockets[mux]->rx.put(c);
|
||||||
}
|
}
|
||||||
// DBG("### READ:", len_requested, "from", mux);
|
|
||||||
// sockets[mux]->sock_available = modemGetAvailable(mux);
|
|
||||||
auto diff = int64_t(size) - int64_t(len_confirmed);
|
|
||||||
if (diff < 0) diff = 0;
|
|
||||||
sockets[mux]->sock_available = diff;
|
|
||||||
waitResponse();
|
waitResponse();
|
||||||
|
// DBG("### READ:", len_confirmed, "from", mux);
|
||||||
|
// make sure the sock available number is accurate again
|
||||||
|
// the module is **EXTREMELY** testy about being asked to read more from
|
||||||
|
// the buffer than exits; it will freeze until a hard reset or power cycle!
|
||||||
|
sockets[mux]->sock_available = modemGetAvailable(mux);
|
||||||
return len_confirmed;
|
return len_confirmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
// NOTE: This gets how many characters are available on all connections
|
// NOTE: This gets how many characters are available on all connections that
|
||||||
|
// have data. It does not return all the connections, just those with data.
|
||||||
sendAT(GF("+CARECV?"));
|
sendAT(GF("+CARECV?"));
|
||||||
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
||||||
if (waitResponse(3000, GF(GSM_NL "+CARECV: ")) != 1) { break; }
|
// after the last connection, there's an ok, so we catch it right away
|
||||||
size_t result = 0;
|
int res = waitResponse(3000, GF("+CARECV:"), GFP(GSM_OK), GFP(GSM_ERROR));
|
||||||
// if (streamGetIntBefore(',') != muxNo) { // check the mux no
|
// if we get the +CARECV: response, read the mux number and the number of
|
||||||
// DBG("### Warning: misaligned mux numbers!");
|
// characters available
|
||||||
// }
|
if (res == 1) {
|
||||||
streamSkipUntil(','); // skip mux [use muxNo]
|
int ret_mux = streamGetIntBefore(',');
|
||||||
result = streamGetIntBefore('\n');
|
size_t result = streamGetIntBefore('\n');
|
||||||
GsmClientSim7000SSL* sock = sockets[mux];
|
GsmClientSim7000SSL* sock = sockets[ret_mux];
|
||||||
if (sock && muxNo == mux) { sock->sock_available = result; }
|
if (sock) { sock->sock_available = result; }
|
||||||
|
// if the first returned mux isn't 0 (or is higher than expected)
|
||||||
|
// we need to fill in the missing muxes
|
||||||
|
if (ret_mux > muxNo) {
|
||||||
|
for (int extra_mux = muxNo; extra_mux < ret_mux; extra_mux++) {
|
||||||
|
GsmClientSim7000SSL* sock = sockets[extra_mux];
|
||||||
|
if (sock) { sock->sock_available = 0; }
|
||||||
|
}
|
||||||
|
muxNo = ret_mux;
|
||||||
|
}
|
||||||
|
} else if (res == 2) {
|
||||||
|
// if we get an OK, we've reached the last socket with available data
|
||||||
|
// so we set any we haven't gotten to yet to 0
|
||||||
|
for (int extra_mux = muxNo; extra_mux < TINY_GSM_MUX_COUNT;
|
||||||
|
extra_mux++) {
|
||||||
|
GsmClientSim7000SSL* sock = sockets[extra_mux];
|
||||||
|
if (sock) { sock->sock_available = 0; }
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// if we got an error, give up
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Should be a final OK at the end.
|
||||||
|
// If every connection was returned, catch the OK here.
|
||||||
|
// If only a portion were returned, catch it above.
|
||||||
|
if (muxNo == TINY_GSM_MUX_COUNT - 1) { waitResponse(); }
|
||||||
}
|
}
|
||||||
waitResponse(); // Should be an OK at the end
|
modemGetConnected(mux); // check the state of all connections
|
||||||
modemGetConnected(mux);
|
if (!sockets[mux]) { return 0; }
|
||||||
if (!sockets[mux]) return 0;
|
|
||||||
return sockets[mux]->sock_available;
|
return sockets[mux]->sock_available;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool modemGetConnected(uint8_t mux) {
|
bool modemGetConnected(uint8_t mux) {
|
||||||
// NOTE: This gets the state of all connections
|
// NOTE: This gets the state of all connections that have been opened
|
||||||
|
// since the last connection
|
||||||
sendAT(GF("+CASTATE?"));
|
sendAT(GF("+CASTATE?"));
|
||||||
|
|
||||||
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
||||||
if (waitResponse(3000, GF(GSM_NL "+CASTATE: ")) != 1) { break; }
|
// after the last connection, there's an ok, so we catch it right away
|
||||||
uint8_t status = 0;
|
int res = waitResponse(3000, GF("+CASTATE:"), GFP(GSM_OK),
|
||||||
// if (streamGetIntBefore(',') != muxNo) { // check the mux no
|
GFP(GSM_ERROR));
|
||||||
// DBG("### Warning: misaligned mux numbers!");
|
// if we get the +CASTATE: response, read the mux number and the status
|
||||||
// }
|
if (res == 1) {
|
||||||
streamSkipUntil(','); // skip mux [use muxNo]
|
int ret_mux = streamGetIntBefore(',');
|
||||||
status = stream.parseInt(); // Read the status
|
size_t status = streamGetIntBefore('\n');
|
||||||
// 0: Closed by remote server or internal error
|
// 0: Closed by remote server or internal error
|
||||||
// 1: Connected to remote server
|
// 1: Connected to remote server
|
||||||
// 2: Listening (server mode)
|
// 2: Listening (server mode)
|
||||||
GsmClientSim7000SSL* sock = sockets[mux];
|
GsmClientSim7000SSL* sock = sockets[ret_mux];
|
||||||
if (sock && muxNo == mux) { sock->sock_connected = (status == 1); }
|
if (sock) { sock->sock_connected = (status == 1); }
|
||||||
|
// if the first returned mux isn't 0 (or is higher than expected)
|
||||||
|
// we need to fill in the missing muxes
|
||||||
|
if (ret_mux > muxNo) {
|
||||||
|
for (int extra_mux = muxNo; extra_mux < ret_mux; extra_mux++) {
|
||||||
|
GsmClientSim7000SSL* sock = sockets[extra_mux];
|
||||||
|
if (sock) { sock->sock_connected = false; }
|
||||||
|
}
|
||||||
|
muxNo = ret_mux;
|
||||||
|
}
|
||||||
|
} else if (res == 2) {
|
||||||
|
// if we get an OK, we've reached the last socket with available data
|
||||||
|
// so we set any we haven't gotten to yet to 0
|
||||||
|
for (int extra_mux = muxNo; extra_mux < TINY_GSM_MUX_COUNT;
|
||||||
|
extra_mux++) {
|
||||||
|
GsmClientSim7000SSL* sock = sockets[extra_mux];
|
||||||
|
if (sock) { sock->sock_connected = false; }
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// if we got an error, give up
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Should be a final OK at the end.
|
||||||
|
// If every connection was returned, catch the OK here.
|
||||||
|
// If only a portion were returned, catch it above.
|
||||||
|
if (muxNo == TINY_GSM_MUX_COUNT - 1) { waitResponse(); }
|
||||||
}
|
}
|
||||||
waitResponse(); // Should be an OK at the end
|
|
||||||
return sockets[mux]->sock_connected;
|
return sockets[mux]->sock_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -571,21 +654,23 @@ class TinyGsmSim7000SSL
|
|||||||
} else if (r5 && data.endsWith(r5)) {
|
} else if (r5 && data.endsWith(r5)) {
|
||||||
index = 5;
|
index = 5;
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (data.endsWith(GF(GSM_NL "+CARECV:"))) {
|
} else if (data.endsWith(GF("+CARECV:"))) {
|
||||||
int8_t mux = streamGetIntBefore(',');
|
int8_t mux = streamGetIntBefore(',');
|
||||||
|
int16_t len = streamGetIntBefore('\n');
|
||||||
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]->got_data = true;
|
||||||
|
if (len >= 0 && len <= 1024) { sockets[mux]->sock_available = len; }
|
||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
DBG("### Got Data:", mux);
|
DBG("### Got Data:", len, "on", mux);
|
||||||
} else if (data.endsWith(GF(GSM_NL "+CADATAIND:"))) {
|
} else if (data.endsWith(GF("+CADATAIND:"))) {
|
||||||
int8_t mux = streamGetIntBefore('\n');
|
int8_t mux = streamGetIntBefore('\n');
|
||||||
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]->got_data = true;
|
||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
DBG("### Got Data:", mux);
|
DBG("### Got Data:", mux);
|
||||||
} else if (data.endsWith(GF(GSM_NL "+CASTATE:"))) {
|
} else if (data.endsWith(GF("+CASTATE:"))) {
|
||||||
int8_t mux = streamGetIntBefore(',');
|
int8_t mux = streamGetIntBefore(',');
|
||||||
int8_t state = streamGetIntBefore('\n');
|
int8_t state = streamGetIntBefore('\n');
|
||||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||||
@@ -625,6 +710,7 @@ class TinyGsmSim7000SSL
|
|||||||
data = "";
|
data = "";
|
||||||
DBG("### Unexpected module reset!");
|
DBG("### Unexpected module reset!");
|
||||||
init();
|
init();
|
||||||
|
data = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (millis() - startMillis < timeout_ms);
|
} while (millis() - startMillis < timeout_ms);
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* @file TinyGsmClientSim70x0.h
|
* @file TinyGsmClientSim7080.h
|
||||||
* @author Volodymyr Shymanskyy
|
* @author Volodymyr Shymanskyy
|
||||||
* @license LGPL-3.0
|
* @license LGPL-3.0
|
||||||
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
|
* @copyright Copyright (c) 2016 Volodymyr Shymanskyy
|
||||||
* @date Nov 2016
|
* @date Nov 2016
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRC_TINYGSMCLIENTSIM70X0_H_
|
#ifndef SRC_TINYGSMCLIENTSIM7080_H_
|
||||||
#define SRC_TINYGSMCLIENTSIM70X0_H_
|
#define SRC_TINYGSMCLIENTSIM7080_H_
|
||||||
|
|
||||||
// #define TINY_GSM_DEBUG Serial
|
// #define TINY_GSM_DEBUG Serial
|
||||||
// #define TINY_GSM_USE_HEX
|
// #define TINY_GSM_USE_HEX
|
||||||
@@ -19,28 +19,28 @@
|
|||||||
#include "TinyGsmTCP.tpp"
|
#include "TinyGsmTCP.tpp"
|
||||||
#include "TinyGsmSSL.tpp"
|
#include "TinyGsmSSL.tpp"
|
||||||
|
|
||||||
class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
|
||||||
public TinyGsmTCP<TinyGsmSim70x0, TINY_GSM_MUX_COUNT>,
|
public TinyGsmTCP<TinyGsmSim7080, TINY_GSM_MUX_COUNT>,
|
||||||
public TinyGsmSSL<TinyGsmSim70x0> {
|
public TinyGsmSSL<TinyGsmSim7080> {
|
||||||
friend class TinyGsmSim70xx<TinyGsmSim70x0>;
|
friend class TinyGsmSim70xx<TinyGsmSim7080>;
|
||||||
friend class TinyGsmTCP<TinyGsmSim70x0, TINY_GSM_MUX_COUNT>;
|
friend class TinyGsmTCP<TinyGsmSim7080, TINY_GSM_MUX_COUNT>;
|
||||||
friend class TinyGsmSSL<TinyGsmSim70x0>;
|
friend class TinyGsmSSL<TinyGsmSim7080>;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Inner Client
|
* Inner Client
|
||||||
*/
|
*/
|
||||||
public:
|
public:
|
||||||
class GsmClientSim70x0 : public GsmClient {
|
class GsmClientSim7080 : public GsmClient {
|
||||||
friend class TinyGsmSim70x0;
|
friend class TinyGsmSim7080;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GsmClientSim70x0() {}
|
GsmClientSim7080() {}
|
||||||
|
|
||||||
explicit GsmClientSim70x0(TinyGsmSim70x0& modem, uint8_t mux = 0) {
|
explicit GsmClientSim7080(TinyGsmSim7080& modem, uint8_t mux = 0) {
|
||||||
init(&modem, mux);
|
init(&modem, mux);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init(TinyGsmSim70x0* modem, uint8_t mux = 0) {
|
bool init(TinyGsmSim7080* modem, uint8_t mux = 0) {
|
||||||
this->at = modem;
|
this->at = modem;
|
||||||
sock_available = 0;
|
sock_available = 0;
|
||||||
prev_check = 0;
|
prev_check = 0;
|
||||||
@@ -88,12 +88,12 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
* Inner Secure Client
|
* Inner Secure Client
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class GsmClientSecureSIM70x0 : public GsmClientSim70x0 {
|
class GsmClientSecureSIM7080 : public GsmClientSim7080 {
|
||||||
public:
|
public:
|
||||||
GsmClientSecureSIM70x0() {}
|
GsmClientSecureSIM7080() {}
|
||||||
|
|
||||||
GsmClientSecureSIM70x0(TinyGsmSim70x0& modem, uint8_t mux = 0)
|
GsmClientSecureSIM7080(TinyGsmSim7080& modem, uint8_t mux = 0)
|
||||||
: GsmClientSim70x0(modem, mux) {}
|
: GsmClientSim7080(modem, mux) {}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool setCertificate(const String& certificateName) {
|
bool setCertificate(const String& certificateName) {
|
||||||
@@ -114,8 +114,8 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public:
|
public:
|
||||||
explicit TinyGsmSim70x0(Stream& stream)
|
explicit TinyGsmSim7080(Stream& stream)
|
||||||
: TinyGsmSim70xx<TinyGsmSim70x0>(stream),
|
: TinyGsmSim70xx<TinyGsmSim7080>(stream),
|
||||||
certificates() {
|
certificates() {
|
||||||
memset(sockets, 0, sizeof(sockets));
|
memset(sockets, 0, sizeof(sockets));
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
protected:
|
protected:
|
||||||
bool initImpl(const char* pin = NULL) {
|
bool initImpl(const char* pin = NULL) {
|
||||||
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
|
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
|
||||||
DBG(GF("### TinyGSM Compiled Module: TinyGsmClientSIM70x0"));
|
DBG(GF("### TinyGSM Compiled Module: TinyGsmClientSIM7080"));
|
||||||
|
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
|
|
||||||
@@ -162,6 +162,23 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void maintainImpl() {
|
||||||
|
// Keep listening for modem URC's and proactively iterate through
|
||||||
|
// sockets asking if any data is avaiable
|
||||||
|
bool check_socks = false;
|
||||||
|
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
||||||
|
GsmClientSim7080* sock = sockets[mux];
|
||||||
|
if (sock && sock->got_data) {
|
||||||
|
sock->got_data = false;
|
||||||
|
check_socks = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// modemGetAvailable checks all socks, so we only want to do it once
|
||||||
|
// modemGetAvailable calls modemGetConnected(), which also checks allf
|
||||||
|
if (check_socks) { modemGetAvailable(0); }
|
||||||
|
while (stream.available()) { waitResponse(15, NULL, NULL); }
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
@@ -199,26 +216,6 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
const char* pwd = NULL) {
|
const char* pwd = NULL) {
|
||||||
gprsDisconnect();
|
gprsDisconnect();
|
||||||
|
|
||||||
// Bearer settings for applications based on IP
|
|
||||||
// Set the connection type to GPRS
|
|
||||||
sendAT(GF("+SAPBR=3,1,\"Contype\",\"GPRS\""));
|
|
||||||
waitResponse();
|
|
||||||
|
|
||||||
// Set the APN
|
|
||||||
sendAT(GF("+SAPBR=3,1,\"APN\",\""), apn, '"');
|
|
||||||
waitResponse();
|
|
||||||
|
|
||||||
// Set the user name
|
|
||||||
if (user && strlen(user) > 0) {
|
|
||||||
sendAT(GF("+SAPBR=3,1,\"USER\",\""), user, '"');
|
|
||||||
waitResponse();
|
|
||||||
}
|
|
||||||
// Set the password
|
|
||||||
if (pwd && strlen(pwd) > 0) {
|
|
||||||
sendAT(GF("+SAPBR=3,1,\"PWD\",\""), pwd, '"');
|
|
||||||
waitResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define the PDP context
|
// Define the PDP context
|
||||||
sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"');
|
sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
@@ -227,21 +224,20 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
sendAT(GF("+CGATT=1"));
|
sendAT(GF("+CGATT=1"));
|
||||||
if (waitResponse(60000L) != 1) { return false; }
|
if (waitResponse(60000L) != 1) { return false; }
|
||||||
|
|
||||||
// Activate the PDP context
|
// NOTE: **DO NOT** activate the PDP context
|
||||||
sendAT(GF("+CGACT=1,1"));
|
// For who only knows what reason, doing so screws up the rest of the
|
||||||
waitResponse(60000L);
|
// process
|
||||||
|
|
||||||
// Open the definied GPRS bearer context
|
// Check the APN returned by the server
|
||||||
sendAT(GF("+SAPBR=1,1"));
|
// not sure why, but the connection is more consistent with this
|
||||||
waitResponse(85000L);
|
sendAT(GF("+CGNAPN"));
|
||||||
// Query the GPRS bearer context status
|
waitResponse();
|
||||||
sendAT(GF("+SAPBR=2,1"));
|
|
||||||
if (waitResponse(30000L) != 1) { return false; }
|
|
||||||
|
|
||||||
// Bearer settings for applications based on IP
|
// Bearer settings for applications based on IP
|
||||||
// Set the user name and password
|
// Set the user name and password
|
||||||
// AT+CNCFG=<pdpidx>,<ip_type>,[<APN>,[<usename>,<password>,[<authentication>]]]
|
// AT+CNCFG=<pdpidx>,<ip_type>,[<APN>,[<usename>,<password>,[<authentication>]]]
|
||||||
// <pdpidx> PDP Context Identifier (1 is setup above)
|
// <pdpidx> PDP Context Identifier - for reasons not understood by me,
|
||||||
|
// use PDP context identifier of 0 for what we defined as 1 above
|
||||||
// <ip_type> 0: Dual PDN Stack
|
// <ip_type> 0: Dual PDN Stack
|
||||||
// 1: Internet Protocol Version 4
|
// 1: Internet Protocol Version 4
|
||||||
// 2: Internet Protocol Version 6
|
// 2: Internet Protocol Version 6
|
||||||
@@ -250,44 +246,42 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
// 2: CHAP
|
// 2: CHAP
|
||||||
// 3: PAP or CHAP
|
// 3: PAP or CHAP
|
||||||
if (pwd && strlen(pwd) > 0 && user && strlen(user) > 0) {
|
if (pwd && strlen(pwd) > 0 && user && strlen(user) > 0) {
|
||||||
sendAT(GF("+CNCFG=1,1,\""), apn, "\",\"", "\",\"", user, pwd, '"');
|
sendAT(GF("+CNCFG=0,1,\""), apn, "\",\"", "\",\"", user, pwd, '"');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
} else if (user && strlen(user) > 0) {
|
} else if (user && strlen(user) > 0) {
|
||||||
// Set the user name only
|
// Set the user name only
|
||||||
sendAT(GF("+CNCFG=1,1,\""), apn, "\",\"", user, '"');
|
sendAT(GF("+CNCFG=0,1,\""), apn, "\",\"", user, '"');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
} else {
|
} else {
|
||||||
// Set the APN only
|
// Set the APN only
|
||||||
sendAT(GF("+CNCFG=1,1,\""), apn, '"');
|
sendAT(GF("+CNCFG=0,1,\""), apn, '"');
|
||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activate application network connection
|
// Activate application network connection
|
||||||
// This is for most other supported applications outside of the
|
|
||||||
// TCP application toolkit (ie, SSL)
|
|
||||||
// AT+CNACT=<pdpidx>,<action>
|
// AT+CNACT=<pdpidx>,<action>
|
||||||
// <pdpidx> PDP Context Identifier (1 is setup above)
|
// <pdpidx> PDP Context Identifier - for reasons not understood by me,
|
||||||
|
// use PDP context identifier of 0 for what we defined as 1 above
|
||||||
// <action> 0: Deactive
|
// <action> 0: Deactive
|
||||||
// 1: Active
|
// 1: Active
|
||||||
// 2: Auto Active
|
// 2: Auto Active
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int ntries = 0;
|
int ntries = 0;
|
||||||
while (res != 1 && ntries < 5) {
|
while (res != 1 && ntries < 5) {
|
||||||
sendAT(GF("+CNACT=1,1,\""), apn, GF("\""));
|
sendAT(GF("+CNACT=0,1"));
|
||||||
res = waitResponse(60000L, GF(GSM_NL "+APP PDP: ACTIVE"),
|
res = waitResponse(60000L, GF(GSM_NL "+APP PDP: 0,ACTIVE"),
|
||||||
GF(GSM_NL "+APP PDP: DEACTIVE"));
|
GF(GSM_NL "+APP PDP: 0,DEACTIVE"));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
ntries++;
|
ntries++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return res == 1;
|
return res == 1;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gprsDisconnectImpl() {
|
bool gprsDisconnectImpl() {
|
||||||
// Shut down the general application TCP/IP connection
|
// Shut down the general application TCP/IP connection
|
||||||
// CNACT will close *all* open application connections
|
// CNACT will close *all* open application connections
|
||||||
sendAT(GF("+CNACT=1,0"));
|
sendAT(GF("+CNACT=0,0"));
|
||||||
if (waitResponse(60000L) != 1) { return false; }
|
if (waitResponse(60000L) != 1) { return false; }
|
||||||
|
|
||||||
sendAT(GF("+CGATT=0")); // Deactivate the bearer context
|
sendAT(GF("+CGATT=0")); // Deactivate the bearer context
|
||||||
@@ -353,13 +347,26 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
// 3: QAPI_NET_SSL_PROTOCOL_TLS_1_2
|
// 3: QAPI_NET_SSL_PROTOCOL_TLS_1_2
|
||||||
// 4: QAPI_NET_SSL_PROTOCOL_DTLS_1_0
|
// 4: QAPI_NET_SSL_PROTOCOL_DTLS_1_0
|
||||||
// 5: QAPI_NET_SSL_PROTOCOL_DTLS_1_2
|
// 5: QAPI_NET_SSL_PROTOCOL_DTLS_1_2
|
||||||
sendAT(GF("+CSSLCFG=\"SSLVERSION\",0,3")); // TLS 1.2
|
// NOTE: despite docs using caps, "sslversion" must be in lower case
|
||||||
|
sendAT(GF("+CSSLCFG=\"sslversion\",0,3")); // TLS 1.2
|
||||||
if (waitResponse(5000L) != 1) return false;
|
if (waitResponse(5000L) != 1) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable or disable ssl
|
||||||
|
// AT+CASSLCFG=<cid>,"SSL",<sslFlag>
|
||||||
|
// <cid> Application connection ID (set with AT+CACID above)
|
||||||
|
// <sslFlag> 0: Not support SSL
|
||||||
|
// 1: Support SSL
|
||||||
|
sendAT(GF("+CASSLCFG="), mux, ',', GF("SSL,"), ssl);
|
||||||
|
waitResponse();
|
||||||
|
|
||||||
|
if (ssl) {
|
||||||
// set the PDP context to apply SSL to
|
// set the PDP context to apply SSL to
|
||||||
// AT+CSSLCFG="CTXINDEX",<ctxindex>
|
// AT+CSSLCFG="CTXINDEX",<ctxindex>
|
||||||
// <ctxindex> PDP context identifier
|
// <ctxindex> PDP context identifier
|
||||||
sendAT(GF("+CSSLCFG=\"CTXINDEX\",0"));
|
// NOTE: despite docs using "CRINDEX" in all caps, the module only
|
||||||
|
// accepts the command "ctxindex" and it must be in lower case
|
||||||
|
sendAT(GF("+CSSLCFG=\"ctxindex\",0"));
|
||||||
if (waitResponse(5000L, GF("+CSSLCFG:")) != 1) return false;
|
if (waitResponse(5000L, GF("+CSSLCFG:")) != 1) return false;
|
||||||
streamSkipUntil('\n'); // read out the certificate information
|
streamSkipUntil('\n'); // read out the certificate information
|
||||||
waitResponse();
|
waitResponse();
|
||||||
@@ -373,20 +380,13 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
"\"");
|
"\"");
|
||||||
if (waitResponse(5000L) != 1) return false;
|
if (waitResponse(5000L) != 1) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set the SSL SNI (server name indication)
|
||||||
|
// NOTE: despite docs using caps, "sni" must be in lower case
|
||||||
|
sendAT(GF("+CSSLCFG=\"sni\","), mux, ',', GF("\""), host, GF("\""));
|
||||||
|
waitResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable or disable ssl
|
|
||||||
// AT+CASSLCFG=<cid>,"SSL",<sslFlag>
|
|
||||||
// <cid> Application connection ID (set with AT+CACID above)
|
|
||||||
// <sslFlag> 0: Not support SSL
|
|
||||||
// 1: Support SSL
|
|
||||||
sendAT(GF("+CASSLCFG="), mux, ',', GF("SSL,"), ssl);
|
|
||||||
waitResponse();
|
|
||||||
|
|
||||||
// set the SSL SNI (server name indication)
|
|
||||||
sendAT(GF("+CSSLCFG=\"SNI\","), mux, ',', GF("\""), host, GF("\""));
|
|
||||||
waitResponse();
|
|
||||||
|
|
||||||
// actually open the connection
|
// actually open the connection
|
||||||
// AT+CAOPEN=<cid>,<pdp_index>,<conn_type>,<server>,<port>[,<recv_mode>]
|
// AT+CAOPEN=<cid>,<pdp_index>,<conn_type>,<server>,<port>[,<recv_mode>]
|
||||||
// <cid> TCP/UDP identifier
|
// <cid> TCP/UDP identifier
|
||||||
@@ -398,8 +398,8 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
// URC:
|
// URC:
|
||||||
// +CAURC:
|
// +CAURC:
|
||||||
// "recv",<id>,<length>,<remoteIP>,<remote_port><CR><LF><data>
|
// "recv",<id>,<length>,<remoteIP>,<remote_port><CR><LF><data>
|
||||||
sendAT(GF("+CAOPEN="), mux, GF(",0,\"TCP\",\""), host, GF("\","), port, ',',
|
// NOTE: including the <recv_mode> fails
|
||||||
0);
|
sendAT(GF("+CAOPEN="), mux, GF(",0,\"TCP\",\""), host, GF("\","), port);
|
||||||
if (waitResponse(timeout_ms, GF(GSM_NL "+CAOPEN:")) != 1) { return 0; }
|
if (waitResponse(timeout_ms, GF(GSM_NL "+CAOPEN:")) != 1) { return 0; }
|
||||||
// returns OK/r/n/r/n+CAOPEN: <cid>,<result>
|
// returns OK/r/n/r/n+CAOPEN: <cid>,<result>
|
||||||
// <result> 0: Success
|
// <result> 0: Success
|
||||||
@@ -428,39 +428,46 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int16_t modemSend(const void* buff, size_t len, uint8_t mux) {
|
int16_t modemSend(const void* buff, size_t len, uint8_t mux) {
|
||||||
|
// send data on prompt
|
||||||
sendAT(GF("+CASEND="), mux, ',', (uint16_t)len);
|
sendAT(GF("+CASEND="), mux, ',', (uint16_t)len);
|
||||||
if (waitResponse(GF(">")) != 1) { return 0; }
|
if (waitResponse(GF(">")) != 1) { return 0; }
|
||||||
|
|
||||||
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
|
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
|
||||||
stream.flush();
|
stream.flush();
|
||||||
|
|
||||||
if (waitResponse(GF(GSM_NL "+CASEND:")) != 1) { return 0; }
|
// OK after posting data
|
||||||
streamSkipUntil(','); // Skip mux
|
if (waitResponse() != 1) { return 0; }
|
||||||
if (streamGetIntBefore(',') != 0) { return 0; } // If result != success
|
|
||||||
return streamGetIntBefore('\n');
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
if (!sockets[mux]) return 0;
|
if (!sockets[mux]) { return 0; }
|
||||||
|
|
||||||
sendAT(GF("+CARECV="), mux, ',', (uint16_t)size);
|
sendAT(GF("+CARECV="), mux, ',', (uint16_t)size);
|
||||||
|
|
||||||
if (waitResponse(GF("+CARECV:")) != 1) {
|
if (waitResponse(GF("+CARECV:")) != 1) { return 0; }
|
||||||
sockets[mux]->sock_available = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
stream.read();
|
// uint8_t ret_mux = stream.parseInt();
|
||||||
if (stream.peek() == '0') {
|
// streamSkipUntil(',');
|
||||||
waitResponse();
|
// const int16_t len_confirmed = streamGetIntBefore('\n');
|
||||||
sockets[mux]->sock_available = 0;
|
// DBG("### READING:", len_confirmed, "from", ret_mux);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int16_t len_confirmed = streamGetIntBefore(',');
|
// if (ret_mux != mux) {
|
||||||
|
// DBG("### Data from wrong mux! Got", ret_mux, "expected", mux);
|
||||||
|
// waitResponse();
|
||||||
|
// sockets[mux]->sock_available = modemGetAvailable(mux);
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// NOTE: manual says the mux number is returned before the number of
|
||||||
|
// characters available, but in tests only the number is returned
|
||||||
|
|
||||||
|
int16_t len_confirmed = stream.parseInt();
|
||||||
|
streamSkipUntil(','); // skip the comma
|
||||||
if (len_confirmed <= 0) {
|
if (len_confirmed <= 0) {
|
||||||
sockets[mux]->sock_available = 0;
|
|
||||||
waitResponse();
|
waitResponse();
|
||||||
|
sockets[mux]->sock_available = modemGetAvailable(mux);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,54 +480,103 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
char c = stream.read();
|
char c = stream.read();
|
||||||
sockets[mux]->rx.put(c);
|
sockets[mux]->rx.put(c);
|
||||||
}
|
}
|
||||||
// DBG("### READ:", len_requested, "from", mux);
|
|
||||||
// sockets[mux]->sock_available = modemGetAvailable(mux);
|
|
||||||
auto diff = int64_t(size) - int64_t(len_confirmed);
|
|
||||||
if (diff < 0) diff = 0;
|
|
||||||
sockets[mux]->sock_available = diff;
|
|
||||||
waitResponse();
|
waitResponse();
|
||||||
|
// make sure the sock available number is accurate again
|
||||||
|
sockets[mux]->sock_available = modemGetAvailable(mux);
|
||||||
return len_confirmed;
|
return len_confirmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
// NOTE: This gets how many characters are available on all connections
|
// NOTE: This gets how many characters are available on all connections that
|
||||||
|
// have data. It does not return all the connections, just those with data.
|
||||||
sendAT(GF("+CARECV?"));
|
sendAT(GF("+CARECV?"));
|
||||||
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
||||||
if (waitResponse(3000, GF(GSM_NL "+CARECV: ")) != 1) { break; }
|
// after the last connection, there's an ok, so we catch it right away
|
||||||
size_t result = 0;
|
int res = waitResponse(3000, GF("+CARECV:"), GFP(GSM_OK), GFP(GSM_ERROR));
|
||||||
// if (streamGetIntBefore(',') != muxNo) { // check the mux no
|
// if we get the +CARECV: response, read the mux number and the number of
|
||||||
// DBG("### Warning: misaligned mux numbers!");
|
// characters available
|
||||||
// }
|
if (res == 1) {
|
||||||
streamSkipUntil(','); // skip mux [use muxNo]
|
int ret_mux = streamGetIntBefore(',');
|
||||||
result = streamGetIntBefore('\n');
|
size_t result = streamGetIntBefore('\n');
|
||||||
GsmClientSim70x0* sock = sockets[mux];
|
GsmClientSim7080* sock = sockets[ret_mux];
|
||||||
if (sock && muxNo == mux) { sock->sock_available = result; }
|
if (sock) { sock->sock_available = result; }
|
||||||
|
// if the first returned mux isn't 0 (or is higher than expected)
|
||||||
|
// we need to fill in the missing muxes
|
||||||
|
if (ret_mux > muxNo) {
|
||||||
|
for (int extra_mux = muxNo; extra_mux < ret_mux; extra_mux++) {
|
||||||
|
GsmClientSim7080* sock = sockets[extra_mux];
|
||||||
|
if (sock) { sock->sock_available = 0; }
|
||||||
|
}
|
||||||
|
muxNo = ret_mux;
|
||||||
|
}
|
||||||
|
} else if (res == 2) {
|
||||||
|
// if we get an OK, we've reached the last socket with available data
|
||||||
|
// so we set any we haven't gotten to yet to 0
|
||||||
|
for (int extra_mux = muxNo; extra_mux < TINY_GSM_MUX_COUNT;
|
||||||
|
extra_mux++) {
|
||||||
|
GsmClientSim7080* sock = sockets[extra_mux];
|
||||||
|
if (sock) { sock->sock_available = 0; }
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// if we got an error, give up
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Should be a final OK at the end.
|
||||||
|
// If every connection was returned, catch the OK here.
|
||||||
|
// If only a portion were returned, catch it above.
|
||||||
|
if (muxNo == TINY_GSM_MUX_COUNT - 1) { waitResponse(); }
|
||||||
}
|
}
|
||||||
waitResponse(); // Should be an OK at the end
|
modemGetConnected(mux); // check the state of all connections
|
||||||
modemGetConnected(mux);
|
if (!sockets[mux]) { return 0; }
|
||||||
if (!sockets[mux]) return 0;
|
|
||||||
return sockets[mux]->sock_available;
|
return sockets[mux]->sock_available;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool modemGetConnected(uint8_t mux) {
|
bool modemGetConnected(uint8_t mux) {
|
||||||
// NOTE: This gets the state of all connections
|
// NOTE: This gets the state of all connections that have been opened
|
||||||
|
// since the last connection
|
||||||
sendAT(GF("+CASTATE?"));
|
sendAT(GF("+CASTATE?"));
|
||||||
|
|
||||||
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
|
||||||
if (waitResponse(3000, GF(GSM_NL "+CASTATE: ")) != 1) { break; }
|
// after the last connection, there's an ok, so we catch it right away
|
||||||
uint8_t status = 0;
|
int res = waitResponse(3000, GF("+CASTATE:"), GFP(GSM_OK),
|
||||||
// if (streamGetIntBefore(',') != muxNo) { // check the mux no
|
GFP(GSM_ERROR));
|
||||||
// DBG("### Warning: misaligned mux numbers!");
|
// if we get the +CASTATE: response, read the mux number and the status
|
||||||
// }
|
if (res == 1) {
|
||||||
streamSkipUntil(','); // skip mux [use muxNo]
|
int ret_mux = streamGetIntBefore(',');
|
||||||
status = stream.parseInt(); // Read the status
|
size_t status = streamGetIntBefore('\n');
|
||||||
// 0: Closed by remote server or internal error
|
// 0: Closed by remote server or internal error
|
||||||
// 1: Connected to remote server
|
// 1: Connected to remote server
|
||||||
// 2: Listening (server mode)
|
// 2: Listening (server mode)
|
||||||
GsmClientSim70x0* sock = sockets[mux];
|
GsmClientSim7080* sock = sockets[ret_mux];
|
||||||
if (sock && muxNo == mux) { sock->sock_connected = (status == 1); }
|
if (sock) { sock->sock_connected = (status == 1); }
|
||||||
|
// if the first returned mux isn't 0 (or is higher than expected)
|
||||||
|
// we need to fill in the missing muxes
|
||||||
|
if (ret_mux > muxNo) {
|
||||||
|
for (int extra_mux = muxNo; extra_mux < ret_mux; extra_mux++) {
|
||||||
|
GsmClientSim7080* sock = sockets[extra_mux];
|
||||||
|
if (sock) { sock->sock_connected = false; }
|
||||||
|
}
|
||||||
|
muxNo = ret_mux;
|
||||||
|
}
|
||||||
|
} else if (res == 2) {
|
||||||
|
// if we get an OK, we've reached the last socket with available data
|
||||||
|
// so we set any we haven't gotten to yet to 0
|
||||||
|
for (int extra_mux = muxNo; extra_mux < TINY_GSM_MUX_COUNT;
|
||||||
|
extra_mux++) {
|
||||||
|
GsmClientSim7080* sock = sockets[extra_mux];
|
||||||
|
if (sock) { sock->sock_connected = false; }
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// if we got an error, give up
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Should be a final OK at the end.
|
||||||
|
// If every connection was returned, catch the OK here.
|
||||||
|
// If only a portion were returned, catch it above.
|
||||||
|
if (muxNo == TINY_GSM_MUX_COUNT - 1) { waitResponse(); }
|
||||||
}
|
}
|
||||||
waitResponse(); // Should be an OK at the end
|
|
||||||
return sockets[mux]->sock_connected;
|
return sockets[mux]->sock_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -575,21 +631,23 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
} else if (r5 && data.endsWith(r5)) {
|
} else if (r5 && data.endsWith(r5)) {
|
||||||
index = 5;
|
index = 5;
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (data.endsWith(GF(GSM_NL "+CARECV:"))) {
|
} else if (data.endsWith(GF("+CARECV:"))) {
|
||||||
int8_t mux = streamGetIntBefore(',');
|
int8_t mux = streamGetIntBefore(',');
|
||||||
|
int16_t len = streamGetIntBefore('\n');
|
||||||
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]->got_data = true;
|
||||||
|
if (len >= 0 && len <= 1024) { sockets[mux]->sock_available = len; }
|
||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
DBG("### Got Data:", mux);
|
DBG("### Got Data:", len, "on", mux);
|
||||||
} else if (data.endsWith(GF(GSM_NL "+CADATAIND:"))) {
|
} else if (data.endsWith(GF("+CADATAIND:"))) {
|
||||||
int8_t mux = streamGetIntBefore('\n');
|
int8_t mux = streamGetIntBefore('\n');
|
||||||
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]->got_data = true;
|
||||||
}
|
}
|
||||||
data = "";
|
data = "";
|
||||||
DBG("### Got Data:", mux);
|
DBG("### Got Data:", mux);
|
||||||
} else if (data.endsWith(GF(GSM_NL "+CASTATE:"))) {
|
} else if (data.endsWith(GF("+CASTATE:"))) {
|
||||||
int8_t mux = streamGetIntBefore(',');
|
int8_t mux = streamGetIntBefore(',');
|
||||||
int8_t state = streamGetIntBefore('\n');
|
int8_t state = streamGetIntBefore('\n');
|
||||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||||
@@ -629,6 +687,7 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
data = "";
|
data = "";
|
||||||
DBG("### Unexpected module reset!");
|
DBG("### Unexpected module reset!");
|
||||||
init();
|
init();
|
||||||
|
data = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (millis() - startMillis < timeout_ms);
|
} while (millis() - startMillis < timeout_ms);
|
||||||
@@ -669,8 +728,8 @@ class TinyGsmSim70x0 : public TinyGsmSim70xx<TinyGsmSim70x0>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GsmClientSim70x0* sockets[TINY_GSM_MUX_COUNT];
|
GsmClientSim7080* sockets[TINY_GSM_MUX_COUNT];
|
||||||
String certificates[TINY_GSM_MUX_COUNT];
|
String certificates[TINY_GSM_MUX_COUNT];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SRC_TINYGSMCLIENTSIM70X0_H_
|
#endif // SRC_TINYGSMCLIENTSIM7080_H_
|
@@ -128,8 +128,8 @@ class TinyGsmSim70xx : public TinyGsmModem<TinyGsmSim70xx<modemType>>,
|
|||||||
|
|
||||||
// During sleep, the SIM70xx module has its serial communication disabled.
|
// During sleep, the SIM70xx module has its serial communication disabled.
|
||||||
// In order to reestablish communication pull the DRT-pin of the SIM70xx
|
// In order to reestablish communication pull the DRT-pin of the SIM70xx
|
||||||
// module LOW for at least 50ms. Then use this function to disable sleep mode.
|
// module LOW for at least 50ms. Then use this function to disable sleep
|
||||||
// The DTR-pin can then be released again.
|
// mode. The DTR-pin can then be released again.
|
||||||
bool sleepEnableImpl(bool enable = true) {
|
bool sleepEnableImpl(bool enable = true) {
|
||||||
thisModem().sendAT(GF("+CSCLK="), enable);
|
thisModem().sendAT(GF("+CSCLK="), enable);
|
||||||
return thisModem().waitResponse() == 1;
|
return thisModem().waitResponse() == 1;
|
||||||
|
@@ -596,8 +596,8 @@ class TinyGsmSequansMonarch
|
|||||||
// SOCK_LISTENING = 4,
|
// SOCK_LISTENING = 4,
|
||||||
// SOCK_INCOMING = 5,
|
// SOCK_INCOMING = 5,
|
||||||
// SOCK_OPENING = 6,
|
// SOCK_OPENING = 6,
|
||||||
GsmClientSequansMonarch* sock = sockets[mux % TINY_GSM_MUX_COUNT];
|
GsmClientSequansMonarch* sock = sockets[muxNo % TINY_GSM_MUX_COUNT];
|
||||||
if (sock && muxNo == mux) {
|
if (sock) {
|
||||||
sock->sock_connected = ((status != SOCK_CLOSED) &&
|
sock->sock_connected = ((status != SOCK_CLOSED) &&
|
||||||
(status != SOCK_INCOMING) &&
|
(status != SOCK_INCOMING) &&
|
||||||
(status != SOCK_OPENING));
|
(status != SOCK_OPENING));
|
||||||
|
@@ -391,9 +391,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
case 115200: changesMade |= changeSettingIfNeeded(GF("BD"), 0x7); break;
|
case 115200: changesMade |= changeSettingIfNeeded(GF("BD"), 0x7); break;
|
||||||
case 230400: changesMade |= changeSettingIfNeeded(GF("BD"), 0x8); break;
|
case 230400: changesMade |= changeSettingIfNeeded(GF("BD"), 0x8); break;
|
||||||
case 460800: changesMade |= changeSettingIfNeeded(GF("BD"), 0x9); break;
|
case 460800: changesMade |= changeSettingIfNeeded(GF("BD"), 0x9); break;
|
||||||
case 921600:
|
case 921600: changesMade |= changeSettingIfNeeded(GF("BD"), 0xA); break;
|
||||||
changesMade |= changeSettingIfNeeded(GF("BD"), 0xA);
|
|
||||||
break;
|
|
||||||
default: {
|
default: {
|
||||||
DBG(GF("Specified baud rate is unsupported! Setting to 9600 baud."));
|
DBG(GF("Specified baud rate is unsupported! Setting to 9600 baud."));
|
||||||
changesMade |= changeSettingIfNeeded(GF("BD"),
|
changesMade |= changeSettingIfNeeded(GF("BD"),
|
||||||
@@ -735,10 +733,12 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetworkImpl(uint32_t timeout_ms = 60000L) {
|
bool waitForNetworkImpl(uint32_t timeout_ms = 60000L,
|
||||||
|
bool check_signal = false) {
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
XBEE_COMMAND_START_DECORATOR(5, false)
|
XBEE_COMMAND_START_DECORATOR(5, false)
|
||||||
for (uint32_t start = millis(); millis() - start < timeout_ms;) {
|
for (uint32_t start = millis(); millis() - start < timeout_ms;) {
|
||||||
|
if (check_signal) { getSignalQuality(); }
|
||||||
if (isNetworkConnected()) {
|
if (isNetworkConnected()) {
|
||||||
retVal = true;
|
retVal = true;
|
||||||
break;
|
break;
|
||||||
|
@@ -77,8 +77,8 @@ class TinyGsmModem {
|
|||||||
return thisModem().isNetworkConnectedImpl();
|
return thisModem().isNetworkConnectedImpl();
|
||||||
}
|
}
|
||||||
// Waits for network attachment
|
// Waits for network attachment
|
||||||
bool waitForNetwork(uint32_t timeout_ms = 60000L) {
|
bool waitForNetwork(uint32_t timeout_ms = 60000L, bool check_signal = false) {
|
||||||
return thisModem().waitForNetworkImpl(timeout_ms);
|
return thisModem().waitForNetworkImpl(timeout_ms, check_signal);
|
||||||
}
|
}
|
||||||
// Gets signal quality report
|
// Gets signal quality report
|
||||||
int16_t getSignalQuality() {
|
int16_t getSignalQuality() {
|
||||||
@@ -197,8 +197,10 @@ class TinyGsmModem {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetworkImpl(uint32_t timeout_ms = 60000L) {
|
bool waitForNetworkImpl(uint32_t timeout_ms = 60000L,
|
||||||
|
bool check_signal = false) {
|
||||||
for (uint32_t start = millis(); millis() - start < timeout_ms;) {
|
for (uint32_t start = millis(); millis() - start < timeout_ms;) {
|
||||||
|
if (check_signal) { thisModem().getSignalQuality(); }
|
||||||
if (thisModem().isNetworkConnected()) { return true; }
|
if (thisModem().isNetworkConnected()) { return true; }
|
||||||
delay(250);
|
delay(250);
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,7 @@ class TinyGsmNTP {
|
|||||||
thisModem().waitResponse(10000L);
|
thisModem().waitResponse(10000L);
|
||||||
|
|
||||||
// Set NTP server and timezone
|
// Set NTP server and timezone
|
||||||
thisModem().sendAT(GF("+CNTP="), server, ',', String(TimeZone));
|
thisModem().sendAT(GF("+CNTP=\""), server, "\",", String(TimeZone));
|
||||||
if (thisModem().waitResponse(10000L) != 1) { return -1; }
|
if (thisModem().waitResponse(10000L) != 1) { return -1; }
|
||||||
|
|
||||||
// Request network synchronization
|
// Request network synchronization
|
||||||
|
@@ -141,6 +141,8 @@ class TinyGsmTCP {
|
|||||||
// with the modem to see if anything has arrived without a UURC.
|
// with the modem to see if anything has arrived without a UURC.
|
||||||
if (!rx.size()) {
|
if (!rx.size()) {
|
||||||
if (millis() - prev_check > 500) {
|
if (millis() - prev_check > 500) {
|
||||||
|
// setting got_data to true will tell maintain to run
|
||||||
|
// modemGetAvailable(mux)
|
||||||
got_data = true;
|
got_data = true;
|
||||||
prev_check = millis();
|
prev_check = millis();
|
||||||
}
|
}
|
||||||
@@ -211,6 +213,8 @@ class TinyGsmTCP {
|
|||||||
}
|
}
|
||||||
// Workaround: Some modules "forget" to notify about data arrival
|
// Workaround: Some modules "forget" to notify about data arrival
|
||||||
if (millis() - prev_check > 500) {
|
if (millis() - prev_check > 500) {
|
||||||
|
// setting got_data to true will tell maintain to run
|
||||||
|
// modemGetAvailable()
|
||||||
got_data = true;
|
got_data = true;
|
||||||
prev_check = millis();
|
prev_check = millis();
|
||||||
}
|
}
|
||||||
@@ -250,8 +254,8 @@ class TinyGsmTCP {
|
|||||||
if (available()) { return true; }
|
if (available()) { return true; }
|
||||||
#if defined TINY_GSM_BUFFER_READ_AND_CHECK_SIZE
|
#if defined TINY_GSM_BUFFER_READ_AND_CHECK_SIZE
|
||||||
// If the modem is one where we can read and check the size of the buffer,
|
// If the modem is one where we can read and check the size of the buffer,
|
||||||
// then the 'available()' function will call a check of the current size of
|
// then the 'available()' function will call a check of the current size
|
||||||
// the buffer and state of the connection. [available calls maintain,
|
// of the buffer and state of the connection. [available calls maintain,
|
||||||
// maintain calls modemGetAvailable, modemGetAvailable calls
|
// maintain calls modemGetAvailable, modemGetAvailable calls
|
||||||
// modemGetConnected] This cascade means that the sock_connected value
|
// modemGetConnected] This cascade means that the sock_connected value
|
||||||
// should be correct and all we need
|
// should be correct and all we need
|
||||||
|
Reference in New Issue
Block a user