Description
Hi
I have an excessive memory consumption when i used methods responseStatusCode() & responseBody() more than 50%.I using the code you post for resolve arduino-libraries/ArduinoHttpClient#57
I also add a code to check memory using on the arduino.
Please can you help me
MyConfig is
Arduino MKR1400
ArduinoHttpClient : 0.4.0
MKRGSM : 1.4.2
Memory Consumtion Displaying on the terminal
memory at startup of setup : 28347
memory at end of setup : 28279
making GET request
memory before responseStatusCode : 27871
memory after responseStatusCode: 24027
memory before responseBody : 24027
memory after responseBody : 19079
Status code: 200
Response: Wait ten secondsmaking GET request
memory before responseStatusCode : 19079
memory after responseStatusCode: 19079
memory before responseBody : 19079
memory after responseBody : 14131
Status code: 200
Response: Wait ten secondsmaking GET request
memory before responseStatusCode : 14131
memory after responseStatusCode: 14131
memory before responseBody : 14131
memory after responseBody : 14131
Status code: 200
Response: Wait ten seconds
The sketch is below
#include <MKRGSM.h>
#ifdef __arm__
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char* sbrk(int incr);
#else // __ARM__
extern char *__brkval;
#endif // __arm__
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[] = SECRET_PINNUMBER;
// APN data
const char GPRS_APN[] = SECRET_GPRS_APN;
const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN;
const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD;
const char serverAddress[] = "www.microsoft.com"; // server address
int port = 443;
// initialize the library instance
GSMSSLClient gsmClient;
GPRS gprs;
GSM gsmAccess;
HttpClient client = HttpClient(gsmClient, serverAddress, port);
String response="";
int statusCode=0;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.print("memory at startup of setup : ");
print_FreeMemory();
// connection state
bool connected = false;
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while (!connected) {
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
connected = true;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.print("memory at end of setup : ");
print_FreeMemory();
}
void loop() {
// assemble the path for the GET message:
String path = "/robots.txt";
// send the GET request
Serial.println("making GET request");
client.get(path);
// read the status code and body of the response
Serial.print("memory before responseStatusCode : ");
print_FreeMemory();
statusCode = client.responseStatusCode();
Serial.print("memory after responseStatusCode: ");
print_FreeMemory();
Serial.print("memory before responseBody : ");
print_FreeMemory();
response = client.responseBody();
Serial.print("memory after responseBody : ");
print_FreeMemory();
Serial.print("Status code: ");
Serial.println(statusCode);
Serial.print("Response: ");
//Serial.println(response);
response="";
Serial.println("Wait ten seconds\n");
delay(10000);
}
int print_FreeMemory() {
char top;
#ifdef __arm__
Serial.println(&top - reinterpret_cast<char*>(sbrk(0)));
return &top - reinterpret_cast<char*>(sbrk(0));
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
Serial.print("Mémoire dispo : ");
Serial.println(&top - __brkval);
return &top - __brkval;
#else // __arm__
//this->set_freememory(__brkval ? &top - __brkval : &top - __malloc_heap_start);
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif // __arm__
}```
----------------------------------------------------------------------------------------