Skip to content

Commit 26c8a28

Browse files
committed
Adding rx, tx and rst pins as HTTP constructor parameter
1 parent 002da0f commit 26c8a28

3 files changed

Lines changed: 30 additions & 32 deletions

File tree

Http.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ enum Result {
5353
class HTTP : public SIM800 {
5454

5555
public:
56-
HTTP(unsigned int baudRate = 9600, bool debug = TRUE):SIM800(baudRate, debug){};
56+
HTTP(unsigned int baudRate, unsigned int rxPin, unsigned int txPin, unsigned int rstPin, bool debug = TRUE):SIM800(baudRate, rxPin, txPin, rstPin, debug){};
5757
Result configureBearer(const char *apn);
5858
Result connect();
5959
Result disconnect();

Sim800.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Sim800.cpp
3-
* A library for SeeedStudio seeeduino GPRS shield
3+
* A library for SeeedStudio seeeduino GPRS shield
44
*
55
* Original work Copyright (c) 2013 seeed technology inc. [lawliet zou]
66
* Modified work Copyright 2016 Antonio Carrasco
@@ -30,17 +30,17 @@
3030

3131
int SIM800::preInit(void)
3232
{
33-
pinMode(SIM800_RESET_PIN, OUTPUT);
33+
pinMode(resetPin, OUTPUT);
3434

35-
digitalWrite(SIM800_RESET_PIN, HIGH);
35+
digitalWrite(resetPin, HIGH);
3636
delay(200);
37-
digitalWrite(SIM800_RESET_PIN, LOW);
37+
digitalWrite(resetPin, LOW);
3838
delay(2000);
39-
digitalWrite(SIM800_RESET_PIN, HIGH);
39+
digitalWrite(resetPin, HIGH);
4040
delay(3000);
4141

4242
purgeSerial();
43-
43+
4444
return TRUE;
4545
}
4646

@@ -56,7 +56,7 @@ int SIM800::readBuffer(char *buffer, int count, unsigned int timeOut)
5656
timerStart = millis();
5757
while(1) {
5858
while (serialSIM800.available()) {
59-
char c = serialSIM800.read();
59+
char c = serialSIM800.read();
6060
buffer[i] = c;
6161
buffer[i + 1] = '\0';
6262
++i;
@@ -99,7 +99,7 @@ int SIM800::waitForResp(const char *resp, unsigned int timeout)
9999
int sum=0;
100100
unsigned long timerStart,timerEnd;
101101
timerStart = millis();
102-
102+
103103
while(1) {
104104
if(serialSIM800.available()) {
105105
char c = serialSIM800.read();
@@ -138,8 +138,8 @@ void SIM800::serialDebug(void)
138138
if(serialSIM800.available()){
139139
Serial.write(serialSIM800.read());
140140
}
141-
if(Serial.available()){
142-
serialSIM800.write(Serial.read());
141+
if(Serial.available()){
142+
serialSIM800.write(Serial.read());
143143
}
144144
}
145145
}

Sim800.h

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Sim800.h
3-
* A library for SeeedStudio seeeduino GPRS shield
3+
* A library for SeeedStudio seeeduino GPRS shield
44
*
55
* Original work Copyright (c) 2013 seeed technology inc. [lawliet zou]
66
* Modified work Copyright 2016 Antonio Carrasco
@@ -35,10 +35,6 @@
3535
#define TRUE 1
3636
#define FALSE 0
3737

38-
#define SIM800_TX_PIN 8
39-
#define SIM800_RX_PIN 7
40-
#define SIM800_RESET_PIN 12
41-
4238
#define DEFAULT_TIMEOUT 5000
4339

4440

@@ -49,41 +45,42 @@ class SIM800
4945
{
5046

5147
public:
52-
/** Create SIM800 Instance
53-
* @param tx uart transmit pin to communicate with SIM800
54-
* @param rx uart receive pin to communicate with SIM800
48+
/** Create SIM800 Instance
5549
* @param baudRate baud rate of uart communication
50+
* @param rxPin uart receive pin to communicate with SIM800
51+
* @param txPin uart transmit pin to communicate with SIM800
5652
*/
57-
SIM800(unsigned int baudRate, bool debug):serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN){
53+
SIM800(unsigned int baudRate, unsigned int rxPin, unsigned int txPin, unsigned int rstPin, bool debug):serialSIM800(txPin, rxPin) {
5854
serialSIM800.begin(baudRate);
5955
debugMode = debug;
56+
resetPin = rstPin;
6057
};
61-
58+
6259
/** Power on SIM800
6360
*/
6461
int preInit(void);
65-
62+
6663
/** Check if SIM800 readable
6764
*/
6865
int checkReadable(void);
69-
66+
7067
/** read from SIM800 module and save to buffer array
7168
* @param buffer buffer array to save what read from SIM800 module
7269
* @param count the maximal bytes number read from SIM800 module
73-
* @param timeOut time to wait for reading from SIM800 module
70+
* @param timeOut time to wait for reading from SIM800 module
7471
* @returns
7572
* TRUE on success
7673
* ERROR on error
7774
*/
7875
int readBuffer(char* buffer,int count, unsigned int timeOut = DEFAULT_TIMEOUT);
7976

80-
77+
8178
/** clean Buffer
8279
* @param buffer buffer to clean
8380
* @param count number of bytes to clean
8481
*/
8582
void cleanBuffer(char* buffer, int count);
86-
83+
8784
/** send AT command to SIM800 module
8885
* @param cmd command array which will be send to GPRS module
8986
*/
@@ -92,18 +89,18 @@ class SIM800
9289
/**send "AT" to SIM800 module
9390
*/
9491
int sendATTest(void);
95-
92+
9693
/**send '0x1A' to SIM800 Module
9794
*/
9895
void sendEndMark(void);
99-
96+
10097
/** check SIM800 module response before time out
10198
* @param *resp correct response which SIM800 module will return
10299
* @param *timeout waiting seconds till timeout
103100
* @returns
104101
* TRUE on success
105102
* ERROR on error
106-
*/
103+
*/
107104
int waitForResp(const char* resp, unsigned timeout);
108105

109106
/** send AT command to GPRS module and wait for correct response
@@ -120,14 +117,15 @@ class SIM800
120117
/** used for serial debug, you can specify tx and rx pin and then communicate with GPRS module with common AT commands
121118
*/
122119
void serialDebug(void);
123-
120+
124121
void purgeSerial();
125122

126123
private:
127-
124+
128125
SoftwareSerial serialSIM800;
129126
bool debugMode;
130-
127+
unsigned int resetPin;
128+
131129
};
132130

133131
#endif

0 commit comments

Comments
 (0)