Skip to content

Commit

Permalink
Merge pull request #41 from carrascoacd/fix-library-for-new-versions
Browse files Browse the repository at this point in the history
Fix compatibility with Arduino 1.8.12 and AVR Boards 1.8.2
  • Loading branch information
carrascoacd authored Apr 5, 2020
2 parents 93459ad + e6a5596 commit 7a7cd60
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
9 changes: 9 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

[![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)

# Arduino SIM800L library
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.

Expand Down Expand Up @@ -112,3 +114,10 @@ In order to perform a request, the library follows these steps:
- Support of HardwareSerial.
- Support of more content types, not only JSON (application/json).
## Development
- Lint
```
cppcheck --enable=all .
```
2 changes: 1 addition & 1 deletion src/GPRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const char CONNECTED[] PROGMEM = "+CREG: 0,1";
const char ROAMING[] PROGMEM = "+CREG: 0,5";
const char BEARER_OPEN[] PROGMEM = "+SAPBR: 1,1";
const char OK[] PROGMEM = "OK";
const char OK_ PROGMEM = "OK";
const char OK_ = "OK";

Result openGPRSContext(SIM800 *sim800, const char *apn)
{
Expand Down
20 changes: 9 additions & 11 deletions src/Http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,17 @@ Result HTTP::disconnect()

Result HTTP::post(const char *uri, const char *body, char *response)
{

Result result = setHTTPSession(uri);
Result result;
setHTTPSession(uri);

char buffer[32];
char resp[16];

unsigned int delayToDownload = 10000;
sprintf_P(buffer, HTTP_DATA, strlen(body), delayToDownload);
strcpy_P(resp, DOWNLOAD);
if (sendCmdAndWaitForResp(buffer, resp, 2000) == FALSE)
{
result = ERROR_HTTP_DATA;
}

sendCmdAndWaitForResp(buffer, resp, 2000);

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

Result HTTP::get(const char *uri, char *response)
{

Result result = setHTTPSession(uri);
char buffer[16];
char resp[16];
Result result;
setHTTPSession(uri);

if (sendCmdAndWaitForResp_P(HTTP_GET, HTTP_2XX, 2000) == TRUE)
{
char buffer[16];
strcpy_P(buffer, HTTP_READ);
sendCmd(buffer);
result = SUCCESS;
Expand Down Expand Up @@ -178,7 +176,7 @@ unsigned int HTTP::readSignalStrength()

Result HTTP::setHTTPSession(const char *uri)
{
Result result;
Result result = SUCCESS;
char buffer[128];

if (sendCmdAndWaitForResp_P(HTTP_CID, OK, 2000) == FALSE)
Expand Down
8 changes: 4 additions & 4 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void parseATResponse(const char *buffer, unsigned int size, unsigned int offset,
const char *twoPointsPointer = strchr(buffer, ':');
unsigned int twoPointsIndex = (int)(twoPointsPointer - buffer);
unsigned int valueStartIndex = twoPointsIndex + offset;
for (int i = valueStartIndex; i < valueStartIndex + size; ++i)
for (unsigned int i = valueStartIndex; i < valueStartIndex + size; ++i)
{
response[i - valueStartIndex] = buffer[i];
response[i - valueStartIndex + 1] = '\0';
Expand All @@ -42,8 +42,8 @@ void parseATResponse(const char *buffer, unsigned int size, unsigned int offset,

void parseJSONResponse(const char *buffer, unsigned int bufferSize, char *response)
{
int start_index = 0;
int i = 0;
unsigned int start_index = 0;
unsigned int i = 0;
while (i < bufferSize - 1 && start_index == 0)
{
char c = buffer[i];
Expand All @@ -54,7 +54,7 @@ void parseJSONResponse(const char *buffer, unsigned int bufferSize, char *respon
++i;
}

int end_index = 0;
unsigned int end_index = 0;
int j = bufferSize - 1;
while (j >= 0 && end_index == 0)
{
Expand Down
11 changes: 5 additions & 6 deletions src/Sim800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ int SIM800::checkReadable(void)
int SIM800::readBuffer(char *buffer, int count, unsigned int timeOut)
{
int i = 0;
unsigned long timerStart, timerEnd;
timerStart = millis();
unsigned long timerStart = millis();
while (1)
{
while (serialSIM800.available())
Expand All @@ -73,7 +72,8 @@ int SIM800::readBuffer(char *buffer, int count, unsigned int timeOut)
}
if (i > count - 1)
break;
timerEnd = millis();

unsigned long timerEnd = millis();
if (timerEnd - timerStart > timeOut)
{
break;
Expand Down Expand Up @@ -114,8 +114,7 @@ int SIM800::waitForResp(const char *resp, unsigned int timeout)
{
int len = strlen(resp);
int sum = 0;
unsigned long timerStart, timerEnd;
timerStart = millis();
unsigned long timerStart = millis();

while (1)
{
Expand All @@ -131,7 +130,7 @@ int SIM800::waitForResp(const char *resp, unsigned int timeout)
if (sum == len)
break;
}
timerEnd = millis();
unsigned long timerEnd = millis();
if (timerEnd - timerStart > timeout)
{
return FALSE;
Expand Down

0 comments on commit 7a7cd60

Please sign in to comment.