Skip to content

Commit 7a7cd60

Browse files
authored
Merge pull request #41 from carrascoacd/fix-library-for-new-versions
Fix compatibility with Arduino 1.8.12 and AVR Boards 1.8.2
2 parents 93459ad + e6a5596 commit 7a7cd60

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

Readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=58Y36H29935PW&item_name=Support+me+to+continue+developing+features&currency_code=EUR&source=url)
3+
24
# Arduino SIM800L library
35
A smart HTTP & FTP library based on Seeeduino that implements the AT HTTP commands to perform GET and POST requests to a JSON API as well as FTP uploads.
46

@@ -112,3 +114,10 @@ In order to perform a request, the library follows these steps:
112114
113115
- Support of HardwareSerial.
114116
- Support of more content types, not only JSON (application/json).
117+
118+
119+
## Development
120+
- Lint
121+
```
122+
cppcheck --enable=all .
123+
```

src/GPRS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const char CONNECTED[] PROGMEM = "+CREG: 0,1";
4242
const char ROAMING[] PROGMEM = "+CREG: 0,5";
4343
const char BEARER_OPEN[] PROGMEM = "+SAPBR: 1,1";
4444
const char OK[] PROGMEM = "OK";
45-
const char OK_ PROGMEM = "OK";
45+
const char OK_ = "OK";
4646

4747
Result openGPRSContext(SIM800 *sim800, const char *apn)
4848
{

src/Http.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,17 @@ Result HTTP::disconnect()
7373

7474
Result HTTP::post(const char *uri, const char *body, char *response)
7575
{
76-
77-
Result result = setHTTPSession(uri);
76+
Result result;
77+
setHTTPSession(uri);
78+
7879
char buffer[32];
7980
char resp[16];
8081

8182
unsigned int delayToDownload = 10000;
8283
sprintf_P(buffer, HTTP_DATA, strlen(body), delayToDownload);
8384
strcpy_P(resp, DOWNLOAD);
84-
if (sendCmdAndWaitForResp(buffer, resp, 2000) == FALSE)
85-
{
86-
result = ERROR_HTTP_DATA;
87-
}
85+
86+
sendCmdAndWaitForResp(buffer, resp, 2000);
8887

8988
purgeSerial();
9089
sendCmd(body);
@@ -106,13 +105,12 @@ Result HTTP::post(const char *uri, const char *body, char *response)
106105

107106
Result HTTP::get(const char *uri, char *response)
108107
{
109-
110-
Result result = setHTTPSession(uri);
111-
char buffer[16];
112-
char resp[16];
108+
Result result;
109+
setHTTPSession(uri);
113110

114111
if (sendCmdAndWaitForResp_P(HTTP_GET, HTTP_2XX, 2000) == TRUE)
115112
{
113+
char buffer[16];
116114
strcpy_P(buffer, HTTP_READ);
117115
sendCmd(buffer);
118116
result = SUCCESS;
@@ -178,7 +176,7 @@ unsigned int HTTP::readSignalStrength()
178176

179177
Result HTTP::setHTTPSession(const char *uri)
180178
{
181-
Result result;
179+
Result result = SUCCESS;
182180
char buffer[128];
183181

184182
if (sendCmdAndWaitForResp_P(HTTP_CID, OK, 2000) == FALSE)

src/Parser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void parseATResponse(const char *buffer, unsigned int size, unsigned int offset,
3333
const char *twoPointsPointer = strchr(buffer, ':');
3434
unsigned int twoPointsIndex = (int)(twoPointsPointer - buffer);
3535
unsigned int valueStartIndex = twoPointsIndex + offset;
36-
for (int i = valueStartIndex; i < valueStartIndex + size; ++i)
36+
for (unsigned int i = valueStartIndex; i < valueStartIndex + size; ++i)
3737
{
3838
response[i - valueStartIndex] = buffer[i];
3939
response[i - valueStartIndex + 1] = '\0';
@@ -42,8 +42,8 @@ void parseATResponse(const char *buffer, unsigned int size, unsigned int offset,
4242

4343
void parseJSONResponse(const char *buffer, unsigned int bufferSize, char *response)
4444
{
45-
int start_index = 0;
46-
int i = 0;
45+
unsigned int start_index = 0;
46+
unsigned int i = 0;
4747
while (i < bufferSize - 1 && start_index == 0)
4848
{
4949
char c = buffer[i];
@@ -54,7 +54,7 @@ void parseJSONResponse(const char *buffer, unsigned int bufferSize, char *respon
5454
++i;
5555
}
5656

57-
int end_index = 0;
57+
unsigned int end_index = 0;
5858
int j = bufferSize - 1;
5959
while (j >= 0 && end_index == 0)
6060
{

src/Sim800.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ int SIM800::checkReadable(void)
5858
int SIM800::readBuffer(char *buffer, int count, unsigned int timeOut)
5959
{
6060
int i = 0;
61-
unsigned long timerStart, timerEnd;
62-
timerStart = millis();
61+
unsigned long timerStart = millis();
6362
while (1)
6463
{
6564
while (serialSIM800.available())
@@ -73,7 +72,8 @@ int SIM800::readBuffer(char *buffer, int count, unsigned int timeOut)
7372
}
7473
if (i > count - 1)
7574
break;
76-
timerEnd = millis();
75+
76+
unsigned long timerEnd = millis();
7777
if (timerEnd - timerStart > timeOut)
7878
{
7979
break;
@@ -114,8 +114,7 @@ int SIM800::waitForResp(const char *resp, unsigned int timeout)
114114
{
115115
int len = strlen(resp);
116116
int sum = 0;
117-
unsigned long timerStart, timerEnd;
118-
timerStart = millis();
117+
unsigned long timerStart = millis();
119118

120119
while (1)
121120
{
@@ -131,7 +130,7 @@ int SIM800::waitForResp(const char *resp, unsigned int timeout)
131130
if (sum == len)
132131
break;
133132
}
134-
timerEnd = millis();
133+
unsigned long timerEnd = millis();
135134
if (timerEnd - timerStart > timeout)
136135
{
137136
return FALSE;

0 commit comments

Comments
 (0)