Rename GSM_NL to AT_NL

Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
Sara Damiano
2024-05-13 14:03:29 -04:00
parent 3e7e615ef2
commit b8efb21f29
20 changed files with 271 additions and 283 deletions

View File

@@ -32,11 +32,11 @@
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
TinyGsm modem(SerialAT);
#endif
void setup() {
@@ -57,23 +57,21 @@ void setup() {
const int cert_size = sizeof(cert);
modem.sendAT(GF("+FSWRITE=" CERT_FILE ",0,"), cert_size, GF(",10"));
if (modem.waitResponse(GF(">")) != 1) {
return;
}
if (modem.waitResponse(GF(">")) != 1) { return; }
for (int i = 0; i < cert_size; i++) {
char c = pgm_read_byte(&cert[i]);
modem.stream.write(c);
}
modem.stream.write(GSM_NL);
modem.stream.write(AT_NL);
modem.stream.flush();
if (modem.waitResponse(2000) != 1) return;
modem.sendAT(GF("+SSLSETCERT=\"" CERT_FILE "\""));
if (modem.waitResponse() != 1) return;
if (modem.waitResponse(5000L, GF(GSM_NL "+SSLSETCERT:")) != 1) return;
if (modem.waitResponse(5000L, GF(AT_NL "+SSLSETCERT:")) != 1) return;
const int retCode = modem.stream.readStringUntil('\n').toInt();
@@ -86,11 +84,7 @@ void setup() {
}
void loop() {
if (SerialAT.available()) {
SerialMon.write(SerialAT.read());
}
if (SerialMon.available()) {
SerialAT.write(SerialMon.read());
}
if (SerialAT.available()) { SerialMon.write(SerialAT.read()); }
if (SerialMon.available()) { SerialAT.write(SerialMon.read()); }
delay(0);
}

View File

@@ -14,9 +14,9 @@
#define TINY_GSM_MUX_COUNT 8
#define TINY_GSM_NO_MODEM_BUFFER
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -208,8 +208,8 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
sendAT(GF("+CIFSR"));
String res;
if (waitResponse(10000L, res) != 1) { return ""; }
res.replace(GSM_NL "OK" GSM_NL, "");
res.replace(GSM_NL, "");
res.replace(AT_NL "OK" AT_NL, "");
res.replace(AT_NL, "");
res.trim();
return res;
}
@@ -262,7 +262,7 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
waitResponse();
sendAT(GF("+COPS?"));
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+COPS:")) != 1) { return ""; }
streamSkipUntil('"'); // Skip mode and format
String res = stream.readStringUntil('"');
waitResponse();
@@ -275,7 +275,7 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
protected:
String getSimCCIDImpl() {
sendAT(GF("+CCID"));
if (waitResponse(GF(GSM_NL "+SCID: SIM Card ID:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+SCID: SIM Card ID:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -296,16 +296,16 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
if (waitResponse(5000L) != 1) { return false; }
if (waitResponse(60000L, GF(GSM_NL "+CIEV: \"CALL\",1"),
GF(GSM_NL "+CIEV: \"CALL\",0"), GFP(GSM_ERROR)) != 1) {
if (waitResponse(60000L, GF(AT_NL "+CIEV: \"CALL\",1"),
GF(AT_NL "+CIEV: \"CALL\",0"), GFP(GSM_ERROR)) != 1) {
return false;
}
int8_t rsp = waitResponse(60000L, GF(GSM_NL "+CIEV: \"SOUNDER\",0"),
GF(GSM_NL "+CIEV: \"CALL\",0"));
int8_t rsp = waitResponse(60000L, GF(AT_NL "+CIEV: \"SOUNDER\",0"),
GF(AT_NL "+CIEV: \"CALL\",0"));
int8_t rsp2 = waitResponse(300L, GF(GSM_NL "BUSY" GSM_NL),
GF(GSM_NL "NO ANSWER" GSM_NL));
int8_t rsp2 = waitResponse(300L, GF(AT_NL "BUSY" AT_NL),
GF(AT_NL "NO ANSWER" AT_NL));
return rsp == 1 && rsp2 == 0;
}
@@ -358,7 +358,7 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
waitResponse();
sendAT(GF("+CUSD=1,\""), code, GF("\",15"));
if (waitResponse(10000L) != 1) { return ""; }
if (waitResponse(GF(GSM_NL "+CUSD:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+CUSD:")) != 1) { return ""; }
streamSkipUntil('"');
String hex = stream.readStringUntil('"');
streamSkipUntil(',');
@@ -389,7 +389,7 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
// Needs a '?' after CBC, unlike most
int8_t getBattPercentImpl() {
sendAT(GF("+CBC?"));
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return false; }
streamSkipUntil(','); // Skip battery charge status
// Read battery charge level
int8_t res = streamGetIntBefore('\n');
@@ -402,7 +402,7 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) {
sendAT(GF("+CBC?"));
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return false; }
chargeState = streamGetIntBefore(',');
percent = streamGetIntBefore('\n');
milliVolts = 0;
@@ -421,12 +421,12 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000;
sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port);
if (waitResponse(timeout_ms, GF(GSM_NL "+CIPNUM:")) != 1) { return false; }
if (waitResponse(timeout_ms, GF(AT_NL "+CIPNUM:")) != 1) { return false; }
int8_t newMux = streamGetIntBefore('\n');
int8_t rsp = waitResponse(
(timeout_ms - (millis() - startMillis)), GF("CONNECT OK" GSM_NL),
GF("CONNECT FAIL" GSM_NL), GF("ALREADY CONNECT" GSM_NL));
int8_t rsp = waitResponse((timeout_ms - (millis() - startMillis)),
GF("CONNECT OK" AT_NL), GF("CONNECT FAIL" AT_NL),
GF("ALREADY CONNECT" AT_NL));
if (waitResponse() != 1) { return false; }
*mux = newMux;
@@ -435,10 +435,10 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
int16_t modemSend(const void* buff, size_t len, uint8_t mux) {
sendAT(GF("+CIPSEND="), mux, ',', (uint16_t)len);
if (waitResponse(2000L, GF(GSM_NL ">")) != 1) { return 0; }
if (waitResponse(2000L, GF(AT_NL ">")) != 1) { return 0; }
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(10000L, GFP(GSM_OK), GF(GSM_NL "FAIL")) != 1) { return 0; }
if (waitResponse(10000L, GFP(GSM_OK), GF(AT_NL "FAIL")) != 1) { return 0; }
return len;
}

View File

@@ -14,9 +14,9 @@
#define TINY_GSM_MUX_COUNT 12
#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -289,7 +289,7 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
protected:
String getSimCCIDImpl() {
sendAT(GF("+QCCID"));
if (waitResponse(GF(GSM_NL "+QCCID:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+QCCID:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -337,7 +337,7 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
// get the RAW GPS output
String getGPSrawImpl() {
sendAT(GF("+QGPSLOC=2"));
if (waitResponse(10000L, GF(GSM_NL "+QGPSLOC:")) != 1) { return ""; }
if (waitResponse(10000L, GF(AT_NL "+QGPSLOC:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -350,7 +350,7 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
int* year = 0, int* month = 0, int* day = 0, int* hour = 0,
int* minute = 0, int* second = 0) {
sendAT(GF("+QGPSLOC=2"));
if (waitResponse(10000L, GF(GSM_NL "+QGPSLOC:")) != 1) {
if (waitResponse(10000L, GF(AT_NL "+QGPSLOC:")) != 1) {
// NOTE: Will return an error if the position isn't fixed
return false;
}
@@ -510,7 +510,7 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
// get temperature in degree celsius
uint16_t getTemperatureImpl() {
sendAT(GF("+QTEMP"));
if (waitResponse(GF(GSM_NL "+QTEMP:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+QTEMP:")) != 1) { return 0; }
// return temperature in C
uint16_t res =
streamGetIntBefore(','); // read PMIC (primary ic) temperature
@@ -538,7 +538,7 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
GF("\","), port, GF(",0,0"));
waitResponse();
if (waitResponse(timeout_ms, GF(GSM_NL "+QIOPEN:")) != 1) { return false; }
if (waitResponse(timeout_ms, GF(AT_NL "+QIOPEN:")) != 1) { return false; }
if (streamGetIntBefore(',') != mux) { return false; }
// Read status
@@ -550,7 +550,7 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
if (waitResponse(GF(">")) != 1) { return 0; }
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(GF(GSM_NL "SEND OK")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "SEND OK")) != 1) { return 0; }
// TODO(?): Wait for ACK? AT+QISEND=id,0
return len;
}
@@ -607,7 +607,7 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
*/
public:
bool handleURCs(String& data) {
if (data.endsWith(GF(GSM_NL "+QIURC:"))) {
if (data.endsWith(GF(AT_NL "+QIURC:"))) {
streamSkipUntil('\"');
String urc = stream.readStringUntil('\"');
streamSkipUntil(',');

View File

@@ -14,9 +14,9 @@
#define TINY_GSM_MUX_COUNT 5
#define TINY_GSM_NO_MODEM_BUFFER
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmModem.tpp"
@@ -190,8 +190,8 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
sendAT(GF("+GMR"));
String res;
if (waitResponse(1000L, res) != 1) { return ""; }
res.replace(GSM_NL "OK" GSM_NL, "");
res.replace(GSM_NL, " ");
res.replace(AT_NL "OK" AT_NL, "");
res.replace(AT_NL, " ");
res.trim();
return res;
}
@@ -204,7 +204,7 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
if (!testAT()) { return false; }
sendAT(GF("+RST"));
if (waitResponse(10000L) != 1) { return false; }
if (waitResponse(10000L, GF(GSM_NL "ready" GSM_NL)) != 1) { return false; }
if (waitResponse(10000L, GF(AT_NL "ready" AT_NL)) != 1) { return false; }
delay(500);
return init(pin);
}
@@ -303,9 +303,9 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
// attempt first without than with the 'current' flag used in some firmware
// versions
sendAT(GF("+CWJAP=\""), ssid, GF("\",\""), pwd, GF("\""));
if (waitResponse(30000L, GFP(GSM_OK), GF(GSM_NL "FAIL" GSM_NL)) != 1) {
if (waitResponse(30000L, GFP(AT_OK), GF(AT_NL "FAIL" AT_NL)) != 1) {
sendAT(GF("+CWJAP_CUR=\""), ssid, GF("\",\""), pwd, GF("\""));
if (waitResponse(30000L, GFP(GSM_OK), GF(GSM_NL "FAIL" GSM_NL)) != 1) {
if (waitResponse(30000L, GFP(AT_OK), GF(AT_NL "FAIL" AT_NL)) != 1) {
return false;
}
}
@@ -335,7 +335,7 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
GF("\",\""), host, GF("\","), port, GF(","),
TINY_GSM_TCP_KEEP_ALIVE);
// TODO(?): Check mux
int8_t rsp = waitResponse(timeout_ms, GFP(GSM_OK), GFP(GSM_ERROR),
int8_t rsp = waitResponse(timeout_ms, GFP(AT_OK), GFP(GSM_ERROR),
GF("ALREADY CONNECT"));
// if (rsp == 3) waitResponse();
// May return "ERROR" after the "ALREADY CONNECT"
@@ -347,7 +347,7 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
if (waitResponse(GF(">")) != 1) { return 0; }
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(10000L, GF(GSM_NL "SEND OK" GSM_NL)) != 1) { return 0; }
if (waitResponse(10000L, GF(AT_NL "SEND OK" AT_NL)) != 1) { return 0; }
return len;
}
@@ -357,7 +357,7 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
// after "STATUS:" it should return the status number (0,1,2,3,4,5),
// followed by an OK
// Hopefully we'll catch the "3" here, but fall back to the OK or Error
int8_t status = waitResponse(GF("3"), GFP(GSM_OK), GFP(GSM_ERROR));
int8_t status = waitResponse(GF("3"), GFP(AT_OK), GFP(GSM_ERROR));
// if the status is anything but 3, there are no connections open
if (status != 1) {
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
@@ -367,7 +367,7 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
}
bool verified_connections[TINY_GSM_MUX_COUNT] = {0, 0, 0, 0, 0};
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
uint8_t has_status = waitResponse(GF("+CIPSTATUS:"), GFP(GSM_OK),
uint8_t has_status = waitResponse(GF("+CIPSTATUS:"), GFP(AT_OK),
GFP(GSM_ERROR));
if (has_status == 1) {
int8_t returned_mux = streamGetIntBefore(',');
@@ -416,7 +416,7 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
return true;
} else if (data.endsWith(GF("CLOSED"))) {
int8_t muxStart = TinyGsmMax(0,
data.lastIndexOf(GSM_NL, data.length() - 8));
data.lastIndexOf(AT_NL, data.length() - 8));
int8_t coma = data.indexOf(',', muxStart);
int8_t mux = data.substring(muxStart, coma).toInt();
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {

View File

@@ -14,9 +14,9 @@
#define TINY_GSM_MUX_COUNT 2
#define TINY_GSM_NO_MODEM_BUFFER
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmGPRS.tpp"
@@ -171,7 +171,7 @@ class TinyGsmM590 : public TinyGsmModem<TinyGsmM590>,
if (!testAT()) { return false; }
if (!setPhoneFunctionality(15)) { return false; }
// MODEM:STARTUP
waitResponse(60000L, GF(GSM_NL "+PBREADY" GSM_NL));
waitResponse(60000L, GF(AT_NL "+PBREADY" AT_NL));
return init(pin);
}
@@ -206,7 +206,7 @@ class TinyGsmM590 : public TinyGsmModem<TinyGsmM590>,
String getLocalIPImpl() {
sendAT(GF("+XIIC?"));
if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+XIIC:")) != 1) { return ""; }
streamSkipUntil(',');
String res = stream.readStringUntil('\n');
waitResponse();
@@ -264,7 +264,7 @@ class TinyGsmM590 : public TinyGsmModem<TinyGsmM590>,
bool isGprsConnectedImpl() {
sendAT(GF("+XIIC?"));
if (waitResponse(GF(GSM_NL "+XIIC:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+XIIC:")) != 1) { return false; }
int8_t res = streamGetIntBefore(',');
waitResponse();
return res == 1;
@@ -300,9 +300,8 @@ class TinyGsmM590 : public TinyGsmModem<TinyGsmM590>,
String ip = dnsIpQuery(host);
sendAT(GF("+TCPSETUP="), mux, GF(","), ip, GF(","), port);
int8_t rsp = waitResponse(timeout_ms, GF(",OK" GSM_NL),
GF(",FAIL" GSM_NL),
GF("+TCPSETUP:Error" GSM_NL));
int8_t rsp = waitResponse(timeout_ms, GF(",OK" AT_NL), GF(",FAIL" AT_NL),
GF("+TCPSETUP:Error" AT_NL));
if (1 == rsp) {
return true;
} else if (3 == rsp) {
@@ -320,7 +319,7 @@ class TinyGsmM590 : public TinyGsmModem<TinyGsmM590>,
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.write(static_cast<char>(0x0D));
stream.flush();
if (waitResponse(30000L, GF(GSM_NL "+TCPSEND:")) != 1) { return 0; }
if (waitResponse(30000L, GF(AT_NL "+TCPSEND:")) != 1) { return 0; }
streamSkipUntil('\n');
return len;
}
@@ -335,9 +334,9 @@ class TinyGsmM590 : public TinyGsmModem<TinyGsmM590>,
String dnsIpQuery(const char* host) {
sendAT(GF("+DNS=\""), host, GF("\""));
if (waitResponse(10000L, GF(GSM_NL "+DNS:")) != 1) { return ""; }
if (waitResponse(10000L, GF(AT_NL "+DNS:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse(GF("+DNS:OK" GSM_NL));
waitResponse(GF("+DNS:OK" AT_NL));
res.trim();
return res;
}

View File

@@ -15,9 +15,9 @@
#define TINY_GSM_MUX_COUNT 6
#define TINY_GSM_BUFFER_READ_NO_CHECK
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -342,7 +342,7 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
protected:
String getSimCCIDImpl() {
sendAT(GF("+QCCID"));
if (waitResponse(GF(GSM_NL "+QCCID:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+QCCID:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -388,7 +388,7 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
protected:
float getTemperatureImpl() {
sendAT(GF("+QTEMP?"));
if (waitResponse(GF(GSM_NL "+QTEMP:")) != 1) {
if (waitResponse(GF(AT_NL "+QTEMP:")) != 1) {
return static_cast<float>(-9999);
}
streamSkipUntil(','); // Skip mode
@@ -411,9 +411,9 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000;
sendAT(GF("+QIOPEN="), mux, GF(",\""), GF("TCP"), GF("\",\""), host,
GF("\","), port);
int8_t rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL),
GF("CONNECT FAIL" GSM_NL),
GF("ALREADY CONNECT" GSM_NL));
int8_t rsp = waitResponse(timeout_ms, GF("CONNECT OK" AT_NL),
GF("CONNECT FAIL" AT_NL),
GF("ALREADY CONNECT" AT_NL));
return (1 == rsp);
}
@@ -422,13 +422,13 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
if (waitResponse(GF(">")) != 1) { return 0; }
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(GF(GSM_NL "SEND OK")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "SEND OK")) != 1) { return 0; }
// bool allAcknowledged = false;
// // bool failed = false;
// while ( !allAcknowledged ) {
// sendAT( GF("+QISACK"));
// if (waitResponse(5000L, GF(GSM_NL "+QISACK:")) != 1) {
// if (waitResponse(5000L, GF(AT_NL "+QISACK:")) != 1) {
// return -1;
// } else {
// streamSkipUntil(','); // Skip total length sent on connection
@@ -455,7 +455,7 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size);
// If it replies only OK for the write command, it means there is no
// received data in the buffer of the connection.
int8_t res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR));
int8_t res = waitResponse(GF("+QIRD:"), GFP(AT_OK), GFP(GSM_ERROR));
if (res == 1) {
streamSkipUntil(':'); // skip IP address
streamSkipUntil(','); // skip port
@@ -512,7 +512,7 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
*/
public:
bool handleURCs(String& data) {
if (data.endsWith(GF(GSM_NL "+QIRDI:"))) {
if (data.endsWith(GF(AT_NL "+QIRDI:"))) {
streamSkipUntil(','); // Skip the context
streamSkipUntil(','); // Skip the role
int8_t mux = streamGetIntBefore('\n');
@@ -524,8 +524,8 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
}
data = "";
return true;
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
int8_t nl = data.lastIndexOf(GSM_NL, data.length() - 8);
} else if (data.endsWith(GF("CLOSED" AT_NL))) {
int8_t nl = data.lastIndexOf(AT_NL, data.length() - 8);
int8_t coma = data.indexOf(',', nl + 2);
int8_t mux = data.substring(nl + 2, coma).toInt();
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {

View File

@@ -17,9 +17,9 @@
#define TINY_GSM_MUX_COUNT 6
#define TINY_GSM_BUFFER_READ_NO_CHECK
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -312,7 +312,7 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
SimStatus getSimStatusImpl(uint32_t timeout_ms = 10000L) {
for (uint32_t start = millis(); millis() - start < timeout_ms;) {
sendAT(GF("+CPIN?"));
if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) {
if (waitResponse(GF(AT_NL "+CPIN:")) != 1) {
delay(1000);
continue;
}
@@ -384,9 +384,9 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
uint32_t timeout_ms = ((uint32_t)timeout_s) * 1000;
sendAT(GF("+QIOPEN="), mux, GF(",\""), GF("TCP"), GF("\",\""), host,
GF("\","), port);
int8_t rsp = waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL),
GF("CONNECT FAIL" GSM_NL),
GF("ALREADY CONNECT" GSM_NL));
int8_t rsp = waitResponse(timeout_ms, GF("CONNECT OK" AT_NL),
GF("CONNECT FAIL" AT_NL),
GF("ALREADY CONNECT" AT_NL));
return (1 == rsp);
}
@@ -395,14 +395,14 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
if (waitResponse(GF(">")) != 1) { return 0; }
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(GF(GSM_NL "SEND OK")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "SEND OK")) != 1) { return 0; }
bool allAcknowledged = false;
// bool failed = false;
while (!allAcknowledged) {
sendAT(GF("+QISACK="), mux); // If 'mux' is not specified, MC60 returns
// 'ERRROR' (for QIMUX == 1)
if (waitResponse(5000L, GF(GSM_NL "+QISACK:")) != 1) {
if (waitResponse(5000L, GF(AT_NL "+QISACK:")) != 1) {
return -1;
} else {
streamSkipUntil(','); /** Skip total */
@@ -429,7 +429,7 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
sendAT(GF("+QIRD=0,1,"), mux, ',', (uint16_t)size);
// If it replies only OK for the write command, it means there is no
// received data in the buffer of the connection.
int8_t res = waitResponse(GF("+QIRD:"), GFP(GSM_OK), GFP(GSM_ERROR));
int8_t res = waitResponse(GF("+QIRD:"), GFP(AT_OK), GFP(GSM_ERROR));
if (res == 1) {
streamSkipUntil(':'); // skip IP address
streamSkipUntil(','); // skip port
@@ -485,7 +485,7 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
*/
public:
bool handleURCs(String& data) {
if (data.endsWith(GF(GSM_NL "+QIRDI:"))) { // TODO(?): QIRD? or QIRDI?
if (data.endsWith(GF(AT_NL "+QIRDI:"))) { // TODO(?): QIRD? or QIRDI?
// +QIRDI: <id>,<sc>,<sid>,<num>,<len>,< tlen>
streamSkipUntil(','); // Skip the context
streamSkipUntil(','); // Skip the role
@@ -505,8 +505,8 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
data = "";
// DBG("### Got Data:", len_total, "on", mux);
return true;
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
int8_t nl = data.lastIndexOf(GSM_NL, data.length() - 8);
} else if (data.endsWith(GF("CLOSED" AT_NL))) {
int8_t nl = data.lastIndexOf(AT_NL, data.length() - 8);
int8_t coma = data.indexOf(',', nl + 2);
int8_t mux = data.substring(nl + 2, coma).toInt();
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {

View File

@@ -14,9 +14,9 @@
#define TINY_GSM_MUX_COUNT 10
#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -197,7 +197,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
sendAT(GF("+CGMM"));
String res2;
if (waitResponse(1000L, res2) != 1) { return name; }
res2.replace(GSM_NL "OK" GSM_NL, "");
res2.replace(AT_NL "OK" AT_NL, "");
res2.replace("_", " ");
res2.trim();
@@ -221,7 +221,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
if (waitResponse(10000L) != 1) { return false; }
// After booting, modem sends out messages as each of its
// internal modules loads. The final message is "PB DONE".
if (waitResponse(40000L, GF(GSM_NL "PB DONE")) != 1) { return false; }
if (waitResponse(40000L, GF(AT_NL "PB DONE")) != 1) { return false; }
return init(pin);
}
@@ -263,7 +263,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
public:
String getNetworkModes() {
sendAT(GF("+CNMP=?"));
if (waitResponse(GF(GSM_NL "+CNMP:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+CNMP:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
return res;
@@ -271,7 +271,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
int16_t getNetworkMode() {
sendAT(GF("+CNMP?"));
if (waitResponse(GF(GSM_NL "+CNMP:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+CNMP:")) != 1) { return false; }
int16_t mode = streamGetIntBefore('\n');
waitResponse();
return mode;
@@ -287,8 +287,8 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
// sendAT(GF("+CGPADDR=1")); // Show PDP address
String res;
if (waitResponse(10000L, res) != 1) { return ""; }
res.replace(GSM_NL "OK" GSM_NL, "");
res.replace(GSM_NL, "");
res.replace(AT_NL "OK" AT_NL, "");
res.replace(AT_NL, "");
res.trim();
return res;
}
@@ -372,7 +372,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
// We to ignore any immediate response and wait for the
// URC to show it's really connected.
sendAT(GF("+NETOPEN"));
if (waitResponse(75000L, GF(GSM_NL "+NETOPEN: 0")) != 1) { return false; }
if (waitResponse(75000L, GF(AT_NL "+NETOPEN: 0")) != 1) { return false; }
return true;
}
@@ -388,7 +388,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
// Note: all sockets should be closed first - on 3G/4G models the sockets
// must be closed manually
sendAT(GF("+NETCLOSE"));
if (waitResponse(60000L, GF(GSM_NL "+NETCLOSE: 0")) != 1) { return false; }
if (waitResponse(60000L, GF(AT_NL "+NETCLOSE: 0")) != 1) { return false; }
return true;
}
@@ -396,7 +396,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
bool isGprsConnectedImpl() {
sendAT(GF("+NETOPEN?"));
// May return +NETOPEN: 1, 0. We just confirm that the first number is 1
if (waitResponse(GF(GSM_NL "+NETOPEN: 1")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+NETOPEN: 1")) != 1) { return false; }
waitResponse();
sendAT(GF("+IPADDR")); // Inquire Socket PDP address
@@ -413,7 +413,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
// Gets the CCID of a sim card via AT+CCID
String getSimCCIDImpl() {
sendAT(GF("+CICCID"));
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+ICCID:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -451,7 +451,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
// SRGD Note: Returns voltage in VOLTS instead of millivolts
uint16_t getBattVoltageImpl() {
sendAT(GF("+CBC"));
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return 0; }
streamSkipUntil(','); // Skip battery charge status
streamSkipUntil(','); // Skip battery charge level
// get voltage in VOLTS
@@ -467,7 +467,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
bool getBattStatsImpl(uint8_t& chargeState, int8_t& percent,
uint16_t& milliVolts) {
sendAT(GF("+CBC"));
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return false; }
chargeState = streamGetIntBefore(',');
percent = streamGetIntBefore(',');
// get voltage in VOLTS
@@ -489,7 +489,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
if (waitResponse() != 1) { return 0; }
// Get Temparature Value
sendAT(GF("+CMTE?"));
if (waitResponse(GF(GSM_NL "+CMTE:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+CMTE:")) != 1) { return false; }
float res = streamGetFloatBefore('\n');
// Wait for final OK
waitResponse();
@@ -512,7 +512,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
sendAT(GF("+CIPOPEN="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","),
port);
// The reply is +CIPOPEN: ## of socket created
if (waitResponse(timeout_ms, GF(GSM_NL "+CIPOPEN:")) != 1) { return false; }
if (waitResponse(timeout_ms, GF(AT_NL "+CIPOPEN:")) != 1) { return false; }
return true;
}
@@ -521,7 +521,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
if (waitResponse(GF(">")) != 1) { return 0; }
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(GF(GSM_NL "+CIPSEND:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+CIPSEND:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip requested bytes to send
// TODO(?): make sure requested and confirmed bytes match
@@ -606,7 +606,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
*/
public:
bool handleURCs(String& data) {
if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
if (data.endsWith(GF(AT_NL "+CIPRXGET:"))) {
int8_t mode = streamGetIntBefore(',');
if (mode == 1) {
int8_t mux = streamGetIntBefore('\n');
@@ -620,7 +620,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
data += mode;
return false;
}
} else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) {
} else if (data.endsWith(GF(AT_NL "+RECEIVE:"))) {
int8_t mux = streamGetIntBefore(',');
int16_t len = streamGetIntBefore('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {

View File

@@ -152,8 +152,8 @@ class TinyGsmSim7000 : public TinyGsmSim70xx<TinyGsmSim7000>,
sendAT(GF("+CIFSR;E0"));
String res;
if (waitResponse(10000L, res) != 1) { return ""; }
res.replace(GSM_NL "OK" GSM_NL, "");
res.replace(GSM_NL, "");
res.replace(AT_NL "OK" AT_NL, "");
res.replace(AT_NL, "");
res.trim();
return res;
}
@@ -293,10 +293,9 @@ class TinyGsmSim7000 : public TinyGsmSim70xx<TinyGsmSim7000>,
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host,
GF("\","), port);
return (1 ==
waitResponse(timeout_ms, GF("CONNECT OK" GSM_NL),
GF("CONNECT FAIL" GSM_NL),
GF("ALREADY CONNECT" GSM_NL), GF("ERROR" GSM_NL),
GF("CLOSE OK" GSM_NL)));
waitResponse(timeout_ms, GF("CONNECT OK" AT_NL),
GF("CONNECT FAIL" AT_NL), GF("ALREADY CONNECT" AT_NL),
GF("ERROR" AT_NL), GF("CLOSE OK" AT_NL)));
}
int16_t modemSend(const void* buff, size_t len, uint8_t mux) {
@@ -306,7 +305,7 @@ class TinyGsmSim7000 : public TinyGsmSim70xx<TinyGsmSim7000>,
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "DATA ACCEPT:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux
return streamGetIntBefore('\n');
}
@@ -391,7 +390,7 @@ class TinyGsmSim7000 : public TinyGsmSim70xx<TinyGsmSim7000>,
*/
public:
bool handleURCs(String& data) {
if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
if (data.endsWith(GF(AT_NL "+CIPRXGET:"))) {
int8_t mode = streamGetIntBefore(',');
if (mode == 1) {
int8_t mux = streamGetIntBefore('\n');
@@ -405,7 +404,7 @@ class TinyGsmSim7000 : public TinyGsmSim70xx<TinyGsmSim7000>,
data += mode;
return false;
}
} else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) {
} else if (data.endsWith(GF(AT_NL "+RECEIVE:"))) {
int8_t mux = streamGetIntBefore(',');
int16_t len = streamGetIntBefore('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
@@ -415,8 +414,8 @@ class TinyGsmSim7000 : public TinyGsmSim70xx<TinyGsmSim7000>,
data = "";
// DBG("### Got Data:", len, "on", mux);
return true;
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
int8_t nl = data.lastIndexOf(GSM_NL, data.length() - 8);
} else if (data.endsWith(GF("CLOSED" AT_NL))) {
int8_t nl = data.lastIndexOf(AT_NL, data.length() - 8);
int8_t coma = data.indexOf(',', nl + 2);
int8_t mux = data.substring(nl + 2, coma).toInt();
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
@@ -445,7 +444,7 @@ class TinyGsmSim7000 : public TinyGsmSim70xx<TinyGsmSim7000>,
data = "";
DBG("### Daylight savings time state updated.");
return true;
} else if (data.endsWith(GF(GSM_NL "SMS Ready" GSM_NL))) {
} else if (data.endsWith(GF(AT_NL "SMS Ready" AT_NL))) {
data = "";
DBG("### Unexpected module reset!");
init();

View File

@@ -194,7 +194,7 @@ class TinyGsmSim7000SSL
protected:
String getLocalIPImpl() {
sendAT(GF("+CNACT?"));
if (waitResponse(GF(GSM_NL "+CNACT:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+CNACT:")) != 1) { return ""; }
streamSkipUntil('\"');
String res = stream.readStringUntil('\"');
waitResponse();
@@ -265,8 +265,8 @@ class TinyGsmSim7000SSL
int ntries = 0;
while (!res && ntries < 5) {
sendAT(GF("+CNACT=1,\""), apn, GF("\""));
res = waitResponse(60000L, GF(GSM_NL "+APP PDP: ACTIVE"),
GF(GSM_NL "+APP PDP: DEACTIVE")) == 1;
res = waitResponse(60000L, GF(AT_NL "+APP PDP: ACTIVE"),
GF(AT_NL "+APP PDP: DEACTIVE")) == 1;
waitResponse();
ntries++;
}
@@ -393,7 +393,7 @@ class TinyGsmSim7000SSL
// <conn_type> "TCP" or "UDP"
// 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(AT_NL "+CAOPEN:")) != 1) { return 0; }
// returns OK/r/n/r/n+CAOPEN: <cid>,<result>
// <result> 0: Success
// 1: Socket error
@@ -430,7 +430,7 @@ class TinyGsmSim7000SSL
// after posting data, module responds with:
//+CASEND: <cid>,<result>,<sendlen>
if (waitResponse(GF(GSM_NL "+CASEND:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+CASEND:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux
if (streamGetIntBefore(',') != 0) { return 0; } // If result != success
return streamGetIntBefore('\n');
@@ -496,7 +496,7 @@ class TinyGsmSim7000SSL
sendAT(GF("+CARECV?"));
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
// after the last connection, there's an ok, so we catch it right away
int res = waitResponse(3000, GF("+CARECV:"), GFP(GSM_OK), GFP(GSM_ERROR));
int res = waitResponse(3000, GF("+CARECV:"), GFP(AT_OK), GFP(GSM_ERROR));
// if we get the +CARECV: response, read the mux number and the number of
// characters available
if (res == 1) {
@@ -543,8 +543,7 @@ class TinyGsmSim7000SSL
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
// after the last connection, there's an ok, so we catch it right away
int res = waitResponse(3000, GF("+CASTATE:"), GFP(GSM_OK),
GFP(GSM_ERROR));
int res = waitResponse(3000, GF("+CASTATE:"), GFP(AT_OK), GFP(GSM_ERROR));
// if we get the +CASTATE: response, read the mux number and the status
if (res == 1) {
int ret_mux = streamGetIntBefore(',');
@@ -638,7 +637,7 @@ class TinyGsmSim7000SSL
data = "";
DBG("### Daylight savings time state updated.");
return true;
} else if (data.endsWith(GF(GSM_NL "SMS Ready" GSM_NL))) {
} else if (data.endsWith(GF(AT_NL "SMS Ready" AT_NL))) {
data = "";
DBG("### Unexpected module reset!");
init();

View File

@@ -192,7 +192,7 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
protected:
String getLocalIPImpl() {
sendAT(GF("+CNACT?"));
if (waitResponse(GF(GSM_NL "+CNACT:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+CNACT:")) != 1) { return ""; }
streamSkipUntil('\"');
String res = stream.readStringUntil('\"');
waitResponse();
@@ -270,8 +270,8 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
int ntries = 0;
while (!res && ntries < 5) {
sendAT(GF("+CNACT=0,1"));
res = waitResponse(60000L, GF(GSM_NL "+APP PDP: 0,ACTIVE"),
GF(GSM_NL "+APP PDP: 0,DEACTIVE"));
res = waitResponse(60000L, GF(AT_NL "+APP PDP: 0,ACTIVE"),
GF(AT_NL "+APP PDP: 0,DEACTIVE"));
waitResponse();
ntries++;
}
@@ -401,7 +401,7 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
// "recv",<id>,<length>,<remoteIP>,<remote_port><CR><LF><data>
// NOTE: including the <recv_mode> fails
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(AT_NL "+CAOPEN:")) != 1) { return 0; }
// returns OK/r/n/r/n+CAOPEN: <cid>,<result>
// <result> 0: Success
// 1: Socket error
@@ -495,7 +495,7 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
sendAT(GF("+CARECV?"));
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
// after the last connection, there's an ok, so we catch it right away
int res = waitResponse(3000, GF("+CARECV:"), GFP(GSM_OK), GFP(GSM_ERROR));
int res = waitResponse(3000, GF("+CARECV:"), GFP(AT_OK), GFP(GSM_ERROR));
// if we get the +CARECV: response, read the mux number and the number of
// characters available
if (res == 1) {
@@ -542,8 +542,7 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
for (int muxNo = 0; muxNo < TINY_GSM_MUX_COUNT; muxNo++) {
// after the last connection, there's an ok, so we catch it right away
int res = waitResponse(3000, GF("+CASTATE:"), GFP(GSM_OK),
GFP(GSM_ERROR));
int res = waitResponse(3000, GF("+CASTATE:"), GFP(AT_OK), GFP(GSM_ERROR));
// if we get the +CASTATE: response, read the mux number and the status
if (res == 1) {
int ret_mux = streamGetIntBefore(',');
@@ -637,7 +636,7 @@ class TinyGsmSim7080 : public TinyGsmSim70xx<TinyGsmSim7080>,
data = "";
DBG("### Daylight savings time state updated.");
return true;
} else if (data.endsWith(GF(GSM_NL "SMS Ready" GSM_NL))) {
} else if (data.endsWith(GF(AT_NL "SMS Ready" AT_NL))) {
data = "";
DBG("### Unexpected module reset!");
init();

View File

@@ -11,9 +11,9 @@
// #define TINY_GSM_DEBUG Serial
// #define TINY_GSM_USE_HEX
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -84,7 +84,7 @@ class TinyGsmSim70xx : public TinyGsmModem<TinyGsmSim70xx<modemType>>,
thisModem().sendAT(GF("+GMM"));
String res2;
if (thisModem().waitResponse(5000L, res2) != 1) { return name; }
res2.replace(GSM_NL "OK" GSM_NL, "");
res2.replace(AT_NL "OK" AT_NL, "");
res2.replace("_", " ");
res2.trim();
@@ -166,7 +166,7 @@ class TinyGsmSim70xx : public TinyGsmModem<TinyGsmSim70xx<modemType>>,
String getNetworkModes() {
// Get the help string, not the setting value
thisModem().sendAT(GF("+CNMP=?"));
if (thisModem().waitResponse(GF(GSM_NL "+CNMP:")) != 1) { return ""; }
if (thisModem().waitResponse(GF(AT_NL "+CNMP:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
thisModem().waitResponse();
return res;
@@ -174,7 +174,7 @@ class TinyGsmSim70xx : public TinyGsmModem<TinyGsmSim70xx<modemType>>,
int16_t getNetworkMode() {
thisModem().sendAT(GF("+CNMP?"));
if (thisModem().waitResponse(GF(GSM_NL "+CNMP:")) != 1) { return false; }
if (thisModem().waitResponse(GF(AT_NL "+CNMP:")) != 1) { return false; }
int16_t mode = thisModem().streamGetIntBefore('\n');
thisModem().waitResponse();
return mode;
@@ -192,7 +192,7 @@ class TinyGsmSim70xx : public TinyGsmModem<TinyGsmSim70xx<modemType>>,
String getPreferredModes() {
// Get the help string, not the setting value
thisModem().sendAT(GF("+CMNB=?"));
if (thisModem().waitResponse(GF(GSM_NL "+CMNB:")) != 1) { return ""; }
if (thisModem().waitResponse(GF(AT_NL "+CMNB:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
thisModem().waitResponse();
return res;
@@ -200,7 +200,7 @@ class TinyGsmSim70xx : public TinyGsmModem<TinyGsmSim70xx<modemType>>,
int16_t getPreferredMode() {
thisModem().sendAT(GF("+CMNB?"));
if (thisModem().waitResponse(GF(GSM_NL "+CMNB:")) != 1) { return false; }
if (thisModem().waitResponse(GF(AT_NL "+CMNB:")) != 1) { return false; }
int16_t mode = thisModem().streamGetIntBefore('\n');
thisModem().waitResponse();
return mode;
@@ -218,7 +218,7 @@ class TinyGsmSim70xx : public TinyGsmModem<TinyGsmSim70xx<modemType>>,
// n: whether to automatically report the system mode info
// stat: the current service. 0 if it not connected
thisModem().sendAT(GF("+CNSMOD?"));
if (thisModem().waitResponse(GF(GSM_NL "+CNSMOD:")) != 1) { return false; }
if (thisModem().waitResponse(GF(AT_NL "+CNSMOD:")) != 1) { return false; }
n = thisModem().streamGetIntBefore(',') != 0;
stat = thisModem().streamGetIntBefore('\n');
thisModem().waitResponse();
@@ -256,7 +256,7 @@ class TinyGsmSim70xx : public TinyGsmModem<TinyGsmSim70xx<modemType>>,
// Doesn't return the "+CCID" before the number
String getSimCCIDImpl() {
thisModem().sendAT(GF("+CCID"));
if (thisModem().waitResponse(GF(GSM_NL)) != 1) { return ""; }
if (thisModem().waitResponse(GF(AT_NL)) != 1) { return ""; }
String res = stream.readStringUntil('\n');
thisModem().waitResponse();
res.trim();
@@ -289,7 +289,7 @@ class TinyGsmSim70xx : public TinyGsmModem<TinyGsmSim70xx<modemType>>,
// get the RAW GPS output
String getGPSrawImpl() {
thisModem().sendAT(GF("+CGNSINF"));
if (thisModem().waitResponse(10000L, GF(GSM_NL "+CGNSINF:")) != 1) {
if (thisModem().waitResponse(10000L, GF(AT_NL "+CGNSINF:")) != 1) {
return "";
}
String res = stream.readStringUntil('\n');
@@ -304,7 +304,7 @@ class TinyGsmSim70xx : public TinyGsmModem<TinyGsmSim70xx<modemType>>,
int* year = 0, int* month = 0, int* day = 0, int* hour = 0,
int* minute = 0, int* second = 0) {
thisModem().sendAT(GF("+CGNSINF"));
if (thisModem().waitResponse(10000L, GF(GSM_NL "+CGNSINF:")) != 1) {
if (thisModem().waitResponse(10000L, GF(AT_NL "+CGNSINF:")) != 1) {
return false;
}

View File

@@ -14,9 +14,9 @@
#define TINY_GSM_MUX_COUNT 10
#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -205,7 +205,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
sendAT(GF("+CGMM"));
String res2;
if (waitResponse(1000L, res2) != 1) { return name; }
res2.replace(GSM_NL "OK" GSM_NL, "");
res2.replace(AT_NL "OK" AT_NL, "");
res2.replace("_", " ");
res2.trim();
@@ -268,7 +268,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
public:
String getNetworkModes() {
sendAT(GF("+CNMP=?"));
if (waitResponse(GF(GSM_NL "+CNMP:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+CNMP:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
return res;
@@ -276,7 +276,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
int16_t getNetworkMode() {
sendAT(GF("+CNMP?"));
if (waitResponse(GF(GSM_NL "+CNMP:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+CNMP:")) != 1) { return false; }
int16_t mode = streamGetIntBefore('\n');
waitResponse();
return mode;
@@ -292,8 +292,8 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
// sendAT(GF("+CGPADDR=1")); // Show PDP address
String res;
if (waitResponse(10000L, res) != 1) { return ""; }
res.replace(GSM_NL "OK" GSM_NL, "");
res.replace(GSM_NL, "");
res.replace(AT_NL "OK" AT_NL, "");
res.replace(AT_NL, "");
res.trim();
return res;
}
@@ -360,7 +360,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
// We to ignore any immediate response and wait for the
// URC to show it's really connected.
sendAT(GF("+NETOPEN"));
if (waitResponse(75000L, GF(GSM_NL "+NETOPEN: 0")) != 1) { return false; }
if (waitResponse(75000L, GF(AT_NL "+NETOPEN: 0")) != 1) { return false; }
return true;
}
@@ -370,7 +370,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
// Note: On the LTE models, this single command closes all sockets and the
// service
sendAT(GF("+NETCLOSE"));
if (waitResponse(60000L, GF(GSM_NL "+NETCLOSE: 0")) != 1) { return false; }
if (waitResponse(60000L, GF(AT_NL "+NETCLOSE: 0")) != 1) { return false; }
return true;
}
@@ -378,7 +378,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
bool isGprsConnectedImpl() {
sendAT(GF("+NETOPEN?"));
// May return +NETOPEN: 1, 0. We just confirm that the first number is 1
if (waitResponse(GF(GSM_NL "+NETOPEN: 1")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+NETOPEN: 1")) != 1) { return false; }
waitResponse();
sendAT(GF("+IPADDR")); // Inquire Socket PDP address
@@ -395,7 +395,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
// Gets the CCID of a sim card via AT+CCID
String getSimCCIDImpl() {
sendAT(GF("+CICCID"));
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+ICCID:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -443,7 +443,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
// get the RAW GPS output
String getGPSrawImpl() {
sendAT(GF("+CGNSSINFO"));
if (waitResponse(GF(GSM_NL "+CGNSSINFO:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+CGNSSINFO:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -456,7 +456,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
int* year = 0, int* month = 0, int* day = 0, int* hour = 0,
int* minute = 0, int* second = 0) {
sendAT(GF("+CGNSSINFO"));
if (waitResponse(GF(GSM_NL "+CGNSSINFO:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+CGNSSINFO:")) != 1) { return false; }
uint8_t fixMode = streamGetIntBefore(','); // mode 2=2D Fix or 3=3DFix
// TODO(?) Can 1 be returned
@@ -547,14 +547,14 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
String res;
sendAT(GF("+CGNSSMODE="), mode, ",", dpo);
if (waitResponse(10000L, res) != 1) { return ""; }
res.replace(GSM_NL, "");
res.replace(AT_NL, "");
res.trim();
return res;
}
uint8_t getGNSSModeImpl() {
sendAT(GF("+CGNSSMODE?"));
if (waitResponse(GF(GSM_NL "+CGNSSMODE:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+CGNSSMODE:")) != 1) { return 0; }
return stream.readStringUntil(',').toInt();
}
@@ -577,7 +577,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
// returns volts, multiply by 1000 to get mV
uint16_t getBattVoltageImpl() {
sendAT(GF("+CBC"));
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+CBC:")) != 1) { return 0; }
// get voltage in VOLTS
float voltage = streamGetFloatBefore('\n');
@@ -607,7 +607,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
// get temperature in degree celsius
uint16_t getTemperatureImpl() {
sendAT(GF("+CPMUTEMP"));
if (waitResponse(GF(GSM_NL "+CPMUTEMP:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+CPMUTEMP:")) != 1) { return 0; }
// return temperature in C
uint16_t res = streamGetIntBefore('\n');
// Wait for final OK
@@ -632,7 +632,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
port);
// The reply is OK followed by +CIPOPEN: <link_num>,<err> where <link_num>
// is the mux number and <err> should be 0 if there's no error
if (waitResponse(timeout_ms, GF(GSM_NL "+CIPOPEN:")) != 1) { return false; }
if (waitResponse(timeout_ms, GF(AT_NL "+CIPOPEN:")) != 1) { return false; }
uint8_t opened_mux = streamGetIntBefore(',');
uint8_t opened_result = streamGetIntBefore('\n');
if (opened_mux != mux || opened_result != 0) return false;
@@ -644,7 +644,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
if (waitResponse(GF(">")) != 1) { return 0; }
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(GF(GSM_NL "+CIPSEND:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+CIPSEND:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux
streamSkipUntil(','); // Skip requested bytes to send
// TODO(?): make sure requested and confirmed bytes match
@@ -731,7 +731,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
*/
public:
bool handleURCs(String& data) {
if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
if (data.endsWith(GF(AT_NL "+CIPRXGET:"))) {
int8_t mode = streamGetIntBefore(',');
if (mode == 1) {
int8_t mux = streamGetIntBefore('\n');
@@ -745,7 +745,7 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
data += mode;
return false;
}
} else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) {
} else if (data.endsWith(GF(AT_NL "+RECEIVE:"))) {
int8_t mux = streamGetIntBefore(',');
int16_t len = streamGetIntBefore('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {

View File

@@ -15,9 +15,9 @@
#define TINY_GSM_MUX_COUNT 5
#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -209,7 +209,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
sendAT(GF("+GMM"));
String res2;
if (waitResponse(1000L, res2) != 1) { return name; }
res2.replace(GSM_NL "OK" GSM_NL, "");
res2.replace(AT_NL "OK" AT_NL, "");
res2.replace("_", " ");
res2.trim();
@@ -239,7 +239,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
return false;
#else
sendAT(GF("+CIPSSL=?"));
if (waitResponse(GF(GSM_NL "+CIPSSL:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+CIPSSL:")) != 1) { return false; }
return waitResponse() == 1;
#endif
}
@@ -300,8 +300,8 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
sendAT(GF("+CIFSR;E0"));
String res;
if (waitResponse(10000L, res) != 1) { return ""; }
res.replace(GSM_NL "OK" GSM_NL, "");
res.replace(GSM_NL, "");
res.replace(AT_NL "OK" AT_NL, "");
res.replace(AT_NL, "");
res.trim();
return res;
}
@@ -403,7 +403,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
// May not return the "+CCID" before the number
String getSimCCIDImpl() {
sendAT(GF("+CCID"));
if (waitResponse(GF(GSM_NL)) != 1) { return ""; }
if (waitResponse(GF(AT_NL)) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
// Trim out the CCID header in case it is there
@@ -454,7 +454,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
uint8_t getVolume() {
// Get speaker volume
sendAT(GF("+CLVL?"));
if (waitResponse(GF(GSM_NL)) != 1) { return 0; }
if (waitResponse(GF(AT_NL)) != 1) { return 0; }
String res = stream.readStringUntil('\n');
waitResponse();
res.replace("+CLVL:", "");
@@ -530,9 +530,9 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host,
GF("\","), port);
rsp = waitResponse(
timeout_ms, GF("CONNECT OK" GSM_NL), GF("CONNECT FAIL" GSM_NL),
GF("ALREADY CONNECT" GSM_NL), GF("ERROR" GSM_NL),
GF("CLOSE OK" GSM_NL)); // Happens when HTTPS handshake fails
timeout_ms, GF("CONNECT OK" AT_NL), GF("CONNECT FAIL" AT_NL),
GF("ALREADY CONNECT" AT_NL), GF("ERROR" AT_NL),
GF("CLOSE OK" AT_NL)); // Happens when HTTPS handshake fails
return (1 == rsp);
}
@@ -541,7 +541,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
if (waitResponse(GF(">")) != 1) { return 0; }
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "DATA ACCEPT:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux
return streamGetIntBefore('\n');
}
@@ -624,7 +624,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
*/
public:
bool handleURCs(String& data) {
if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
if (data.endsWith(GF(AT_NL "+CIPRXGET:"))) {
int8_t mode = streamGetIntBefore(',');
if (mode == 1) {
int8_t mux = streamGetIntBefore('\n');
@@ -638,7 +638,7 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
data += mode;
return false;
}
} else if (data.endsWith(GF(GSM_NL "+RECEIVE:"))) {
} else if (data.endsWith(GF(AT_NL "+RECEIVE:"))) {
int8_t mux = streamGetIntBefore(',');
int16_t len = streamGetIntBefore('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
@@ -648,8 +648,8 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
data = "";
// DBG("### Got Data:", len, "on", mux);
return true;
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
int8_t nl = data.lastIndexOf(GSM_NL, data.length() - 8);
} else if (data.endsWith(GF("CLOSED" AT_NL))) {
int8_t nl = data.lastIndexOf(AT_NL, data.length() - 8);
int8_t coma = data.indexOf(',', nl + 2);
int8_t mux = data.substring(nl + 2, coma).toInt();
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {

View File

@@ -14,7 +14,9 @@
#include "TinyGsmGPS.tpp"
#include "TinyGsmBluetooth.tpp"
class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808>, public TinyGsmBluetooth<TinyGsmSim808> {
class TinyGsmSim808 : public TinyGsmSim800,
public TinyGsmGPS<TinyGsmSim808>,
public TinyGsmBluetooth<TinyGsmSim808> {
friend class TinyGsmGPS<TinyGsmSim808>;
friend class TinyGsmBluetooth<TinyGsmSim808>;
@@ -43,7 +45,7 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808>, pu
// works only with ans SIM808 V2
String getGPSrawImpl() {
sendAT(GF("+CGNSINF"));
if (waitResponse(10000L, GF(GSM_NL "+CGNSINF:")) != 1) { return ""; }
if (waitResponse(10000L, GF(AT_NL "+CGNSINF:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -57,7 +59,7 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808>, pu
int* year = 0, int* month = 0, int* day = 0, int* hour = 0,
int* minute = 0, int* second = 0) {
sendAT(GF("+CGNSINF"));
if (waitResponse(10000L, GF(GSM_NL "+CGNSINF:")) != 1) { return false; }
if (waitResponse(10000L, GF(AT_NL "+CGNSINF:")) != 1) { return false; }
streamSkipUntil(','); // GNSS run status
if (streamGetIntBefore(',') == 1) { // fix status
@@ -129,11 +131,11 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808>, pu
waitResponse();
return false;
}
/*
/*
* Bluetooth functions
*/
bool enableBluetoothImpl() {
sendAT(GF("+BTPOWER=1"));
if (waitResponse() != 1) { return false; }
@@ -145,22 +147,18 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808>, pu
if (waitResponse() != 1) { return false; }
return true;
}
bool setBluetoothVisibilityImpl(bool visible) {
sendAT(GF("+BTVIS="), visible);
if (waitResponse() != 1) {
return false;
}
if (waitResponse() != 1) { return false; }
return true;
}
bool setBluetoothHostNameImpl(const char* name) {
sendAT(GF("+BTHOST="), name);
if (waitResponse() != 1) {
return false;
}
if (waitResponse() != 1) { return false; }
return true;
}
};

View File

@@ -14,9 +14,9 @@
#define TINY_GSM_MUX_COUNT 7
#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -264,13 +264,13 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
sendAT(GF("+CGMI"));
String res1;
if (waitResponse(1000L, res1) != 1) { return "u-blox Cellular Modem"; }
res1.replace(GSM_NL "OK" GSM_NL, "");
res1.replace(AT_NL "OK" AT_NL, "");
res1.trim();
sendAT(GF("+GMM"));
String res2;
if (waitResponse(1000L, res2) != 1) { return "u-blox Cellular Modem"; }
res2.replace(GSM_NL "OK" GSM_NL, "");
res2.replace(AT_NL "OK" AT_NL, "");
res2.trim();
String name = res1 + String(' ') + res2;
@@ -406,7 +406,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
// This uses "CGSN" instead of "GSN"
String getIMEIImpl() {
sendAT(GF("+CGSN"));
if (waitResponse(GF(GSM_NL)) != 1) { return ""; }
if (waitResponse(GF(AT_NL)) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -436,12 +436,12 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
// <aid_mode> - 0: no aiding (default)
// <GNSS_systems> - 3: GPS + SBAS (default)
sendAT(GF("+UGPS=1,0,3"));
if (waitResponse(10000L, GF(GSM_NL "+UGPS:")) != 1) { return false; }
if (waitResponse(10000L, GF(AT_NL "+UGPS:")) != 1) { return false; }
return waitResponse(10000L) == 1;
}
bool disableGPSImpl() {
sendAT(GF("+UGPS=0"));
if (waitResponse(10000L, GF(GSM_NL "+UGPS:")) != 1) { return false; }
if (waitResponse(10000L, GF(AT_NL "+UGPS:")) != 1) { return false; }
return waitResponse(10000L) == 1;
}
String inline getUbloxLocationRaw(int8_t sensor) {
@@ -461,7 +461,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
// wait for first "OK"
if (waitResponse(10000L) != 1) { return ""; }
// wait for the final result - wait full timeout time
if (waitResponse(120000L, GF(GSM_NL "+UULOC:")) != 1) { return ""; }
if (waitResponse(120000L, GF(AT_NL "+UULOC:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -496,7 +496,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
// wait for first "OK"
if (waitResponse(10000L) != 1) { return false; }
// wait for the final result - wait full timeout time
if (waitResponse(120000L, GF(GSM_NL "+UULOC: ")) != 1) { return false; }
if (waitResponse(120000L, GF(AT_NL "+UULOC: ")) != 1) { return false; }
// +UULOC: <date>, <time>, <lat>, <long>, <alt>, <uncertainty>, <speed>,
// <direction>, <vertical_acc>, <sensor_used>, <SV_used>, <antenna_status>,
@@ -592,7 +592,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
int8_t getBattPercentImpl() {
sendAT(GF("+CIND?"));
if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+CIND:")) != 1) { return 0; }
int8_t res = streamGetIntBefore(',');
int8_t percent = res * 20; // return is 0-5
@@ -620,7 +620,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
sendAT(GF("+UTEMP=0")); // Would use 1 for Fahrenheit
if (waitResponse() != 1) { return static_cast<float>(-9999); }
sendAT(GF("+UTEMP?"));
if (waitResponse(GF(GSM_NL "+UTEMP:")) != 1) {
if (waitResponse(GF(AT_NL "+UTEMP:")) != 1) {
return static_cast<float>(-9999);
}
int16_t res = streamGetIntBefore('\n');
@@ -641,7 +641,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
// create a socket
sendAT(GF("+USOCR=6"));
// reply is +USOCR: ## of socket created
if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+USOCR:")) != 1) { return false; }
*mux = streamGetIntBefore('\n');
waitResponse();
@@ -675,7 +675,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
"the URC '+UUSOCO' appears.");
sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port, ",1");
if (waitResponse(timeout_ms - (millis() - startMillis),
GF(GSM_NL "+UUSOCO:")) == 1) {
GF(AT_NL "+UUSOCO:")) == 1) {
streamGetIntBefore(','); // skip repeated mux
int8_t connection_status = streamGetIntBefore('\n');
DBG("### Waited", millis() - startMillis, "ms for socket to open");
@@ -700,7 +700,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
delay(50);
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+USOWR:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux
int16_t sent = streamGetIntBefore('\n');
waitResponse(); // sends back OK after the confirmation of number sent
@@ -710,7 +710,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
size_t modemRead(size_t size, uint8_t mux) {
if (!sockets[mux]) return 0;
sendAT(GF("+USORD="), mux, ',', (uint16_t)size);
if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+USORD:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux
int16_t len = streamGetIntBefore(',');
streamSkipUntil('\"');
@@ -728,7 +728,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
// NOTE: Querying a closed socket gives an error "operation not allowed"
sendAT(GF("+USORD="), mux, ",0");
size_t result = 0;
uint8_t res = waitResponse(GF(GSM_NL "+USORD:"));
uint8_t res = waitResponse(GF(AT_NL "+USORD:"));
// Will give error "operation not allowed" when attempting to read a socket
// that you have already told to close
if (res == 1) {
@@ -745,7 +745,7 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
bool modemGetConnected(uint8_t mux) {
// NOTE: Querying a closed socket gives an error "operation not allowed"
sendAT(GF("+USOCTL="), mux, ",10");
uint8_t res = waitResponse(GF(GSM_NL "+USOCTL:"));
uint8_t res = waitResponse(GF(AT_NL "+USOCTL:"));
if (res != 1) { return false; }
streamSkipUntil(','); // Skip mux

View File

@@ -13,9 +13,9 @@
#define TINY_GSM_MUX_COUNT 6
#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmCalling.tpp"
@@ -283,7 +283,7 @@ class TinyGsmSequansMonarch
if (!testAT()) { return false; }
sendAT(GF("+CFUN=0"));
int8_t res = waitResponse(20000L, GFP(GSM_OK), GFP(GSM_ERROR),
int8_t res = waitResponse(20000L, GFP(AT_OK), GFP(GSM_ERROR),
GF("+SYSSTART"));
if (res != 1 && res != 3) { return false; }
@@ -382,7 +382,7 @@ class TinyGsmSequansMonarch
protected:
String getSimCCIDImpl() {
sendAT(GF("+SQNCCID"));
if (waitResponse(GF(GSM_NL "+SQNCCID:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+SQNCCID:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -481,8 +481,8 @@ class TinyGsmSequansMonarch
// <acceptAnyRemote> = Applies to UDP only
sendAT(GF("+SQNSD="), mux, ",0,", port, ',', GF("\""), host, GF("\""),
",0,0,1");
rsp = waitResponse((timeout_ms - (millis() - startMillis)), GFP(GSM_OK),
GFP(GSM_ERROR), GF("NO CARRIER" GSM_NL));
rsp = waitResponse((timeout_ms - (millis() - startMillis)), GFP(AT_OK),
GFP(GSM_ERROR), GF("NO CARRIER" AT_NL));
// creation of socket failed immediately.
if (rsp != 1) { return false; }
@@ -503,7 +503,7 @@ class TinyGsmSequansMonarch
}
sendAT(GF("+SQNSSENDEXT="), mux, ',', (uint16_t)len);
waitResponse(10000L, GF(GSM_NL "> "));
waitResponse(10000L, GF(AT_NL "> "));
// Translate bytes into char to be able to send them as an hex string
char char_command[2];
for (size_t i = 0; i < len; i++) {
@@ -523,7 +523,7 @@ class TinyGsmSequansMonarch
// bool gotPrompt = false;
// while (nAttempts > 0 && !gotPrompt) {
// sendAT(GF("+SQNSSEND="), mux);
// if (waitResponse(5000, GF(GSM_NL "> ")) == 1) {
// if (waitResponse(5000, GF(AT_NL "> ")) == 1) {
// gotPrompt = true;
// }
// nAttempts--;
@@ -582,7 +582,7 @@ class TinyGsmSequansMonarch
// six possible sockets.
sendAT(GF("+SQNSS"));
for (int muxNo = 1; muxNo <= TINY_GSM_MUX_COUNT; muxNo++) {
if (waitResponse(GFP(GSM_OK), GF(GSM_NL "+SQNSS: ")) != 2) { break; }
if (waitResponse(GFP(AT_OK), GF(AT_NL "+SQNSS: ")) != 2) { break; }
uint8_t status = 0;
// if (streamGetIntBefore(',') != muxNo) { // check the mux no
// DBG("### Warning: misaligned mux numbers!");
@@ -615,7 +615,7 @@ class TinyGsmSequansMonarch
*/
public:
bool handleURCs(String& data) {
if (data.endsWith(GF(GSM_NL "+SQNSRING:"))) {
if (data.endsWith(GF(AT_NL "+SQNSRING:"))) {
int8_t mux = streamGetIntBefore(',');
int16_t len = streamGetIntBefore('\n');
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT &&
@@ -644,7 +644,7 @@ class TinyGsmSequansMonarch
protected:
GsmClientSequansMonarch* sockets[TINY_GSM_MUX_COUNT];
// GSM_NL (\r\n) is not accepted with SQNSSENDEXT in data mode so use \n
// AT_NL (\r\n) is not accepted with SQNSSENDEXT in data mode so use \n
const char* gsmNL = "\n";
};

View File

@@ -14,9 +14,9 @@
#define TINY_GSM_MUX_COUNT 7
#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r\n" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -210,13 +210,13 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
sendAT(GF("+CGMI"));
String res1;
if (waitResponse(1000L, res1) != 1) { return "u-blox Cellular Modem"; }
res1.replace(GSM_NL "OK" GSM_NL, "");
res1.replace(AT_NL "OK" AT_NL, "");
res1.trim();
sendAT(GF("+GMM"));
String res2;
if (waitResponse(1000L, res2) != 1) { return "u-blox Cellular Modem"; }
res2.replace(GSM_NL "OK" GSM_NL, "");
res2.replace(AT_NL "OK" AT_NL, "");
res2.trim();
String name = res1 + String(' ') + res2;
@@ -303,7 +303,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
String getLocalIPImpl() {
sendAT(GF("+UPSND=0,0"));
if (waitResponse(GF(GSM_NL "+UPSND:")) != 1) { return ""; }
if (waitResponse(GF(AT_NL "+UPSND:")) != 1) { return ""; }
streamSkipUntil(','); // Skip PSD profile
streamSkipUntil('\"'); // Skip request type
String res = stream.readStringUntil('\"');
@@ -402,7 +402,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
// This uses "CGSN" instead of "GSN"
String getIMEIImpl() {
sendAT(GF("+CGSN"));
if (waitResponse(GF(GSM_NL)) != 1) { return ""; }
if (waitResponse(GF(AT_NL)) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -436,12 +436,12 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
// <aid_mode> - 0: no aiding (default)
// <GNSS_systems> - 3: GPS + SBAS (default)
sendAT(GF("+UGPS=1,0,3"));
if (waitResponse(10000L, GF(GSM_NL "+UGPS:")) != 1) { return false; }
if (waitResponse(10000L, GF(AT_NL "+UGPS:")) != 1) { return false; }
return waitResponse(10000L) == 1;
}
bool disableGPSImpl() {
sendAT(GF("+UGPS=0"));
if (waitResponse(10000L, GF(GSM_NL "+UGPS:")) != 1) { return false; }
if (waitResponse(10000L, GF(AT_NL "+UGPS:")) != 1) { return false; }
return waitResponse(10000L) == 1;
}
String inline getUbloxLocationRaw(int8_t sensor) {
@@ -461,7 +461,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
// wait for first "OK"
if (waitResponse(10000L) != 1) { return ""; }
// wait for the final result - wait full timeout time
if (waitResponse(120000L, GF(GSM_NL "+UULOC:")) != 1) { return ""; }
if (waitResponse(120000L, GF(AT_NL "+UULOC:")) != 1) { return ""; }
String res = stream.readStringUntil('\n');
waitResponse();
res.trim();
@@ -496,7 +496,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
// wait for first "OK"
if (waitResponse(10000L) != 1) { return false; }
// wait for the final result - wait full timeout time
if (waitResponse(120000L, GF(GSM_NL "+UULOC: ")) != 1) { return false; }
if (waitResponse(120000L, GF(AT_NL "+UULOC: ")) != 1) { return false; }
// +UULOC: <date>, <time>, <lat>, <long>, <alt>, <uncertainty>, <speed>,
// <direction>, <vertical_acc>, <sensor_used>, <SV_used>, <antenna_status>,
@@ -592,7 +592,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
int8_t getBattPercentImpl() {
sendAT(GF("+CIND?"));
if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+CIND:")) != 1) { return 0; }
int8_t res = streamGetIntBefore(',');
int8_t percent = res * 20; // return is 0-5
@@ -631,7 +631,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
// create a socket
sendAT(GF("+USOCR=6"));
// reply is +USOCR: ## of socket created
if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { return false; }
if (waitResponse(GF(AT_NL "+USOCR:")) != 1) { return false; }
*mux = streamGetIntBefore('\n');
waitResponse();
@@ -665,7 +665,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
delay(50);
stream.write(reinterpret_cast<const uint8_t*>(buff), len);
stream.flush();
if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+USOWR:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux
int16_t sent = streamGetIntBefore('\n');
waitResponse(); // sends back OK after the confirmation of number sent
@@ -675,7 +675,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
size_t modemRead(size_t size, uint8_t mux) {
if (!sockets[mux]) return 0;
sendAT(GF("+USORD="), mux, ',', (uint16_t)size);
if (waitResponse(GF(GSM_NL "+USORD:")) != 1) { return 0; }
if (waitResponse(GF(AT_NL "+USORD:")) != 1) { return 0; }
streamSkipUntil(','); // Skip mux
int16_t len = streamGetIntBefore(',');
streamSkipUntil('\"');
@@ -693,7 +693,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
// NOTE: Querying a closed socket gives an error "operation not allowed"
sendAT(GF("+USORD="), mux, ",0");
size_t result = 0;
uint8_t res = waitResponse(GF(GSM_NL "+USORD:"));
uint8_t res = waitResponse(GF(AT_NL "+USORD:"));
// Will give error "operation not allowed" when attempting to read a socket
// that you have already told to close
if (res == 1) {
@@ -710,7 +710,7 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
bool modemGetConnected(uint8_t mux) {
// NOTE: Querying a closed socket gives an error "operation not allowed"
sendAT(GF("+USOCTL="), mux, ",10");
uint8_t res = waitResponse(GF(GSM_NL "+USOCTL:"));
uint8_t res = waitResponse(GF(AT_NL "+USOCTL:"));
if (res != 1) { return false; }
streamSkipUntil(','); // Skip mux

View File

@@ -20,9 +20,9 @@
// XBee's have a default guard time of 1 second (1000ms, 10 extra for safety
// here)
#define TINY_GSM_XBEE_GUARD_TIME 1010
#ifdef GSM_NL
#undef GSM_NL
#define GSM_NL "\r" // NOTE: define before including TinyGsmModem!
#ifdef AT_NL
#undef AT_NL
#define AT_NL "\r" // NOTE: define before including TinyGsmModem!
#endif
#include "TinyGsmBattery.tpp"
@@ -1322,7 +1322,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
// // Ask for information about any open sockets
// sendAT(GF("SI"));
// String open_socks = stream.readStringUntil('\r');
// open_socks.replace(GSM_NL, "");
// open_socks.replace(AT_NL, "");
// open_socks.trim();
// if (open_socks != "") {
// // In transparent mode, only socket 0 should be possible

View File

@@ -11,34 +11,34 @@
#include "TinyGsmCommon.h"
#ifndef GSM_NL
#define GSM_NL "\r\n"
#ifndef AT_NL
#define AT_NL "\r\n"
#endif
#ifndef GSM_OK
#define GSM_OK "OK"
#ifndef AT_OK
#define AT_OK "OK"
#endif
#ifndef GSM_ERROR
#define GSM_ERROR "ERROR"
#ifndef AT_ERROR
#define AT_ERROR "ERROR"
#endif
#if defined TINY_GSM_DEBUG
#ifndef GSM_VERBOSE
#define GSM_VERBOSE "+CME ERROR:"
#ifndef AT_VERBOSE
#define AT_VERBOSE "+CME ERROR:"
#endif
#ifndef GSM_VERBOSE_2
#define GSM_VERBOSE_2 "+CMS ERROR:"
#ifndef AT_VERBOSE_2
#define AT_VERBOSE_2 "+CMS ERROR:"
#endif
#endif
static const char GSM_OK[] TINY_GSM_PROGMEM = GSM_OK GSM_NL;
static const char GSM_ERROR[] TINY_GSM_PROGMEM = GSM_ERROR GSM_NL;
static const char GSM_OK[] TINY_GSM_PROGMEM = AT_OK AT_NL;
static const char GSM_ERROR[] TINY_GSM_PROGMEM = AT_ERROR AT_NL;
#if defined TINY_GSM_DEBUG
static const char GSM_VERBOSE[] TINY_GSM_PROGMEM = GSM_VERBOSE;
static const char GSM_VERBOSE_2[] TINY_GSM_PROGMEM = GSM_VERBOSE_2;
static const char GSM_VERBOSE[] TINY_GSM_PROGMEM = AT_VERBOSE;
static const char GSM_VERBOSE_2[] TINY_GSM_PROGMEM = AT_VERBOSE_2;
#endif
template <class modemType>
@@ -55,7 +55,7 @@ class TinyGsmModem {
}
template <typename... Args>
inline void sendAT(Args... cmd) {
thisModem().streamWrite("AT", cmd..., GSM_NL);
thisModem().streamWrite("AT", cmd..., AT_NL);
thisModem().stream.flush();
TINY_GSM_YIELD(); /* DBG("### AT:", cmd...); */
}
@@ -219,8 +219,8 @@ class TinyGsmModem {
goto finish;
}
#if defined TINY_GSM_DEBUG
else if (data.endsWith(GFP(GSM_VERBOSE)) ||
data.endsWith(GFP(GSM_VERBOSE_2))) {
else if (data.endsWith(GFP(AT_VERBOSE)) ||
data.endsWith(GFP(AT_VERBOSE_2))) {
// DBG(GF("Verbose details <<<"));
// Read out the verbose message, until whichever type of new line
// comes first
@@ -241,7 +241,7 @@ class TinyGsmModem {
if (data.length()) { DBG("### Unhandled:", data); }
data = "";
}
// data.replace(GSM_NL, "/");
// data.replace(AT_NL, "/");
// DBG('<', index, '>', data);
return index;
}