Skip to content

Commit

Permalink
Rename GSM_NL to AT_NL
Browse files Browse the repository at this point in the history
Signed-off-by: Sara Damiano <[email protected]>
  • Loading branch information
SRGDamia1 committed May 13, 2024
1 parent 3e7e615 commit b8efb21
Show file tree
Hide file tree
Showing 20 changed files with 271 additions and 283 deletions.
24 changes: 9 additions & 15 deletions examples/more/SIM800_SslSetCert/SIM800_SslSetCert.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();


Expand All @@ -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);
}
44 changes: 22 additions & 22 deletions src/TinyGsmClientA6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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(',');
Expand Down Expand Up @@ -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');
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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;
}

Expand Down
20 changes: 10 additions & 10 deletions src/TinyGsmClientBG96.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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(',');
Expand Down
26 changes: 13 additions & 13 deletions src/TinyGsmClientESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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"
Expand All @@ -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;
}

Expand All @@ -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++) {
Expand All @@ -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(',');
Expand Down Expand Up @@ -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]) {
Expand Down
Loading

0 comments on commit b8efb21

Please sign in to comment.