Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Sim800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
Expand All @@ -214,4 +215,5 @@ void SIM800::sleep(bool force)
void SIM800::wakeUp()
{
preInit();
sendCmdAndWaitForResp_P(SLEEP_MODE_0, AT_OK, 2000);
}
10 changes: 5 additions & 5 deletions src/Sim800.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
#define __SIM800_H__

#include <Arduino.h>
#include <SoftwareSerial.h>
#include <HardwareSerial.h>

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

Expand Down Expand Up @@ -139,7 +139,7 @@ class SIM800
void wakeUp();

protected:
SoftwareSerial serialSIM800;
HardwareSerial serialSIM800;
unsigned int resetPin;
};

Expand Down