diff --git a/Readme.md b/Readme.md index c3367db..aa67d4f 100644 --- a/Readme.md +++ b/Readme.md @@ -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¤cy_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. @@ -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 . +``` \ No newline at end of file diff --git a/src/GPRS.cpp b/src/GPRS.cpp index e1c0422..e396ab4 100644 --- a/src/GPRS.cpp +++ b/src/GPRS.cpp @@ -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) { diff --git a/src/Http.cpp b/src/Http.cpp index 906a8bd..b4dae6c 100644 --- a/src/Http.cpp +++ b/src/Http.cpp @@ -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); @@ -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; @@ -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) diff --git a/src/Parser.cpp b/src/Parser.cpp index 05fc87b..362d509 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -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'; @@ -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]; @@ -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) { diff --git a/src/Sim800.cpp b/src/Sim800.cpp index b0dd05c..ec88888 100644 --- a/src/Sim800.cpp +++ b/src/Sim800.cpp @@ -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()) @@ -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; @@ -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) { @@ -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;