From 25644cd025815ac6021258bba8cc938f0919f81f Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Wed, 27 Sep 2017 23:46:02 +0300 Subject: [PATCH] Add testAT, setBaud, sleepEnable --- TinyGsmClientSIM800.h | 58 ++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/TinyGsmClientSIM800.h b/TinyGsmClientSIM800.h index 0633e34..60c5188 100644 --- a/TinyGsmClientSIM800.h +++ b/TinyGsmClientSIM800.h @@ -214,7 +214,7 @@ public: } bool init() { - if (!autoBaud()) { + if (!testAT()) { return false; } sendAT(GF("&FZ")); // Factory + Reset @@ -227,7 +227,11 @@ public: return true; } - bool autoBaud(unsigned long timeout = 10000L) { + void setBaud(unsigned long baud) { + sendAT(GF("+IPR="), baud); + } + + bool testAT(unsigned long timeout = 10000L) { //streamWrite(GF("AAAAA" GSM_NL)); // TODO: extra A's to help detect the baud rate for (unsigned long start = millis(); millis() - start < timeout; ) { sendAT(GF("")); @@ -293,7 +297,7 @@ public: */ bool restart() { - if (!autoBaud()) { + if (!testAT()) { return false; } sendAT(GF("+CFUN=0")); @@ -314,9 +318,6 @@ public: } bool radioOff() { - if (!autoBaud()) { - return false; - } sendAT(GF("+CFUN=0")); if (waitResponse(10000L) != 1) { return false; @@ -325,6 +326,16 @@ public: return true; } + /* + During sleep, the SIM800 module has its serial communication disabled. In order to reestablish communication + pull the DRT-pin of the SIM800 module LOW for at least 50ms. Then use this function to disable sleep mode. + The DTR-pin can then be released again. + */ + bool sleepEnable(bool enable = true) { + sendAT(GF("+CSCLK="), enable); + return waitResponse() == 1; + } + /* * SIM card functions */ @@ -606,9 +617,9 @@ public: int dcs = stream.readStringUntil('\n').toInt(); if (dcs == 15) { - return decodeHex8bit(hex); + return TinyGsmDecodeHex8bit(hex); } else if (dcs == 72) { - return decodeHex16bit(hex); + return TinyGsmDecodeHex16bit(hex); } else { return hex; } @@ -784,37 +795,6 @@ protected: return 1 == res; } - static String decodeHex8bit(String &instr) { - String result; - for (unsigned i=0; i