Skip to content

Commit 92d3c40

Browse files
committed
Add pattern matching in order to support 2XX status codes
1 parent 9b0cbd8 commit 92d3c40

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

Http.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Http.cpp
33
* A HTTP library for the SIM800L board
44
*
5-
* Copyright 2016 Antonio Carrasco
5+
* Copyright 2018 Antonio Carrasco
66
*
77
* The MIT License (MIT)
88
*
@@ -52,7 +52,7 @@
5252

5353
#define OK "OK\r\n"
5454
#define DOWNLOAD "DOWNLOAD"
55-
#define HTTP_200 ",200,"
55+
#define HTTP_2XX ",2XX,"
5656
#define HTTPS_PREFIX "https://"
5757
#define CONNECTED "+CREG: 0,1"
5858
#define BEARER_OPEN "+SAPBR: 1,1"
@@ -137,7 +137,7 @@ Result HTTP::post(const char *uri, const char *body, char *response) {
137137
delay(500);
138138
sendCmd(body);
139139

140-
if (sendCmdAndWaitForResp(HTTP_POST, HTTP_200, delayToDownload) == TRUE) {
140+
if (sendCmdAndWaitForResp(HTTP_POST, HTTP_2XX, delayToDownload) == TRUE) {
141141
sendCmd(HTTP_READ);
142142
readResponse(response);
143143
result = SUCCESS;
@@ -153,7 +153,7 @@ Result HTTP::get(const char *uri, char *response) {
153153

154154
Result result = setHTTPSession(uri);
155155

156-
if (sendCmdAndWaitForResp(HTTP_GET, HTTP_200, 2000) == TRUE) {
156+
if (sendCmdAndWaitForResp(HTTP_GET, HTTP_2XX, 2000) == TRUE) {
157157
sendCmd(HTTP_READ);
158158
result = SUCCESS;
159159
readResponse(response);

Http.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Http.h
33
* A HTTP library for the SIM800L board
44
*
5-
* Copyright 2016 Antonio Carrasco
5+
* Copyright 2018 Antonio Carrasco
66
*
77
* The MIT License (MIT)
88
*

Sim800.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* A library for SeeedStudio seeeduino GPRS shield
44
*
55
* Original work Copyright (c) 2013 seeed technology inc. [lawliet zou]
6-
* Modified work Copyright 2016 Antonio Carrasco
6+
* Modified work Copyright 2018 Antonio Carrasco
77
*
88
* The MIT License (MIT)
99
*
@@ -105,7 +105,7 @@ int SIM800::waitForResp(const char *resp, unsigned int timeout)
105105
if(serialSIM800.available()) {
106106
char c = serialSIM800.read();
107107
if (debugMode) Serial.print(c);
108-
sum = (c==resp[sum]) ? sum+1 : 0;
108+
sum = (c == resp[sum] || resp[sum] == 'X') ? sum+1 : 0;
109109
if(sum == len)break;
110110
}
111111
timerEnd = millis();

Sim800.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* A library for SeeedStudio seeeduino GPRS shield
44
*
55
* Original work Copyright (c) 2013 seeed technology inc. [lawliet zou]
6-
* Modified work Copyright 2016 Antonio Carrasco
6+
* Modified work Copyright 2018 Antonio Carrasco
77
*
88
* The MIT License (MIT)
99
*
@@ -34,7 +34,6 @@
3434

3535
#define TRUE 1
3636
#define FALSE 0
37-
3837
#define DEFAULT_TIMEOUT 5000
3938

4039

@@ -95,7 +94,9 @@ class SIM800
9594
void sendEndMark(void);
9695

9796
/** check SIM800 module response before time out
98-
* @param *resp correct response which SIM800 module will return
97+
* @param *resp correct response which SIM800 module will return. A 'X' char
98+
* can be used to allow any char matching character, example:
99+
* '200' and '201' matches with '20X'
99100
* @param *timeout waiting seconds till timeout
100101
* @returns
101102
* TRUE on success

0 commit comments

Comments
 (0)