diff --git a/src/Sim800.cpp b/src/Sim800.cpp index ab2ac14..efdd12c 100644 --- a/src/Sim800.cpp +++ b/src/Sim800.cpp @@ -32,6 +32,7 @@ const char SLEEP_MODE_2[] PROGMEM = "AT+CSCLK=2\r\n"; const char SLEEP_MODE_1[] PROGMEM = "AT+CSCLK=1\r\n"; const char SLEEP_MODE_0[] PROGMEM = "AT+CSCLK=0\r\n"; const char AT_OK[] PROGMEM = "OK"; +const char AT[] PROGMEM = "AT\r\n"; int SIM800::preInit(void) { @@ -97,7 +98,7 @@ void SIM800::cleanBuffer(char *buffer, int count) void SIM800::sendCmd(const char *cmd, unsigned int delayBeforeSend) { - serialSIM800.listen(); + //serialSIM800.listen(); serialSIM800.flush(); delay(delayBeforeSend); write(cmd); @@ -106,7 +107,7 @@ void SIM800::sendCmd(const char *cmd, unsigned int delayBeforeSend) int SIM800::sendATTest(void) { - int ret = sendCmdAndWaitForResp("AT\r\n", "OK", DEFAULT_TIMEOUT); + int ret = sendCmdAndWaitForResp_P(AT, AT_OK, DEFAULT_TIMEOUT); return ret; } @@ -189,14 +190,14 @@ void SIM800::purgeSerial() void SIM800::write(const char *data) { - serialSIM800.listen(); + //serialSIM800.listen(); serialSIM800.write(data); } void SIM800::write(const char *data, unsigned int size) { - serialSIM800.listen(); - serialSIM800.write(data, size); + //serialSIM800.listen(); + serialSIM800.write((const uint8_t*)data, size); } void SIM800::sleep(bool force) @@ -214,4 +215,5 @@ void SIM800::sleep(bool force) void SIM800::wakeUp() { preInit(); + sendCmdAndWaitForResp_P(SLEEP_MODE_0, AT_OK, 2000); } diff --git a/src/Sim800.h b/src/Sim800.h index f699526..9480f73 100644 --- a/src/Sim800.h +++ b/src/Sim800.h @@ -30,14 +30,14 @@ #define __SIM800_H__ #include -#include +#include #define TRUE 1 #define FALSE 0 #define DEFAULT_TIMEOUT 5000 // Comment or uncomment this to debug the library -// #define DEBUG true +#define DEBUG true /** SIM800 class. * Used for SIM800 communication. attention that SIM800 module communicate with MCU in serial protocol @@ -55,9 +55,9 @@ class SIM800 SIM800(unsigned int baudRate, unsigned int rxPin, unsigned int txPin, - unsigned int rstPin) : serialSIM800(txPin, rxPin) + unsigned int rstPin) : serialSIM800(1) { - serialSIM800.begin(baudRate); + serialSIM800.begin(baudRate, SERIAL_8N1, txPin, rxPin); resetPin = rstPin; }; @@ -139,7 +139,7 @@ class SIM800 void wakeUp(); protected: - SoftwareSerial serialSIM800; + HardwareSerial serialSIM800; unsigned int resetPin; };